mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-11-13 02:30:11 +01:00
server: test using config.get() in case dict value is None
If a key 'foo' is set to None, `if config.get('foo'):` will be false while `if 'foo' in config:` will be true. A None value is not useful here, so config.get() is the better check. Thanks to Adam Pritchard for the suggestion.
This commit is contained in:
parent
ef7c9d89d2
commit
21769e9f0a
@ -42,7 +42,7 @@ def update_awsbucket(repo_section):
|
||||
from libcloud.storage.types import Provider, ContainerDoesNotExistError
|
||||
from libcloud.storage.providers import get_driver
|
||||
|
||||
if 'awsaccesskeyid' not in config or 'awssecretkey' not in config:
|
||||
if not config.get('awsaccesskeyid') or not config.get('awssecretkey'):
|
||||
logging.error('To use awsbucket, you must set awssecretkey and awsaccesskeyid in config.py!')
|
||||
sys.exit(1)
|
||||
awsbucket = config['awsbucket']
|
||||
@ -154,12 +154,12 @@ def main():
|
||||
logging.critical("The only commands currently supported are 'init' and 'update'")
|
||||
sys.exit(1)
|
||||
|
||||
if 'nonstandardwebroot' in config and config['nonstandardwebroot'] == True:
|
||||
if config.get('nonstandardwebroot') == True:
|
||||
standardwebroot = False
|
||||
else:
|
||||
standardwebroot = True
|
||||
|
||||
if 'serverwebroot' in config:
|
||||
if config.get('serverwebroot'):
|
||||
serverwebroot = config['serverwebroot']
|
||||
host, fdroiddir = serverwebroot.rstrip('/').split(':')
|
||||
serverrepobase = os.path.basename(fdroiddir)
|
||||
@ -169,7 +169,7 @@ def main():
|
||||
+ serverwebroot.rstrip('/') + '/fdroid\n\t'
|
||||
+ serverwebroot.rstrip('/').rstrip(serverrepobase) + 'fdroid')
|
||||
sys.exit(1)
|
||||
elif 'awsbucket' not in config:
|
||||
elif not config.get('awsbucket'):
|
||||
logging.warn('No serverwebroot or awsbucket set! Edit your config.py to set one or both.')
|
||||
sys.exit(1)
|
||||
|
||||
@ -178,7 +178,7 @@ def main():
|
||||
repo_sections.append('archive')
|
||||
|
||||
if args[0] == 'init':
|
||||
if serverwebroot != None:
|
||||
if config.get('serverwebroot'):
|
||||
sshargs = ['ssh']
|
||||
if options.quiet:
|
||||
sshargs += ['-q']
|
||||
@ -192,9 +192,9 @@ def main():
|
||||
sys.exit(1)
|
||||
elif args[0] == 'update':
|
||||
for repo_section in repo_sections:
|
||||
if 'serverwebroot' in config:
|
||||
if config.get('serverwebroot'):
|
||||
update_serverwebroot(repo_section)
|
||||
if 'awsbucket' in config:
|
||||
if config.get('awsbucket'):
|
||||
update_awsbucket(repo_section)
|
||||
|
||||
sys.exit(0)
|
||||
|
Loading…
Reference in New Issue
Block a user