LEFT | RIGHT |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # This file is part of the Adblock Plus infrastructure | 3 # This file is part of the Adblock Plus infrastructure |
4 # Copyright (C) 2018-present eyeo GmbH | 4 # Copyright (C) 2018-present eyeo GmbH |
5 # | 5 # |
6 # Adblock Plus is free software: you can redistribute it and/or modify | 6 # Adblock Plus is free software: you can redistribute it and/or modify |
7 # it under the terms of the GNU General Public License version 3 as | 7 # it under the terms of the GNU General Public License version 3 as |
8 # published by the Free Software Foundation. | 8 # published by the Free Software Foundation. |
9 # | 9 # |
10 # Adblock Plus is distributed in the hope that it will be useful, | 10 # Adblock Plus is distributed in the hope that it will be useful, |
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 # GNU General Public License for more details. | 13 # GNU General Public License for more details. |
14 # | 14 # |
15 # You should have received a copy of the GNU General Public License | 15 # You should have received a copy of the GNU General Public License |
16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 |
18 import argparse | 18 import argparse |
19 from filecmp import dircmp | 19 from filecmp import dircmp |
20 import hashlib | 20 import hashlib |
21 import os | 21 import os |
22 import sys | 22 import sys |
23 import shutil | 23 import shutil |
24 import tarfile | 24 import tarfile |
25 import tempfile | 25 import tempfile |
26 import urllib | 26 import urllib |
27 | 27 |
28 | 28 |
29 __doc__ = """This script MUST be renamed in the form of deploy_$WEBSITE, e.g. | 29 __doc__ = """This script MUST be renamed in the form of $WEBSITE, e.g. |
30 deploy_help.eyeo.com, --name must be provided in order to fetch the | 30 help.eyeo.com, --name must be provided in order to fetch the |
31 files, expected files to be fetched are $NAME.tar.gz and $NAME.md5 in | 31 files, expected files to be fetched are $NAME.tar.gz and $NAME.md5 in |
32 order to compare the hashes. --source must be an URL, e.g. | 32 order to compare the hashes. --source must be an URL, e.g. |
33 https://helpcenter.eyeofiles.com""" | 33 https://helpcenter.eyeofiles.com""" |
34 | 34 |
35 | 35 |
36 def download(url, temporary_directory): | 36 def download(url, temporary_directory): |
37 file_name = url.split('/')[-1] | 37 file_name = url.split('/')[-1] |
38 absolute_file_path = os.path.join(temporary_directory, file_name) | 38 absolute_file_path = os.path.join(temporary_directory, file_name) |
39 print 'Downloading: ' + file_name | 39 print 'Downloading: ' + file_name |
40 urllib.urlretrieve(url, absolute_file_path) | 40 urllib.urlretrieve(url, absolute_file_path) |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 for item in source_items: | 90 for item in source_items: |
91 source_path = os.path.join(source, item) | 91 source_path = os.path.join(source, item) |
92 destination_path = os.path.join(destination, item) | 92 destination_path = os.path.join(destination, item) |
93 if os.path.isdir(source_path): | 93 if os.path.isdir(source_path): |
94 copytree(source_path, destination_path) | 94 copytree(source_path, destination_path) |
95 else: | 95 else: |
96 shutil.copy2(source_path, destination_path) | 96 shutil.copy2(source_path, destination_path) |
97 | 97 |
98 | 98 |
99 if __name__ == '__main__': | 99 if __name__ == '__main__': |
100 website = os.path.basename(__file__)[len("deploy_"):] | 100 website = os.path.basename(__file__) |
101 parser = argparse.ArgumentParser( | 101 parser = argparse.ArgumentParser( |
102 description="""Fetch a compressed archive in the form of $NAME.tar.gz | 102 description="""Fetch a compressed archive in the form of $NAME.tar.gz |
103 and deploy it to /var/www/{0} folder""".format(website), | 103 and deploy it to /var/www/{0} folder""".format(website), |
104 epilog=__doc__, | 104 epilog=__doc__, |
105 ) | 105 ) |
106 parser.add_argument('--name', action='store', type=str, required=True, | 106 parser.add_argument('--name', action='store', type=str, required=True, |
107 help='Name of the tarball to deploy') | 107 help='Name of the tarball to deploy') |
108 parser.add_argument('--source', action='store', type=str, required=True, | 108 parser.add_argument('--source', action='store', type=str, required=True, |
109 help='The source where files will be downloaded') | 109 help='The source where files will be downloaded') |
110 arguments = parser.parse_args() | 110 arguments = parser.parse_args() |
(...skipping 13 matching lines...) Expand all Loading... |
124 print 'Deploying files' | 124 print 'Deploying files' |
125 deploy_files(directory_comparison) | 125 deploy_files(directory_comparison) |
126 else: | 126 else: |
127 error_message = """{0}.tar.gz md5 computation doesn't match {0}.md5 | 127 error_message = """{0}.tar.gz md5 computation doesn't match {0}.md5 |
128 contents""".format(name) | 128 contents""".format(name) |
129 sys.exit(error_message) | 129 sys.exit(error_message) |
130 except Exception as error: | 130 except Exception as error: |
131 sys.exit(error) | 131 sys.exit(error) |
132 finally: | 132 finally: |
133 shutil.rmtree(temporary_directory) | 133 shutil.rmtree(temporary_directory) |
LEFT | RIGHT |