From c84308da6f129bf3c4cabc16f41d115de1a96b08 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Wed, 28 Feb 2018 12:27:41 -0500 Subject: [PATCH] minor code review of Python scripts --- dist/firefox/publish-signed-beta.py | 5 +++++ tools/make-firefox-meta.py | 25 +++++++++++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/dist/firefox/publish-signed-beta.py b/dist/firefox/publish-signed-beta.py index f786f5f50..fbc297224 100755 --- a/dist/firefox/publish-signed-beta.py +++ b/dist/firefox/publish-signed-beta.py @@ -36,6 +36,11 @@ from string import Template projdir = os.path.split(os.path.abspath(__file__))[0] while not os.path.isdir(os.path.join(projdir, '.git')): projdir = os.path.normpath(os.path.join(projdir, '..')) +# Check that found project root is valid +version_filepath = os.path.join(projdir, 'dist', 'version') +if not os.path.isfile(version_filepath): + print('Version file not found.') + exit(1) extension_id = 'uBlock0@raymondhill.net' tmpdir = tempfile.TemporaryDirectory() diff --git a/tools/make-firefox-meta.py b/tools/make-firefox-meta.py index 8285e0943..efa77013c 100644 --- a/tools/make-firefox-meta.py +++ b/tools/make-firefox-meta.py @@ -20,6 +20,17 @@ def mkdirs(path): pj = os.path.join +# Find path to project root +proj_dir = os.path.split(os.path.abspath(__file__))[0] +while not os.path.isdir(os.path.join(proj_dir, '.git')): + proj_dir = os.path.normpath(os.path.join(proj_dir, '..')) + +# Check that found project root is valid +version_filepath = os.path.join(proj_dir, 'dist', 'version') +if not os.path.isfile(version_filepath): + print('Version file not found.') + exit(1) + build_dir = os.path.abspath(sys.argv[1]) source_locale_dir = pj(build_dir, '_locales') target_locale_dir = pj(build_dir, 'locale') @@ -60,19 +71,18 @@ with open(chrome_manifest, 'at', encoding='utf-8', newline='\n') as f: rmtree(source_locale_dir) # update install.rdf -proj_dir = pj(os.path.split(os.path.abspath(__file__))[0], '..') - -version = '' -with open(os.path.join(proj_dir, 'dist', 'version')) as f: - version = f.read().strip() chromium_manifest = pj(proj_dir, 'platform', 'chromium', 'manifest.json') with open(chromium_manifest, encoding='utf-8') as m: manifest = json.load(m) +# Fetch extension version # https://developer.mozilla.org/en-US/Add-ons/AMO/Policy/Maintenance#How_do_I_submit_a_Beta_add-on.3F # "To create a beta channel [...] '(a|alpha|b|beta|pre|rc)\d*$' " +version = '' +with open(version_filepath) as f: + version = f.read().strip() match = re.search('^(\d+\.\d+\.\d+)(\.\d+)$', version) if match: buildtype = int(match.group(2)[1:]) @@ -80,9 +90,8 @@ if match: builttype = 'b' + str(buildtype) else: builttype = 'rc' + str(buildtype - 100) - manifest['version'] = match.group(1) + builttype -else: - manifest['version'] = version + version = match.group(1) + builttype +manifest['version'] = version manifest['homepage'] = 'https://github.com/gorhill/uBlock' manifest['description'] = descriptions['en']