1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#!/usr/bin/env python
# Ubuntu CI Engine
# Copyright 2014 Canonical Ltd.
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License version 3, as
# published by the Free Software Foundation.
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranties of
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import atexit
import logging
import os
import subprocess
import shutil
import sys
import tempfile
try:
from webui import settings
except ImportError:
logging.error(
'Collect static files requires access to the "webui" module. '
' Please run this script inside the project venv.')
sys.exit(1)
def main():
tmp = tempfile.mkdtemp()
atexit.register(shutil.rmtree, tmp)
logging.info("Collecting static assets in {}".format(tmp))
bin_dir = os.path.dirname(os.path.abspath(__file__))
working_dir = os.path.abspath(os.path.join(bin_dir, os.pardir))
manager_path = os.path.join(working_dir, 'webui', 'manage.py')
# Pass explict --settings using shell because 'DJANGO_SETTINGS_MODULE'
# variable might be populated by other django project (ticket-system).
subprocess.check_output(
'{} collectstatic --noinput --settings=webui.settings'.format(
manager_path),
cwd=tmp, shell=True,
)
tarfile = 'webui_content.tgz'
logging.info("Building {}".format(tarfile))
subprocess.check_output(
['tar', 'czvf', tarfile, settings.STATIC_ROOT],
cwd=tmp,
)
logging.info("Uploading {} to charmblobs".format(tarfile))
subprocess.check_output(
['swift', 'upload', 'charmblobs', os.path.basename(tarfile)],
cwd=tmp,
)
if __name__ == "__main__":
logging.basicConfig(level=logging.WARN,
format="%(asctime)s %(levelname)s %(message)s")
main()
|