server: automatically create S3 bucket when using s3cmd

This commit is contained in:
Hans-Christoph Steiner 2017-09-29 17:50:23 +02:00
parent 0c4dc9779e
commit b6067e6a1f

View file

@ -79,22 +79,29 @@ def update_awsbucket_s3cmd(repo_section):
os.write(fd, ('secret_key = ' + config['awssecretkey'] + '\n').encode('utf-8')) os.write(fd, ('secret_key = ' + config['awssecretkey'] + '\n').encode('utf-8'))
os.close(fd) os.close(fd)
s3url = 's3://' + config['awsbucket'] + '/fdroid/' s3bucketurl = 's3://' + config['awsbucket']
s3cmdargs = [ s3cmd = [config['s3cmd'], '--config=' + configfilename]
's3cmd', if subprocess.call(s3cmd + ['info', s3bucketurl]) != 0:
'sync', logging.warning(_('Creating new S3 bucket: {url}')
'--config=' + configfilename, .format(url=s3bucketurl))
'--acl-public', if subprocess.call(s3cmd + ['mb', s3bucketurl]) != 0:
] logging.error(_('Failed to create S3 bucket: {url}')
.format(url=s3bucketurl))
raise FDroidException()
s3cmd_sync = s3cmd + ['sync', '--acl-public']
if options.verbose: if options.verbose:
s3cmdargs += ['--verbose'] s3cmd_sync += ['--verbose']
if options.quiet: if options.quiet:
s3cmdargs += ['--quiet'] s3cmd_sync += ['--quiet']
indexxml = os.path.join(repo_section, 'index.xml') indexxml = os.path.join(repo_section, 'index.xml')
indexjar = os.path.join(repo_section, 'index.jar') indexjar = os.path.join(repo_section, 'index.jar')
indexv1jar = os.path.join(repo_section, 'index-v1.jar') indexv1jar = os.path.join(repo_section, 'index-v1.jar')
s3url = s3bucketurl + '/fdroid/'
logging.debug('s3cmd sync new files in ' + repo_section + ' to ' + s3url) logging.debug('s3cmd sync new files in ' + repo_section + ' to ' + s3url)
if subprocess.call(s3cmdargs + logging.debug(_('Running first pass with MD5 checking disabled'))
if subprocess.call(s3cmd_sync +
['--no-check-md5', '--skip-existing', ['--no-check-md5', '--skip-existing',
'--exclude', indexxml, '--exclude', indexxml,
'--exclude', indexjar, '--exclude', indexjar,
@ -102,7 +109,7 @@ def update_awsbucket_s3cmd(repo_section):
repo_section, s3url]) != 0: repo_section, s3url]) != 0:
raise FDroidException() raise FDroidException()
logging.debug('s3cmd sync all files in ' + repo_section + ' to ' + s3url) logging.debug('s3cmd sync all files in ' + repo_section + ' to ' + s3url)
if subprocess.call(s3cmdargs + if subprocess.call(s3cmd_sync +
['--no-check-md5', ['--no-check-md5',
'--exclude', indexxml, '--exclude', indexxml,
'--exclude', indexjar, '--exclude', indexjar,
@ -110,14 +117,15 @@ def update_awsbucket_s3cmd(repo_section):
repo_section, s3url]) != 0: repo_section, s3url]) != 0:
raise FDroidException() raise FDroidException()
logging.debug('s3cmd sync indexes ' + repo_section + ' to ' + s3url + ' and delete') logging.debug(_('s3cmd sync indexes {path} to {url} and delete')
s3cmdargs.append('--delete-removed') .format(path=repo_section, url=s3url))
s3cmdargs.append('--delete-after') s3cmd_sync.append('--delete-removed')
s3cmd_sync.append('--delete-after')
if options.no_checksum: if options.no_checksum:
s3cmdargs.append('--no-check-md5') s3cmd_sync.append('--no-check-md5')
else: else:
s3cmdargs.append('--check-md5') s3cmd_sync.append('--check-md5')
if subprocess.call(s3cmdargs + [repo_section, s3url]) != 0: if subprocess.call(s3cmd_sync + [repo_section, s3url]) != 0:
raise FDroidException() raise FDroidException()