1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-11-14 02:50:12 +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:
Hans-Christoph Steiner 2014-04-23 19:52:37 -04:00
parent ef7c9d89d2
commit 21769e9f0a

View File

@ -42,7 +42,7 @@ def update_awsbucket(repo_section):
from libcloud.storage.types import Provider, ContainerDoesNotExistError from libcloud.storage.types import Provider, ContainerDoesNotExistError
from libcloud.storage.providers import get_driver 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!') logging.error('To use awsbucket, you must set awssecretkey and awsaccesskeyid in config.py!')
sys.exit(1) sys.exit(1)
awsbucket = config['awsbucket'] awsbucket = config['awsbucket']
@ -154,12 +154,12 @@ def main():
logging.critical("The only commands currently supported are 'init' and 'update'") logging.critical("The only commands currently supported are 'init' and 'update'")
sys.exit(1) sys.exit(1)
if 'nonstandardwebroot' in config and config['nonstandardwebroot'] == True: if config.get('nonstandardwebroot') == True:
standardwebroot = False standardwebroot = False
else: else:
standardwebroot = True standardwebroot = True
if 'serverwebroot' in config: if config.get('serverwebroot'):
serverwebroot = config['serverwebroot'] serverwebroot = config['serverwebroot']
host, fdroiddir = serverwebroot.rstrip('/').split(':') host, fdroiddir = serverwebroot.rstrip('/').split(':')
serverrepobase = os.path.basename(fdroiddir) serverrepobase = os.path.basename(fdroiddir)
@ -169,7 +169,7 @@ def main():
+ serverwebroot.rstrip('/') + '/fdroid\n\t' + serverwebroot.rstrip('/') + '/fdroid\n\t'
+ serverwebroot.rstrip('/').rstrip(serverrepobase) + 'fdroid') + serverwebroot.rstrip('/').rstrip(serverrepobase) + 'fdroid')
sys.exit(1) 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.') logging.warn('No serverwebroot or awsbucket set! Edit your config.py to set one or both.')
sys.exit(1) sys.exit(1)
@ -178,7 +178,7 @@ def main():
repo_sections.append('archive') repo_sections.append('archive')
if args[0] == 'init': if args[0] == 'init':
if serverwebroot != None: if config.get('serverwebroot'):
sshargs = ['ssh'] sshargs = ['ssh']
if options.quiet: if options.quiet:
sshargs += ['-q'] sshargs += ['-q']
@ -192,9 +192,9 @@ def main():
sys.exit(1) sys.exit(1)
elif args[0] == 'update': elif args[0] == 'update':
for repo_section in repo_sections: for repo_section in repo_sections:
if 'serverwebroot' in config: if config.get('serverwebroot'):
update_serverwebroot(repo_section) update_serverwebroot(repo_section)
if 'awsbucket' in config: if config.get('awsbucket'):
update_awsbucket(repo_section) update_awsbucket(repo_section)
sys.exit(0) sys.exit(0)