forked from indymedia/epicyon
Create default petname when following
parent
44eacde556
commit
ddb11903d4
|
@ -29,7 +29,7 @@ def setPetName(baseDir: str, nickname: str, domain: str,
|
||||||
if os.path.isfile(petnamesFilename):
|
if os.path.isfile(petnamesFilename):
|
||||||
with open(petnamesFilename, 'r') as petnamesFile:
|
with open(petnamesFilename, 'r') as petnamesFile:
|
||||||
petnamesStr = petnamesFile.read()
|
petnamesStr = petnamesFile.read()
|
||||||
if petnamesStr.startswith(petname + ' '):
|
if entry in petnamesStr:
|
||||||
return True
|
return True
|
||||||
if ' ' + handle + '\n' in petnamesStr:
|
if ' ' + handle + '\n' in petnamesStr:
|
||||||
petnamesList = petnamesStr.split('\n')
|
petnamesList = petnamesStr.split('\n')
|
||||||
|
|
8
tests.py
8
tests.py
|
@ -1387,6 +1387,8 @@ def testClientToServer():
|
||||||
httpPrefix,
|
httpPrefix,
|
||||||
cachedWebfingers, personCache,
|
cachedWebfingers, personCache,
|
||||||
True, __version__)
|
True, __version__)
|
||||||
|
alicePetnamesFilename = aliceDir + '/accounts/' + \
|
||||||
|
'alice@' + aliceDomain + '/petnames.txt'
|
||||||
aliceFollowingFilename = \
|
aliceFollowingFilename = \
|
||||||
aliceDir + '/accounts/alice@' + aliceDomain + '/following.txt'
|
aliceDir + '/accounts/alice@' + aliceDomain + '/following.txt'
|
||||||
bobFollowersFilename = \
|
bobFollowersFilename = \
|
||||||
|
@ -1395,7 +1397,8 @@ def testClientToServer():
|
||||||
if os.path.isfile(bobFollowersFilename):
|
if os.path.isfile(bobFollowersFilename):
|
||||||
if 'alice@' + aliceDomain + ':' + str(alicePort) in \
|
if 'alice@' + aliceDomain + ':' + str(alicePort) in \
|
||||||
open(bobFollowersFilename).read():
|
open(bobFollowersFilename).read():
|
||||||
if os.path.isfile(aliceFollowingFilename):
|
if os.path.isfile(aliceFollowingFilename) and \
|
||||||
|
os.path.isfile(alicePetnamesFilename):
|
||||||
if 'bob@' + bobDomain + ':' + str(bobPort) in \
|
if 'bob@' + bobDomain + ':' + str(bobPort) in \
|
||||||
open(aliceFollowingFilename).read():
|
open(aliceFollowingFilename).read():
|
||||||
break
|
break
|
||||||
|
@ -1403,6 +1406,9 @@ def testClientToServer():
|
||||||
|
|
||||||
assert os.path.isfile(bobFollowersFilename)
|
assert os.path.isfile(bobFollowersFilename)
|
||||||
assert os.path.isfile(aliceFollowingFilename)
|
assert os.path.isfile(aliceFollowingFilename)
|
||||||
|
assert os.path.isfile(alicePetnamesFilename)
|
||||||
|
assert 'bob bob@' + bobDomain in \
|
||||||
|
open(alicePetnamesFilename).read()
|
||||||
print('alice@' + aliceDomain + ':' + str(alicePort) + ' in ' +
|
print('alice@' + aliceDomain + ':' + str(alicePort) + ' in ' +
|
||||||
bobFollowersFilename)
|
bobFollowersFilename)
|
||||||
assert 'alice@' + aliceDomain + ':' + str(alicePort) in \
|
assert 'alice@' + aliceDomain + ':' + str(alicePort) in \
|
||||||
|
|
38
utils.py
38
utils.py
|
@ -522,6 +522,37 @@ def getDomainFromActor(actor: str) -> (str, int):
|
||||||
return domain, port
|
return domain, port
|
||||||
|
|
||||||
|
|
||||||
|
def setDefaultPetName(baseDir: str, nickname: str, domain: str,
|
||||||
|
followNickname: str, followDomain: str) -> None:
|
||||||
|
"""Sets a default petname
|
||||||
|
This helps especially when using onion or i2p address
|
||||||
|
"""
|
||||||
|
if ':' in domain:
|
||||||
|
domain = domain.split(':')[0]
|
||||||
|
userPath = baseDir + '/accounts/' + nickname + '@' + domain
|
||||||
|
petnamesFilename = userPath + '/petnames.txt'
|
||||||
|
|
||||||
|
petnameLookupEntry = followNickname + ' ' + \
|
||||||
|
followNickname + '@' + followDomain + '\n'
|
||||||
|
if not os.path.isfile(petnamesFilename):
|
||||||
|
# if there is no existing petnames lookup file
|
||||||
|
with open(petnamesFilename, 'w+') as petnamesFile:
|
||||||
|
petnamesFile.write(petnameLookupEntry)
|
||||||
|
return
|
||||||
|
|
||||||
|
with open(petnamesFilename, 'r') as petnamesFile:
|
||||||
|
petnamesStr = petnamesFile.read()
|
||||||
|
if petnamesStr:
|
||||||
|
petnamesList = petnamesStr.split('\n')
|
||||||
|
for pet in petnamesList:
|
||||||
|
if pet.startswith(followNickname + ' '):
|
||||||
|
# petname already exists
|
||||||
|
return
|
||||||
|
# petname doesn't already exist
|
||||||
|
with open(petnamesFilename, 'a+') as petnamesFile:
|
||||||
|
petnamesFile.write(petnameLookupEntry)
|
||||||
|
|
||||||
|
|
||||||
def followPerson(baseDir: str, nickname: str, domain: str,
|
def followPerson(baseDir: str, nickname: str, domain: str,
|
||||||
followNickname: str, followDomain: str,
|
followNickname: str, followDomain: str,
|
||||||
federationList: [], debug: bool,
|
federationList: [], debug: bool,
|
||||||
|
@ -593,9 +624,9 @@ def followPerson(baseDir: str, nickname: str, domain: str,
|
||||||
with open(filename, 'w+') as f:
|
with open(filename, 'w+') as f:
|
||||||
f.write(handleToFollow + '\n')
|
f.write(handleToFollow + '\n')
|
||||||
|
|
||||||
# Default to adding new follows to the calendar.
|
|
||||||
# Possibly this could be made optional
|
|
||||||
if followFile.endswith('following.txt'):
|
if followFile.endswith('following.txt'):
|
||||||
|
# Default to adding new follows to the calendar.
|
||||||
|
# Possibly this could be made optional
|
||||||
# if following a person add them to the list of
|
# if following a person add them to the list of
|
||||||
# calendar follows
|
# calendar follows
|
||||||
print('DEBUG: adding ' +
|
print('DEBUG: adding ' +
|
||||||
|
@ -603,6 +634,9 @@ def followPerson(baseDir: str, nickname: str, domain: str,
|
||||||
nickname + '@' + domain)
|
nickname + '@' + domain)
|
||||||
addPersonToCalendar(baseDir, nickname, domain,
|
addPersonToCalendar(baseDir, nickname, domain,
|
||||||
followNickname, followDomain)
|
followNickname, followDomain)
|
||||||
|
# add a default petname
|
||||||
|
setDefaultPetName(baseDir, nickname, domain,
|
||||||
|
followNickname, followDomain)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue