From 78dd2626ca75eb572a965fb9cf40f9563fe32a75 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Tue, 18 Jul 2017 15:36:50 +0200 Subject: [PATCH 1/4] [CUSTOM_APP] Add a zim_path option to build_custom_app.py If the user what to make a custom_app locally, he will need to download the zim file before. As he has already the zim, it is better to give the zim_path instead of give the zim_url and have `build_custom_app.py` download a second time the zim. --- build_custom_app.py | 55 +++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/build_custom_app.py b/build_custom_app.py index 114128c..f6ce3e8 100755 --- a/build_custom_app.py +++ b/build_custom_app.py @@ -59,13 +59,14 @@ def parse_args(): parser.add_argument('--step', default='launch', choices=['launch', 'publish'], help=argparse.SUPPRESS) parser.add_argument('--apks-dir', help=argparse.SUPPRESS) parser.add_argument('--version', default="0", help=argparse.SUPPRESS) + parser.add_argument('--zim-path', default=None, help=argparse.SUPPRESS) parser.add_argument('--content-version-code', type=int) parser.add_argument('--package-name', default=None, help=argparse.SUPPRESS) parser.add_argument('--google-api-key', help=argparse.SUPPRESS) options = parser.parse_args() - if not options.package_name or not options.zim_url: + if not options.package_name or not (options.zim_url or options.zim_path): if not options.package_name: print("Try to get package name from info.json file") if not options.zim_url: @@ -102,38 +103,44 @@ def download_zim_file(zim_url, dest_dir=None): return os.path.join(dest_dir, out_filename) -def get_zim_size(zim_url, check_certificate=True): +def get_zim_size(*, zim_url=None, zim_path=None, check_certificate=True): print("Try to get zim size") - if not check_certificate: - context = ssl.create_default_context() - context.check_hostname = False - context.verify_mode = ssl.CERT_NONE - else: - context = None - extra_args = {'context':context} if sys.version_info >= (3, 4, 3) else {} - with urllib.request.urlopen(zim_url, **extra_args) as resource: - size = resource.getheader('Content-Length', None) - if size is not None: - size = int(size) - print("Zim size is {}".format(size)) - return size - else: - print("No 'Content-Length' header in http answer from the server.\n" - "We need to download the zim file to get its size.") - zim_path = download_zim_file(zim_url, tempfile.gettempdir()) - size = os.path.getsize(zim_path) - print("Zim size is {}".format(size)) - return size + if not zim_path: + if not check_certificate: + context = ssl.create_default_context() + context.check_hostname = False + context.verify_mode = ssl.CERT_NONE + else: + context = None + extra_args = {'context':context} if sys.version_info >= (3, 4, 3) else {} + with urllib.request.urlopen(zim_url, **extra_args) as resource: + size = resource.getheader('Content-Length', None) + if size is not None: + size = int(size) + print("Zim size is {}".format(size)) + return size + else: + print("No 'Content-Length' header in http answer from the server.\n" + "We need to download the zim file to get its size.") + zim_path = download_zim_file(zim_url, tempfile.gettempdir()) + + size = os.path.getsize(zim_path) + print("Zim size is {}".format(size)) + return size def do_launch(options): - zim_size = get_zim_size(options.zim_url, options.check_certificate) + if options.zim_path: + zim_size = get_zim_size(zim_path=options.zim_path) + else: + zim_size = get_zim_size(zim_url=options.zim_url, + check_certificate=options.check_certificate) travis_launch_build('kiwix', 'kiwix-build', options, zim_size) print("Travis build has been launch.") def do_publish(options): - zim_path = download_zim_file(options.zim_url) + zim_path = options.zim_path or download_zim_file(options.zim_url) googleService = Google(options) with googleService.new_request(): versionCodes = [] From 39501fe724580f3881353c9b7e77cb0d9c35fccb Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Tue, 18 Jul 2017 15:43:04 +0200 Subject: [PATCH 2/4] Copy icu data at the right place. `kiwix-android` now use all files in "icu" assets directory. Not anymore directly the `icudt.dat` file. --- dependencies.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/dependencies.py b/dependencies.py index 9d47086..3acd526 100644 --- a/dependencies.py +++ b/dependencies.py @@ -380,8 +380,15 @@ class KiwixAndroid(Dependency): shutil.rmtree(pj(self.build_path, 'kiwixlib', 'src', 'main')) except FileNotFoundError: pass - shutil.copytree(pj(self.buildEnv.install_dir, 'kiwix-lib'), pj(self.build_path, 'kiwixlib', 'src', 'main')) - shutil.copy2(pj(self.buildEnv.install_dir, 'share', 'icu', '58.2', 'icudt58l.dat'), pj(self.build_path, 'app', 'src', 'main', 'assets', 'icudt.dat')) + shutil.copytree(pj(self.buildEnv.install_dir, 'kiwix-lib'), + pj(self.build_path, 'kiwixlib', 'src', 'main')) + os.makedirs( + pj(self.build_path, 'app', 'src', 'main', 'assets', 'icu'), + exist_ok=True) + shutil.copy2(pj(self.buildEnv.install_dir, 'share', 'icu', '58.2', + 'icudt58l.dat'), + pj(self.build_path, 'app', 'src', 'main', 'assets', + 'icu', 'icudt58l.dat')) class KiwixCustomApp(Dependency): @@ -460,8 +467,15 @@ class KiwixCustomApp(Dependency): shutil.rmtree(pj(self.build_path, 'kiwixlib', 'src', 'main')) except FileNotFoundError: pass - shutil.copytree(pj(self.buildEnv.install_dir, 'kiwix-lib'), pj(self.build_path, 'kiwixlib', 'src', 'main')) - shutil.copy2(pj(self.buildEnv.install_dir, 'share', 'icu', '58.2', 'icudt58l.dat'), pj(self.build_path, 'app', 'src', 'main', 'assets', 'icudt.dat')) + shutil.copytree(pj(self.buildEnv.install_dir, 'kiwix-lib'), + pj(self.build_path, 'kiwixlib', 'src', 'main')) + os.makedirs( + pj(self.build_path, 'app', 'src', 'main', 'assets', 'icu'), + exist_ok=True) + shutil.copy2(pj(self.buildEnv.install_dir, 'share', 'icu', '58.2', + 'icudt58l.dat'), + pj(self.build_path, 'app', 'src', 'main', 'assets', + 'icu', 'icudt58l.dat')) # Generate custom directory try: From f16c90909080a73be1b64c991d6c2eb85c6199b9 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Tue, 18 Jul 2017 15:53:29 +0200 Subject: [PATCH 3/4] [CUSTOM_APP] Correctly set the version_name. The version_name need to be set a compilation time. By default the version_name is taken from json info file. But a user may want to change it. --- build_custom_app.py | 14 +++++++++++--- dependencies.py | 2 ++ travis/make_release.sh | 1 - 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/build_custom_app.py b/build_custom_app.py index f6ce3e8..a0fdd0e 100755 --- a/build_custom_app.py +++ b/build_custom_app.py @@ -51,6 +51,8 @@ def parse_args(): advance = parser.add_argument_group('advance', "Some advanced options.") advance.add_argument('--extra-code', type=int, default=0) + advance.add_argument('--version-name', default=None, + help="The version of the application (seen by user). Get from json info file by default.") advance.add_argument('--check-certificate', default=True) advance.add_argument('--zim-url', default=None) advance.add_argument('--no-android-upload', action='store_false', dest='android_upload') @@ -58,7 +60,6 @@ def parse_args(): # Hidden options parser.add_argument('--step', default='launch', choices=['launch', 'publish'], help=argparse.SUPPRESS) parser.add_argument('--apks-dir', help=argparse.SUPPRESS) - parser.add_argument('--version', default="0", help=argparse.SUPPRESS) parser.add_argument('--zim-path', default=None, help=argparse.SUPPRESS) parser.add_argument('--content-version-code', type=int) parser.add_argument('--package-name', default=None, help=argparse.SUPPRESS) @@ -66,11 +67,15 @@ def parse_args(): options = parser.parse_args() - if not options.package_name or not (options.zim_url or options.zim_path): + if (not options.package_name + or not (options.zim_url or options.zim_path) + or not options.version_name): if not options.package_name: print("Try to get package name from info.json file") if not options.zim_url: print("Try to get zim url from info.json file") + if not options.version_name: + print("Try to get version_name form info.json file") request_url = ('https://raw.githubusercontent.com/kiwix/kiwix-android-custom/master/{}/info.json' .format(options.custom_app)) json_request = requests.get(request_url) @@ -85,6 +90,9 @@ def parse_args(): if not options.zim_url: print("Found zim_url '{}'".format(json_data['zim_url'])) options.zim_url = json_data['zim_url'] + if not options.version_name: + print("Found version_name '{}'".format(json_data['version_name'])) + options.version_name = json_data['version_name'] options.base_version = "{}{}".format( datetime.date.today().strftime('%y%j'), @@ -179,7 +187,7 @@ def travis_launch_build(organisation, repository, options, zim_size): { 'ZIM_URL': options.zim_url}, { 'EXTRA_CODE': options.extra_code}, { 'CONTENT_VERSION_CODE': gen_version_code(0, options.base_version)}, - { 'VERSION': options.version}, + { 'VERSION_NAME': options.version_name}, # google_key { 'secure': ('VAgKBMx0KEIyJlSnpM4YrHKLALIbaibkhlsgiv19ITa6dODoEIqeYHz' 'wFTiL3mRHU6HwtXtdNb/JeMle9NfHJVFSV56ZgFzX7ev9zr0YG0qZQv' diff --git a/dependencies.py b/dependencies.py index 3acd526..cd40569 100644 --- a/dependencies.py +++ b/dependencies.py @@ -413,11 +413,13 @@ class KiwixCustomApp(Dependency): template = ("-i -P customDir={customDir}" " -P zim_file_size={zim_size}" " -P version_code={version_code}" + " -P version_name={version_name}" " -P content_version_code={content_version_code}") return template.format( customDir=pj(self.build_path, 'custom'), zim_size=self._get_zim_size(), version_code=os.environ['VERSION_CODE'], + version_name=os.environ['VERSION_NAME'], content_version_code=os.environ['CONTENT_VERSION_CODE']) @property diff --git a/travis/make_release.sh b/travis/make_release.sh index a7524ee..4f2e034 100755 --- a/travis/make_release.sh +++ b/travis/make_release.sh @@ -22,7 +22,6 @@ ${TRAVIS_BUILD_DIR}/build_custom_app.py \ --custom-app ${CUSTOM_APP} \ --package-name ${PACKAGE_NAME} \ --google-api-key ${GOOGLE_API_KEY} \ - --version ${VERSION} \ --zim-url ${ZIM_URL} \ --apks-dir ${HOME}/APKS \ --content-version-code ${CONTENT_VERSION_CODE} From d04af4661a0531005b14f8fdb58c916a09b66a85 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Tue, 18 Jul 2017 15:55:09 +0200 Subject: [PATCH 4/4] [CUSTOM_APP] Small fixes of help of options. --- build_custom_app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build_custom_app.py b/build_custom_app.py index a0fdd0e..454ad7f 100755 --- a/build_custom_app.py +++ b/build_custom_app.py @@ -54,14 +54,14 @@ def parse_args(): advance.add_argument('--version-name', default=None, help="The version of the application (seen by user). Get from json info file by default.") advance.add_argument('--check-certificate', default=True) - advance.add_argument('--zim-url', default=None) + advance.add_argument('--zim-url', default=None, help="Get from json info file by default.") advance.add_argument('--no-android-upload', action='store_false', dest='android_upload') # Hidden options parser.add_argument('--step', default='launch', choices=['launch', 'publish'], help=argparse.SUPPRESS) parser.add_argument('--apks-dir', help=argparse.SUPPRESS) parser.add_argument('--zim-path', default=None, help=argparse.SUPPRESS) - parser.add_argument('--content-version-code', type=int) + parser.add_argument('--content-version-code', type=int, help=argparse.SUPPRESS) parser.add_argument('--package-name', default=None, help=argparse.SUPPRESS) parser.add_argument('--google-api-key', help=argparse.SUPPRESS)