| 1 |
#!/usr/bin/env python |
| 2 |
|
| 3 |
""" |
| 4 |
Must have the vollowing environment variables defined: |
| 5 |
* BUCKET_NAME : AWS bucket name |
| 6 |
* PREFIX : 'latest' or other version number |
| 7 |
|
| 8 |
""" |
| 9 |
|
| 10 |
import os |
| 11 |
import pip |
| 12 |
import tempfile |
| 13 |
import subprocess |
| 14 |
import thermopyl.version |
| 15 |
|
| 16 |
|
| 17 |
BUCKET_NAME = 'thermopyl.org' |
| 18 |
if not thermopyl.version.release: |
| 19 |
PREFIX = 'latest' |
| 20 |
else: |
| 21 |
PREFIX = thermopyl.version.short_version |
| 22 |
|
| 23 |
if not any(d.project_name == 's3cmd' for d in pip.get_installed_distributions()): |
| 24 |
raise ImportError('The s3cmd pacakge is required. try $ pip install s3cmd') |
| 25 |
# The secret key is available as a secure environment variable |
| 26 |
# on travis-ci to push the build documentation to Amazon S3. |
| 27 |
with tempfile.NamedTemporaryFile('w') as f: |
| 28 |
f.write('''[default] |
| 29 |
access_key = {AWS_ACCESS_KEY_ID} |
| 30 |
secret_key = {AWS_SECRET_ACCESS_KEY} |
| 31 |
'''.format(**os.environ)) |
| 32 |
f.flush() |
| 33 |
|
| 34 |
template = ('s3cmd --guess-mime-type --config {config} ' |
| 35 |
'sync docs/_build/ s3://{bucket}/{prefix}/') |
| 36 |
cmd = template.format( |
| 37 |
config=f.name, |
| 38 |
bucket=BUCKET_NAME, |
| 39 |
prefix=PREFIX) |
| 40 |
return_val = subprocess.call(cmd.split()) |
| 41 |
|
| 42 |
# Sync index file. |
| 43 |
template = ('s3cmd --guess-mime-type --config {config} ' |
| 44 |
'sync devtools/ci/index.html s3://{bucket}/') |
| 45 |
cmd = template.format( |
| 46 |
config=f.name, |
| 47 |
bucket=BUCKET_NAME) |
| 48 |
return_val = subprocess.call(cmd.split()) |