minor code review of Python scripts

This commit is contained in:
Raymond Hill 2018-02-28 12:27:41 -05:00
parent 94afd504ee
commit c84308da6f
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 22 additions and 8 deletions

View File

@ -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()

View File

@ -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,8 +90,7 @@ if match:
builttype = 'b' + str(buildtype)
else:
builttype = 'rc' + str(buildtype - 100)
manifest['version'] = match.group(1) + builttype
else:
version = match.group(1) + builttype
manifest['version'] = version
manifest['homepage'] = 'https://github.com/gorhill/uBlock'