summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2017-04-26 23:49:31 +0200
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2017-05-19 03:43:32 +0200
commit4e8a9345150c5948655f1c04a9ddbb554db24543 (patch)
tree460adc30aeb52f6b8a8b4f1e68f927d0620720e4 /bin
parent3bde01f77ae54e8fb99783081e2bf49479168425 (diff)
simplify path handling in the updater scripts
Change-Id: Idcf7f9cedc2368f6a4e4e10c2852cc9b1125b712
Diffstat (limited to 'bin')
-rwxr-xr-xbin/update/create_full_mar.py20
-rwxr-xr-xbin/update/create_full_mar_for_languages.py14
-rwxr-xr-xbin/update/create_partial_update.py53
3 files changed, 45 insertions, 42 deletions
diff --git a/bin/update/create_full_mar.py b/bin/update/create_full_mar.py
index 649eafe2bfa6..a9d7aa2b9fe5 100755
--- a/bin/update/create_full_mar.py
+++ b/bin/update/create_full_mar.py
@@ -8,19 +8,19 @@ import json
from tools import uncompress_file_to_dir, get_file_info, make_complete_mar_name
from config import parse_config
from signing import sign_mar_file
+from path import UpdaterPath
current_dir_path = os.path.dirname(os.path.realpath(__file__))
+def ensure_dir_exist()
+
def main():
- print(sys.argv)
- if len(sys.argv) < 7:
- print("Usage: create_full_mar_for_languages.py $PRODUCTNAME $WORKDIR $TARGETDIR $TEMPDIR $FILENAMEPREFIX $UPDATE_CONFIG")
+ if len(sys.argv) < 5:
+ print("Usage: create_full_mar_for_languages.py $PRODUCTNAME $WORKDIR $FILENAMEPREFIX $UPDATE_CONFIG")
sys.exit(1)
- update_config = sys.argv[6]
- filename_prefix = sys.argv[5]
- temp_dir = sys.argv[4]
- target_dir = sys.argv[3]
+ update_config = sys.argv[4]
+ filename_prefix = sys.argv[3]
workdir = sys.argv[2]
product_name = sys.argv[1]
@@ -28,6 +28,12 @@ def main():
print("missing update config")
sys.exit(1)
+ update_path = UpdaterPath(workdir)
+ update_path.ensure_dir_exist()
+
+ target_dir = update_path.get_update_dir()
+ temp_dir = update_path.get_current_build_dir()
+
config = parse_config(update_config)
tar_dir = os.path.join(workdir, "installation", product_name, "archive", "install", "en-US")
diff --git a/bin/update/create_full_mar_for_languages.py b/bin/update/create_full_mar_for_languages.py
index 7daf5fe6034e..98e1b1c539e7 100755
--- a/bin/update/create_full_mar_for_languages.py
+++ b/bin/update/create_full_mar_for_languages.py
@@ -8,6 +8,7 @@ import json
from tools import uncompress_file_to_dir, get_file_info
from config import parse_config
+from path import UpdaterPath
current_dir_path = os.path.dirname(os.path.realpath(__file__))
@@ -22,18 +23,19 @@ def create_lang_infos(mar_file_name, language, url):
return data
def main():
- print(sys.argv)
- if len(sys.argv) < 7:
+ if len(sys.argv) < 5:
print("Usage: create_full_mar_for_languages.py $PRODUCTNAME $WORKDIR $TARGETDIR $TEMPDIR $FILENAMEPREFIX $UPDATE_CONFIG")
sys.exit(1)
- update_config = sys.argv[6]
- filename_prefix = sys.argv[5]
- temp_dir = sys.argv[4]
- target_dir = sys.argv[3]
+ update_config = sys.argv[4]
+ filename_prefix = sys.argv[3]
workdir = sys.argv[2]
product_name = sys.argv[1]
+ updater_path = UpdaterPath(workdir)
+ target_dir = updater_path.get_update_dir()
+ temp_dir = updater_path.get_language_dir()
+
config = parse_config(update_config)
mar_executable = os.environ.get('MAR', 'mar')
diff --git a/bin/update/create_partial_update.py b/bin/update/create_partial_update.py
index ca194325d20d..419a8f65226b 100755
--- a/bin/update/create_partial_update.py
+++ b/bin/update/create_partial_update.py
@@ -10,12 +10,19 @@ import json
from config import parse_config
from uncompress_mar import extract_mar
-from tools import get_file_info
+from tools import get_file_info, get_hash
from signing import sign_mar_file
+from path import UpdaterPath, mkdir_p
+
BUF_SIZE = 1024
current_dir_path = os.path.dirname(os.path.realpath(__file__))
+def InvalidFileException(Exception):
+
+ def __init__(self, *args, **kwargs):
+ super().__init__(self, *args, **kwargs)
+
def download_file(filepath, url, hash_string):
with open(filepath, "wb") as f:
response = requests.get(url, stream=True)
@@ -26,26 +33,10 @@ def download_file(filepath, url, hash_string):
for block in response.iter_content(1024):
f.write(block)
- with open(filepath, "rb") as f:
- sha512 = hashlib.sha512()
- while True:
- data = f.read(BUF_SIZE)
- if not data:
- break
- sha512.update(data)
- file_hash = sha512.hexdigest()
+ file_hash = get_hash(filepath)
if file_hash != hash_string:
- pass
-
-def mkdir_p(path):
- try:
- os.makedirs(path)
- except OSError as exc: # Python >2.5
- if exc.errno == errno.EEXIST and os.path.isdir(path):
- pass
- else:
- raise
+ raise InvalidFileException()
def handle_language(lang_entries, filedir):
mar = os.environ.get('MAR', 'mar')
@@ -109,16 +100,20 @@ def add_single_dir(path):
return dir_name[0]
def main():
- product_name = sys.argv[1]
- workdir = sys.argv[2]
- update_dir = sys.argv[3]
- temp_dir = sys.argv[4]
- mar_name_prefix = sys.argv[5]
- update_config = sys.argv[6]
- platform = sys.argv[7]
- current_build_path = sys.argv[8]
- build_id = sys.argv[9]
- mar_dir = sys.argv[10]
+ workdir = sys.argv[1]
+
+ updater_path = UpdaterPath(workdir)
+ updater_path.ensure_dir_exist()
+
+ mar_name_prefix = sys.argv[2]
+ update_config = sys.argv[3]
+ platform = sys.argv[4]
+ build_id = sys.argv[5]
+
+ current_build_path = updater_path.get_current_build_dir()
+ mar_dir = updater_path.get_mar_dir()
+ temp_dir = updater_path.get_previous_build_dir()
+ update_dir = updater_path.get_update_dir()
current_build_path = add_single_dir(current_build_path)