forked from indymedia/epicyon
Tidying
parent
af77df857f
commit
f4cb24490a
46
config.py
46
config.py
|
@ -1,46 +0,0 @@
|
||||||
__filename__ = "config.py"
|
|
||||||
__author__ = "Bob Mottram"
|
|
||||||
__license__ = "AGPL3+"
|
|
||||||
__version__ = "1.1.0"
|
|
||||||
__maintainer__ = "Bob Mottram"
|
|
||||||
__email__ = "bob@freedombone.net"
|
|
||||||
__status__ = "Production"
|
|
||||||
|
|
||||||
import os
|
|
||||||
from utils import loadJson
|
|
||||||
from utils import saveJson
|
|
||||||
|
|
||||||
|
|
||||||
def createConfig(baseDir: str) -> None:
|
|
||||||
"""Creates a configuration file
|
|
||||||
"""
|
|
||||||
configFilename = baseDir + '/config.json'
|
|
||||||
if os.path.isfile(configFilename):
|
|
||||||
return
|
|
||||||
configJson = {
|
|
||||||
}
|
|
||||||
saveJson(configJson, configFilename)
|
|
||||||
|
|
||||||
|
|
||||||
def setConfigParam(baseDir: str, variableName: str, variableValue) -> None:
|
|
||||||
"""Sets a configuration value
|
|
||||||
"""
|
|
||||||
createConfig(baseDir)
|
|
||||||
configFilename = baseDir + '/config.json'
|
|
||||||
configJson = {}
|
|
||||||
if os.path.isfile(configFilename):
|
|
||||||
configJson = loadJson(configFilename)
|
|
||||||
configJson[variableName] = variableValue
|
|
||||||
saveJson(configJson, configFilename)
|
|
||||||
|
|
||||||
|
|
||||||
def getConfigParam(baseDir: str, variableName: str):
|
|
||||||
"""Gets a configuration value
|
|
||||||
"""
|
|
||||||
createConfig(baseDir)
|
|
||||||
configFilename = baseDir + '/config.json'
|
|
||||||
configJson = loadJson(configFilename)
|
|
||||||
if configJson:
|
|
||||||
if configJson.get(variableName):
|
|
||||||
return configJson[variableName]
|
|
||||||
return None
|
|
|
@ -54,7 +54,6 @@ from person import registerAccount
|
||||||
from person import personLookup
|
from person import personLookup
|
||||||
from person import personBoxJson
|
from person import personBoxJson
|
||||||
from person import createSharedInbox
|
from person import createSharedInbox
|
||||||
from person import isSuspended
|
|
||||||
from person import suspendAccount
|
from person import suspendAccount
|
||||||
from person import unsuspendAccount
|
from person import unsuspendAccount
|
||||||
from person import removeAccount
|
from person import removeAccount
|
||||||
|
@ -101,8 +100,6 @@ from blocking import removeGlobalBlock
|
||||||
from blocking import isBlockedHashtag
|
from blocking import isBlockedHashtag
|
||||||
from blocking import isBlockedDomain
|
from blocking import isBlockedDomain
|
||||||
from blocking import getDomainBlocklist
|
from blocking import getDomainBlocklist
|
||||||
from config import setConfigParam
|
|
||||||
from config import getConfigParam
|
|
||||||
from roles import setRole
|
from roles import setRole
|
||||||
from roles import clearModeratorStatus
|
from roles import clearModeratorStatus
|
||||||
from blog import htmlBlogPageRSS2
|
from blog import htmlBlogPageRSS2
|
||||||
|
@ -159,6 +156,8 @@ from shares import getSharesFeedForPerson
|
||||||
from shares import addShare
|
from shares import addShare
|
||||||
from shares import removeShare
|
from shares import removeShare
|
||||||
from shares import expireShares
|
from shares import expireShares
|
||||||
|
from utils import setConfigParam
|
||||||
|
from utils import getConfigParam
|
||||||
from utils import removeIdEnding
|
from utils import removeIdEnding
|
||||||
from utils import updateLikesCollection
|
from utils import updateLikesCollection
|
||||||
from utils import undoLikesCollectionEntry
|
from utils import undoLikesCollectionEntry
|
||||||
|
@ -174,6 +173,7 @@ from utils import getStatusNumber
|
||||||
from utils import urlPermitted
|
from utils import urlPermitted
|
||||||
from utils import loadJson
|
from utils import loadJson
|
||||||
from utils import saveJson
|
from utils import saveJson
|
||||||
|
from utils import isSuspended
|
||||||
from manualapprove import manualDenyFollowRequest
|
from manualapprove import manualDenyFollowRequest
|
||||||
from manualapprove import manualApproveFollowRequest
|
from manualapprove import manualApproveFollowRequest
|
||||||
from announce import createAnnounce
|
from announce import createAnnounce
|
||||||
|
|
|
@ -45,10 +45,10 @@ from tests import testPostMessageBetweenServers
|
||||||
from tests import testFollowBetweenServers
|
from tests import testFollowBetweenServers
|
||||||
from tests import testClientToServer
|
from tests import testClientToServer
|
||||||
from tests import runAllTests
|
from tests import runAllTests
|
||||||
from config import setConfigParam
|
|
||||||
from config import getConfigParam
|
|
||||||
from auth import storeBasicCredentials
|
from auth import storeBasicCredentials
|
||||||
from auth import createPassword
|
from auth import createPassword
|
||||||
|
from utils import setConfigParam
|
||||||
|
from utils import getConfigParam
|
||||||
from utils import getDomainFromActor
|
from utils import getDomainFromActor
|
||||||
from utils import getNicknameFromActor
|
from utils import getNicknameFromActor
|
||||||
from utils import followPerson
|
from utils import followPerson
|
||||||
|
|
13
newswire.py
13
newswire.py
|
@ -15,6 +15,7 @@ from datetime import datetime
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from utils import locatePost
|
from utils import locatePost
|
||||||
from utils import loadJson
|
from utils import loadJson
|
||||||
|
from utils import isSuspended
|
||||||
|
|
||||||
|
|
||||||
def rss2Header(httpPrefix: str,
|
def rss2Header(httpPrefix: str,
|
||||||
|
@ -245,16 +246,8 @@ def addLocalBlogsToNewswire(baseDir: str, newswire: {},
|
||||||
|
|
||||||
# has this account been suspended?
|
# has this account been suspended?
|
||||||
nickname = handle.split('@')[0]
|
nickname = handle.split('@')[0]
|
||||||
if os.path.isfile(suspendedFilename):
|
if isSuspended(baseDir, nickname):
|
||||||
with open(suspendedFilename, "r") as f:
|
continue
|
||||||
lines = f.readlines()
|
|
||||||
foundSuspended = False
|
|
||||||
for nick in lines:
|
|
||||||
if nick == nickname + '\n':
|
|
||||||
foundSuspended = True
|
|
||||||
break
|
|
||||||
if foundSuspended:
|
|
||||||
continue
|
|
||||||
|
|
||||||
# is there a blogs timeline for this account?
|
# is there a blogs timeline for this account?
|
||||||
blogsIndex = accountDir + '/tlblogs.index'
|
blogsIndex = accountDir + '/tlblogs.index'
|
||||||
|
|
21
person.py
21
person.py
|
@ -37,8 +37,8 @@ from utils import validNickname
|
||||||
from utils import noOfAccounts
|
from utils import noOfAccounts
|
||||||
from utils import loadJson
|
from utils import loadJson
|
||||||
from utils import saveJson
|
from utils import saveJson
|
||||||
from config import setConfigParam
|
from utils import setConfigParam
|
||||||
from config import getConfigParam
|
from utils import getConfigParam
|
||||||
|
|
||||||
|
|
||||||
def generateRSAKey() -> (str, str):
|
def generateRSAKey() -> (str, str):
|
||||||
|
@ -754,23 +754,6 @@ def setBio(baseDir: str, nickname: str, domain: str, bio: str) -> bool:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def isSuspended(baseDir: str, nickname: str) -> bool:
|
|
||||||
"""Returns true if the given nickname is suspended
|
|
||||||
"""
|
|
||||||
adminNickname = getConfigParam(baseDir, 'admin')
|
|
||||||
if nickname == adminNickname:
|
|
||||||
return False
|
|
||||||
|
|
||||||
suspendedFilename = baseDir + '/accounts/suspended.txt'
|
|
||||||
if os.path.isfile(suspendedFilename):
|
|
||||||
with open(suspendedFilename, "r") as f:
|
|
||||||
lines = f.readlines()
|
|
||||||
for suspended in lines:
|
|
||||||
if suspended.strip('\n').strip('\r') == nickname:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def unsuspendAccount(baseDir: str, nickname: str) -> None:
|
def unsuspendAccount(baseDir: str, nickname: str) -> None:
|
||||||
"""Removes an account suspention
|
"""Removes an account suspention
|
||||||
"""
|
"""
|
||||||
|
|
2
posts.py
2
posts.py
|
@ -45,6 +45,7 @@ from utils import validNickname
|
||||||
from utils import locatePost
|
from utils import locatePost
|
||||||
from utils import loadJson
|
from utils import loadJson
|
||||||
from utils import saveJson
|
from utils import saveJson
|
||||||
|
from utils import getConfigParam
|
||||||
from media import attachMedia
|
from media import attachMedia
|
||||||
from media import replaceYouTube
|
from media import replaceYouTube
|
||||||
from content import removeHtml
|
from content import removeHtml
|
||||||
|
@ -53,7 +54,6 @@ from content import addHtmlTags
|
||||||
from content import replaceEmojiFromTags
|
from content import replaceEmojiFromTags
|
||||||
from content import removeTextFormatting
|
from content import removeTextFormatting
|
||||||
from auth import createBasicAuthHeader
|
from auth import createBasicAuthHeader
|
||||||
from config import getConfigParam
|
|
||||||
from blocking import isBlocked
|
from blocking import isBlocked
|
||||||
from filters import isFiltered
|
from filters import isFiltered
|
||||||
from git import convertPostToPatch
|
from git import convertPostToPatch
|
||||||
|
|
52
utils.py
52
utils.py
|
@ -19,6 +19,58 @@ from calendar import monthrange
|
||||||
from followingCalendar import addPersonToCalendar
|
from followingCalendar import addPersonToCalendar
|
||||||
|
|
||||||
|
|
||||||
|
def createConfig(baseDir: str) -> None:
|
||||||
|
"""Creates a configuration file
|
||||||
|
"""
|
||||||
|
configFilename = baseDir + '/config.json'
|
||||||
|
if os.path.isfile(configFilename):
|
||||||
|
return
|
||||||
|
configJson = {
|
||||||
|
}
|
||||||
|
saveJson(configJson, configFilename)
|
||||||
|
|
||||||
|
|
||||||
|
def setConfigParam(baseDir: str, variableName: str, variableValue) -> None:
|
||||||
|
"""Sets a configuration value
|
||||||
|
"""
|
||||||
|
createConfig(baseDir)
|
||||||
|
configFilename = baseDir + '/config.json'
|
||||||
|
configJson = {}
|
||||||
|
if os.path.isfile(configFilename):
|
||||||
|
configJson = loadJson(configFilename)
|
||||||
|
configJson[variableName] = variableValue
|
||||||
|
saveJson(configJson, configFilename)
|
||||||
|
|
||||||
|
|
||||||
|
def getConfigParam(baseDir: str, variableName: str):
|
||||||
|
"""Gets a configuration value
|
||||||
|
"""
|
||||||
|
createConfig(baseDir)
|
||||||
|
configFilename = baseDir + '/config.json'
|
||||||
|
configJson = loadJson(configFilename)
|
||||||
|
if configJson:
|
||||||
|
if configJson.get(variableName):
|
||||||
|
return configJson[variableName]
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def isSuspended(baseDir: str, nickname: str) -> bool:
|
||||||
|
"""Returns true if the given nickname is suspended
|
||||||
|
"""
|
||||||
|
adminNickname = getConfigParam(baseDir, 'admin')
|
||||||
|
if nickname == adminNickname:
|
||||||
|
return False
|
||||||
|
|
||||||
|
suspendedFilename = baseDir + '/accounts/suspended.txt'
|
||||||
|
if os.path.isfile(suspendedFilename):
|
||||||
|
with open(suspendedFilename, "r") as f:
|
||||||
|
lines = f.readlines()
|
||||||
|
for suspended in lines:
|
||||||
|
if suspended.strip('\n').strip('\r') == nickname:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def getFollowersList(baseDir: str,
|
def getFollowersList(baseDir: str,
|
||||||
nickname: str, domain: str,
|
nickname: str, domain: str,
|
||||||
followFile='following.txt') -> []:
|
followFile='following.txt') -> []:
|
||||||
|
|
|
@ -41,6 +41,7 @@ from utils import getDisplayName
|
||||||
from utils import getCachedPostDirectory
|
from utils import getCachedPostDirectory
|
||||||
from utils import getCachedPostFilename
|
from utils import getCachedPostFilename
|
||||||
from utils import loadJson
|
from utils import loadJson
|
||||||
|
from utils import getConfigParam
|
||||||
from follow import isFollowingActor
|
from follow import isFollowingActor
|
||||||
from webfinger import webfingerHandle
|
from webfinger import webfingerHandle
|
||||||
from posts import isDM
|
from posts import isDM
|
||||||
|
@ -67,7 +68,6 @@ from content import addHtmlTags
|
||||||
from content import replaceEmojiFromTags
|
from content import replaceEmojiFromTags
|
||||||
from content import removeLongWords
|
from content import removeLongWords
|
||||||
from content import removeHtml
|
from content import removeHtml
|
||||||
from config import getConfigParam
|
|
||||||
from skills import getSkills
|
from skills import getSkills
|
||||||
from cache import getPersonFromCache
|
from cache import getPersonFromCache
|
||||||
from cache import storePersonInCache
|
from cache import storePersonInCache
|
||||||
|
|
Loading…
Reference in New Issue