forked from indymedia/epicyon
Use scandir
parent
139c2a1f13
commit
06b936f62e
|
@ -637,7 +637,8 @@ def removeTagsForNickname(baseDir: str,nickname: str,domain: str,port: int) -> N
|
||||||
domainFull=domain+':'+str(port)
|
domainFull=domain+':'+str(port)
|
||||||
matchStr=domainFull+'/users/'+nickname+'/'
|
matchStr=domainFull+'/users/'+nickname+'/'
|
||||||
directory = os.fsencode(baseDir+'/tags/')
|
directory = os.fsencode(baseDir+'/tags/')
|
||||||
for f in os.listdir(directory):
|
for f in os.scandir(directory):
|
||||||
|
f=f.name
|
||||||
filename = os.fsdecode(f)
|
filename = os.fsdecode(f)
|
||||||
if not filename.endswith(".txt"):
|
if not filename.endswith(".txt"):
|
||||||
continue
|
continue
|
||||||
|
|
12
posts.py
12
posts.py
|
@ -378,7 +378,8 @@ def deleteAllPosts(baseDir: str,nickname: str, domain: str,boxname: str) -> None
|
||||||
if boxname!='inbox' and boxname!='outbox':
|
if boxname!='inbox' and boxname!='outbox':
|
||||||
return
|
return
|
||||||
boxDir = createPersonDir(nickname,domain,baseDir,boxname)
|
boxDir = createPersonDir(nickname,domain,baseDir,boxname)
|
||||||
for deleteFilename in os.listdir(boxDir):
|
for deleteFilename in os.scandir(boxDir):
|
||||||
|
deleteFilename=deleteFilename.name
|
||||||
filePath = os.path.join(boxDir, deleteFilename)
|
filePath = os.path.join(boxDir, deleteFilename)
|
||||||
try:
|
try:
|
||||||
if os.path.isfile(filePath):
|
if os.path.isfile(filePath):
|
||||||
|
@ -1749,8 +1750,9 @@ def createBoxBase(baseDir: str,boxname: str, \
|
||||||
# post filenames sorted in descending order
|
# post filenames sorted in descending order
|
||||||
postsInBoxDict={}
|
postsInBoxDict={}
|
||||||
postsCtr=0
|
postsCtr=0
|
||||||
postsInPersonInbox=os.listdir(boxDir)
|
postsInPersonInbox=os.scandir(boxDir)
|
||||||
for postFilename in postsInPersonInbox:
|
for postFilename in postsInPersonInbox:
|
||||||
|
postFilename=postFilename.name
|
||||||
if not postFilename.endswith('.json'):
|
if not postFilename.endswith('.json'):
|
||||||
continue
|
continue
|
||||||
# extract the status number
|
# extract the status number
|
||||||
|
@ -1763,8 +1765,9 @@ def createBoxBase(baseDir: str,boxname: str, \
|
||||||
if sharedBoxDir:
|
if sharedBoxDir:
|
||||||
handle=nickname+'@'+domain
|
handle=nickname+'@'+domain
|
||||||
followingFilename=baseDir+'/accounts/'+handle+'/following.txt'
|
followingFilename=baseDir+'/accounts/'+handle+'/following.txt'
|
||||||
postsInSharedInbox=os.listdir(sharedBoxDir)
|
postsInSharedInbox=os.scandir(sharedBoxDir)
|
||||||
for postFilename in postsInSharedInbox:
|
for postFilename in postsInSharedInbox:
|
||||||
|
postFilename=postFilename.name
|
||||||
statusNumber=getStatusNumberFromPostFilename(postFilename)
|
statusNumber=getStatusNumberFromPostFilename(postFilename)
|
||||||
if statusNumber:
|
if statusNumber:
|
||||||
sharedInboxFilename=os.path.join(sharedBoxDir, postFilename)
|
sharedInboxFilename=os.path.join(sharedBoxDir, postFilename)
|
||||||
|
@ -1967,7 +1970,7 @@ def archivePostsForPerson(httpPrefix: str,nickname: str,domain: str,baseDir: str
|
||||||
if not os.path.isdir(archiveDir):
|
if not os.path.isdir(archiveDir):
|
||||||
os.mkdir(archiveDir)
|
os.mkdir(archiveDir)
|
||||||
boxDir = createPersonDir(nickname,domain,baseDir,boxname)
|
boxDir = createPersonDir(nickname,domain,baseDir,boxname)
|
||||||
postsInBox=os.listdir(boxDir)
|
postsInBox=os.scandir(boxDir)
|
||||||
noOfPosts=len(postsInBox)
|
noOfPosts=len(postsInBox)
|
||||||
if noOfPosts<=maxPostsInBox:
|
if noOfPosts<=maxPostsInBox:
|
||||||
return
|
return
|
||||||
|
@ -1975,6 +1978,7 @@ def archivePostsForPerson(httpPrefix: str,nickname: str,domain: str,baseDir: str
|
||||||
postsInBoxDict={}
|
postsInBoxDict={}
|
||||||
postsCtr=0
|
postsCtr=0
|
||||||
for postFilename in postsInBox:
|
for postFilename in postsInBox:
|
||||||
|
postFilename=postFilename.name
|
||||||
if not postFilename.endswith('.json'):
|
if not postFilename.endswith('.json'):
|
||||||
continue
|
continue
|
||||||
# extract the status number
|
# extract the status number
|
||||||
|
|
3
roles.py
3
roles.py
|
@ -22,7 +22,8 @@ def clearModeratorStatus(baseDir: str) -> None:
|
||||||
rarely when moderators are appointed or removed
|
rarely when moderators are appointed or removed
|
||||||
"""
|
"""
|
||||||
directory = os.fsencode(baseDir+'/accounts/')
|
directory = os.fsencode(baseDir+'/accounts/')
|
||||||
for f in os.listdir(directory):
|
for f in os.scandir(directory):
|
||||||
|
f=f.name
|
||||||
filename = os.fsdecode(f)
|
filename = os.fsdecode(f)
|
||||||
if filename.endswith(".json") and '@' in filename:
|
if filename.endswith(".json") and '@' in filename:
|
||||||
filename=os.path.join(baseDir+'/accounts/', filename)
|
filename=os.path.join(baseDir+'/accounts/', filename)
|
||||||
|
|
Loading…
Reference in New Issue