flake8 format

main
Bob Mottram 2020-04-03 16:45:00 +00:00
parent 128e431e9f
commit a85baf08ed
1 changed files with 110 additions and 95 deletions

View File

@ -7,22 +7,20 @@ __email__="bob@freedombone.net"
__status__ = "Production"
import os
import json
import time
from follow import followedAccountAccepts
from follow import followedAccountRejects
from follow import removeFromFollowRequests
from utils import loadJson
from utils import saveJson
def manualDenyFollowRequest(session,baseDir: str, \
def manualDenyFollowRequest(session, baseDir: str,
httpPrefix: str,
nickname: str,domain: str,port: int, \
denyHandle: str, \
federationList: [], \
sendThreads: [],postLog: [], \
cachedWebfingers: {},personCache: {}, \
debug: bool, \
nickname: str, domain: str, port: int,
denyHandle: str,
federationList: [],
sendThreads: [], postLog: [],
cachedWebfingers: {}, personCache: {},
debug: bool,
projectVersion: str) -> None:
"""Manually deny a follow request
"""
@ -33,8 +31,10 @@ def manualDenyFollowRequest(session,baseDir: str, \
rejectedFollowsFilename = accountsDir + '/followrejects.txt'
if os.path.isfile(rejectedFollowsFilename):
if denyHandle in open(rejectedFollowsFilename).read():
removeFromFollowRequests(baseDir,nickname,domain,denyHandle,debug)
print(denyHandle+' has already been rejected as a follower of '+nickname)
removeFromFollowRequests(baseDir, nickname, domain,
denyHandle, debug)
print(denyHandle + ' has already been rejected as a follower of ' +
nickname)
return
removeFromFollowRequests(baseDir, nickname, domain, denyHandle, debug)
@ -50,16 +50,17 @@ def manualDenyFollowRequest(session,baseDir: str, \
if ':' in denyDomain:
denyPort = denyDomain.split(':')[1]
denyDomain = denyDomain.split(':')[0]
followedAccountRejects(session,baseDir,httpPrefix, \
nickname,domain,port, \
denyNickname,denyDomain,denyPort, \
federationList, \
sendThreads,postLog, \
cachedWebfingers,personCache, \
followedAccountRejects(session, baseDir, httpPrefix,
nickname, domain, port,
denyNickname, denyDomain, denyPort,
federationList,
sendThreads, postLog,
cachedWebfingers, personCache,
debug, projectVersion)
print('Follow request from ' + denyHandle + ' was denied.')
def approveFollowerHandle(accountDir: str, approveHandle: str) -> None:
""" Record manually approved handles so that if they unfollow and then
re-follow later then they don't need to be manually approved again
@ -75,28 +76,32 @@ def approveFollowerHandle(accountDir: str,approveHandle: str) -> None:
approvedFile.write(approveHandle + '\n')
approvedFile.close()
def manualApproveFollowRequest(session,baseDir: str, \
def manualApproveFollowRequest(session, baseDir: str,
httpPrefix: str,
nickname: str,domain: str,port: int, \
approveHandle: str, \
federationList: [], \
sendThreads: [],postLog: [], \
cachedWebfingers: {},personCache: {}, \
acceptedCaps: [], \
debug: bool, \
nickname: str, domain: str, port: int,
approveHandle: str,
federationList: [],
sendThreads: [], postLog: [],
cachedWebfingers: {}, personCache: {},
acceptedCaps: [],
debug: bool,
projectVersion: str) -> None:
"""Manually approve a follow request
"""
handle = nickname + '@' + domain
print('Manual follow accept: '+handle+' approving follow request from '+approveHandle)
print('Manual follow accept: ' + handle +
' approving follow request from ' + approveHandle)
accountDir = baseDir + '/accounts/' + handle
approveFollowsFilename = accountDir + '/followrequests.txt'
if not os.path.isfile(approveFollowsFilename):
print('Manual follow accept: follow requests file '+approveFollowsFilename+' not found')
print('Manual follow accept: follow requests file ' +
approveFollowsFilename + ' not found')
return
# is the handle in the requests file?
if approveHandle not in open(approveFollowsFilename).read():
print('Manual follow accept: '+approveHandle+' not in requests file '+approveFollowsFilename)
print('Manual follow accept: ' + approveHandle +
' not in requests file ' + approveFollowsFilename)
return
approvefilenew = open(approveFollowsFilename + '.new', 'w+')
@ -106,31 +111,38 @@ def manualApproveFollowRequest(session,baseDir: str, \
for handleOfFollowRequester in approvefile:
# is this the approved follow?
if handleOfFollowRequester.startswith(approveHandle):
handleOfFollowRequester=handleOfFollowRequester.replace('\n','')
handleOfFollowRequester = \
handleOfFollowRequester.replace('\n', '')
port2 = port
if ':' in handleOfFollowRequester:
port2Str = handleOfFollowRequester.split(':')[1]
if port2Str.isdigit():
port2 = int(port2Str)
requestsDir = accountDir + '/requests'
followActivityfilename=requestsDir+'/'+handleOfFollowRequester+'.follow'
followActivityfilename = \
requestsDir + '/' + handleOfFollowRequester + '.follow'
if os.path.isfile(followActivityfilename):
followJson = loadJson(followActivityfilename)
if followJson:
approveNickname = approveHandle.split('@')[0]
approveDomain=approveHandle.split('@')[1].replace('\n','')
approveDomain = \
approveHandle.split('@')[1].replace('\n', '')
approvePort = port2
if ':' in approveDomain:
approvePort = approveDomain.split(':')[1]
approveDomain = approveDomain.split(':')[0]
print('Manual follow accept: Sending Accept for '+handle+' follow request from '+approveNickname+'@'+approveDomain)
followedAccountAccepts(session,baseDir,httpPrefix, \
nickname,domain,port, \
approveNickname,approveDomain,approvePort, \
followJson['actor'],federationList, \
followJson,acceptedCaps, \
sendThreads,postLog, \
cachedWebfingers,personCache, \
print('Manual follow accept: Sending Accept for ' +
handle + ' follow request from ' +
approveNickname + '@' + approveDomain)
followedAccountAccepts(session, baseDir, httpPrefix,
nickname, domain, port,
approveNickname, approveDomain,
approvePort,
followJson['actor'],
federationList,
followJson, acceptedCaps,
sendThreads, postLog,
cachedWebfingers, personCache,
debug, projectVersion, False)
updateApprovedFollowers = True
else:
@ -151,11 +163,14 @@ def manualApproveFollowRequest(session,baseDir: str, \
followersFile.seek(0, 0)
followersFile.write(approveHandle + '\n' + content)
except Exception as e:
print('WARN: Manual follow accept. Failed to write entry to followers file '+str(e))
print('WARN: Manual follow accept. ' +
'Failed to write entry to followers file ' + str(e))
else:
print('WARN: Manual follow accept: '+approveHandle+' already exists in '+followersFilename)
print('WARN: Manual follow accept: ' + approveHandle +
' already exists in ' + followersFilename)
else:
print('Manual follow accept: first follower accepted for '+handle+' is '+approveHandle)
print('Manual follow accept: first follower accepted for ' +
handle + ' is ' + approveHandle)
followersFile = open(followersFilename, "w+")
followersFile.write(approveHandle + '\n')
followersFile.close()