def _parser_changelog(changelog_filepath): if not os.path.isfile(changelog_filepath): raise qtciutil.QtCiUtilError("No %s found." % changelog_filepath) with open(changelog_filepath, 'r', encoding='utf-8') as f: content = f.read() m = re.search(r'^.*##\s*(\d+\.\d+.\d+)\s.*\n((.+\n)+)', content) if not m: raise qtciutil.QtCiUtilError( 'The CHANGELOG file is not in the right format.') return (m[1], m[2])
def _parser_readme(readme_filepath): if not os.path.isfile(readme_filepath): raise qtciutil.QtCiUtilError("No %s found." % readme_filepath) with open(readme_filepath, 'r', encoding='utf-8') as f: content = f.read() m = re.search(r'^#(.*)\n', content) if not m: raise qtciutil.QtCiUtilError( 'The README file is not in the right format.') return m[1]
def sincpm_update(): # check sincpm.json if exists filepath = os.path.join(ci_script_dir, "../sincpm.json") if not os.path.isfile(filepath): return # get platform infomation qt_verison_str = qtciutil.qt_version() qmake_spec_str = qtciutil.qmake_spec() compiler_str = qmake_spec_str.split('-')[1] if compiler_str == 'g++': compiler_str = 'gcc' os_system = qtciutil.platform_system() arch_str = 'x64' if os_system == 'windows': arch_str = 'x86' # sincpm update update_args = [sincpm_bin('sincpm'), 'update'] update_args.append('--os=%s' % os_system) update_args.append('--qt=%s' % qt_verison_str) update_args.append('--compiler=%s' % compiler_str) update_args.append('--arch=%s' % arch_str) print("update_args: ", update_args) pinfo = subprocess.run(update_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) if pinfo.returncode != 0: raise qtciutil.QtCiUtilError("sincpm update failed.")
def _parser_module_config(module_json_filepath): if not os.path.isfile(module_json_filepath): raise qtciutil.QtCiUtilError("No %s found." % module_json_filepath) with open(module_json_filepath, 'r', encoding='utf-8') as f: content = f.read() moduleconf_json = json.loads(content) tmp_name = moduleconf_json.get('module_name', '') hook = moduleconf_json.get('hook', '') database_names = [] if (hook != ''): param = urllib.parse.urlencode({'module_name': tmp_name}, quote_via=urllib.parse.quote) r = requests.get(hook, params=param) if (r.status_code != 200): exit(1) hook_ret = r.json() hook_data = hook_ret.get('data', {}) for key in hook_data: urls = key.split('/') urls.reverse() database_names.append(urls[1]) return ', '.join(database_names)
def package(): dist_dir = os.path.join(ci_script_dir, '../dist/') os.environ["PATH"] = os.environ['QT_BIN'] + os.pathsep + os.environ["PATH"] package_name = '{name}-{version}-upgrade-{dt}'.format( name=module_name, version=version, dt=time.strftime("%Y%m%d%H%M")) archive_dir = os.path.join(ci_script_dir, '../archive/') packaging_dist = os.path.join(ci_script_dir, '../archive/%s/' % package_name) if os.path.isdir(archive_dir): shutil.rmtree(archive_dir, ignore_errors=True) os.makedirs(packaging_dist) package_program_filepath = '' package_config_filepath = os.path.join( ci_script_dir, 'upgrade-package-{}.json'.format(platform.system().lower())) # modify release_note module_json_filepath = os.path.join(ci_script_dir, '../module.json') with open(module_json_filepath, 'r', encoding='utf-8') as f: moduleconf_content = f.read() moduleconf_json = json.loads(moduleconf_content) moduleconf_json['version'] = version moduleconf_json['change_log'] = changelog moduleconf_json['is_module'] = 1 moduleconf_json[ 'remark'] = 'Update package is automatically published by CI.' with open(package_config_filepath, 'r', encoding='utf-8') as f: package_config_content = f.read() content_json = json.loads(package_config_content) content_str = json.dumps(moduleconf_json, ensure_ascii=False) content_json['release_note'] = content_str with open(package_config_filepath, 'w', encoding='utf-8') as f: json.dump(content_json, f, ensure_ascii=False, indent=4) package_output_filepath = "%s/%s.pkg" % (packaging_dist, package_name) if platform.system() == 'Windows': package_program_filepath = dist_dir + "/topikm/qt5.6.3-win32-msvc2015/bin/TopUpgradePackager.exe" elif platform.system() == 'Linux': package_program_filepath = dist_dir + "/topikm/qt5.6.3-linuxx86_64/bin/TopUpgradePackager" package_args = [ package_program_filepath, '-c', package_config_filepath, '-d', package_output_filepath, '-H', 'yes' ] print("package_args: ", package_args) pinfo = subprocess.run(package_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) print(pinfo.stdout.decode('utf-8')) if pinfo.returncode != 0: raise qtciutil.QtCiUtilError("package failed.") # Copy README.md and CHANGELOG.md shutil.copy(os.path.join(ci_script_dir, '../README.md'), packaging_dist) shutil.copy(os.path.join(ci_script_dir, '../CHANGELOG.md'), packaging_dist) # upload to database # upload_program_filepath = '' # if platform.system() == 'Windows': # upload_program_filepath = dist_dir + "/topikm/qt5.6.3-win32-msvc2015/bin/PackageUploaderPlus.exe" # elif platform.system() == 'Linux': # upload_program_filepath = dist_dir + "/topikm/qt5.6.3-linuxx86_64/bin/PackageUploaderPlus" # upload_args = [ # upload_program_filepath, # '-u', package_output_filepath, # module_json_filepath # ] # pinfo = subprocess.run(upload_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) # if pinfo.returncode != 0: # raise qtciutil.QtCiUtilError("upload failed. %s" % pinfo.stdout.decode('utf-8')) os.chdir(os.path.join(ci_script_dir, '../archive/')) if platform.system() == 'Linux': shutil.make_archive(package_name, 'gztar', base_dir=package_name) archive_filepath = os.path.join(os.getcwd(), package_name + ".tar.gz") elif platform.system() == 'Windows': shutil.make_archive(package_name, 'zip', base_dir=package_name) archive_filepath = os.path.join(os.getcwd(), package_name + ".zip") else: raise qtciutil.QtCiUtilError( 'This platform is currently not supported.') return archive_filepath