def tweak_webdriver_manager(): """webdriver-manager (version 13.0.0) uses `os.arch()` to determine the architecture of the operating system, however, this function can only be used to determine the architecture of the machine that compiled `node`. In the case of Windows, we are using the portable version, which was compiled on `ia32` machine so that is the value returned by this `os.arch` function. Unfortunately, webdriver-manager seems to assume that Windows wouldn't run on the ia32 architecture, so its help function used to determine download link returns null for this, which means that the application has no idea about where to download the correct version. https://github.com/angular/webdriver-manager/blob/b7539a5a3897a8a76abae7245f0de8175718b142/lib/provider/chromedriver.ts#L16 https://github.com/angular/webdriver-manager/blob/b7539a5a3897a8a76abae7245f0de8175718b142/lib/provider/geckodriver.ts#L21 https://github.com/angular/webdriver-manager/blob/b7539a5a3897a8a76abae7245f0de8175718b142/lib/provider/chromedriver.ts#L167 https://github.com/nodejs/node/issues/17036 """ try: if common.is_windows_os(): regex_pattern = PATTERN_FOR_REPLACE_WEBDRIVER_CODE arch = 'x64' if common.is_x64_architecture() else 'x86' replace = 'this.osArch = "%s";' % arch common.inplace_replace_file(CHROME_PROVIDER_FILE_PATH, regex_pattern, replace) common.inplace_replace_file(GECKO_PROVIDER_FILE_PATH, regex_pattern, replace) yield finally: if common.is_windows_os(): undo_webdriver_tweak()
def update_package_json(): """Updates version param in package json file to match the current release version. """ release_version = common.get_current_release_version_number( common.get_current_branch_name()) common.inplace_replace_file(PACKAGE_JSON_FILEPATH, '"version": ".*"', '"version": "%s"' % release_version)
def enable_webpages(): """Enables deactivated webpages for testing.""" pattern = 'COMMUNITY_DASHBOARD_ENABLED = .*' replace = 'COMMUNITY_DASHBOARD_ENABLED = True' common.inplace_replace_file(FECONF_FILE_PATH, pattern, replace) pattern = '"ENABLE_ACCOUNT_DELETION": .*' replace = '"ENABLE_ACCOUNT_DELETION": true,' common.inplace_replace_file(CONSTANTS_FILE_PATH, pattern, replace)
def cleanup(): """Deactivates webpages and deletes html lighthouse reports.""" shutil.rmtree('.lighthouseci') pattern = 'COMMUNITY_DASHBOARD_ENABLED = .*' replace = 'COMMUNITY_DASHBOARD_ENABLED = False' common.inplace_replace_file(FECONF_FILE_PATH, pattern, replace) pattern = '"ENABLE_ACCOUNT_DELETION": .*' replace = '"ENABLE_ACCOUNT_DELETION": false,' common.inplace_replace_file(CONSTANTS_FILE_PATH, pattern, replace)
def update_dev_mode_in_constants_js(constant_file, dev_mode_setting): """Change constant file based on the running mode. Only the `DEV_MODE` line should be changed. Args: constant_file: str. File path to the constant file. dev_mode_setting: bool. Represents whether the program is running on dev mode. """ pattern = '"DEV_MODE": .*' replace = '"DEV_MODE": %s' % ('true' if dev_mode_setting else 'false') common.inplace_replace_file(constant_file, pattern, replace)
def update_community_dashboard_status_in_feconf_file( feconf_file_path, enable_community_dashboard): """Change feconf.py file based on whether the community dashboard is enabled. Args: feconf_file_path: str. Path to the feconf.py file. enable_community_dashboard: bool. Represents whether community dashboard is enabled. """ pattern = 'COMMUNITY_DASHBOARD_ENABLED = .*' replace = 'COMMUNITY_DASHBOARD_ENABLED = %s' % enable_community_dashboard common.inplace_replace_file(feconf_file_path, pattern, replace)
def update_version_in_config_files(): """Updates version param in package json file to match the current release version. """ release_version = common.get_current_release_version_number( common.get_current_branch_name()) common.inplace_replace_file(PACKAGE_JSON_FILEPATH, '"version": ".*"', '"version": "%s"' % release_version, expected_number_of_replacements=1) common.inplace_replace_file(common.FECONF_PATH, 'OPPIA_VERSION = \'.*\'', 'OPPIA_VERSION = \'%s\'' % release_version, expected_number_of_replacements=1)
def cleanup(): """Deactivates webpages and deletes html lighthouse reports.""" pattern = '"ENABLE_ACCOUNT_DELETION": .*' replace = '"ENABLE_ACCOUNT_DELETION": false,' common.inplace_replace_file(common.CONSTANTS_FILE_PATH, pattern, replace) build.set_constants_to_default() google_app_engine_path = '%s/' % common.GOOGLE_APP_ENGINE_SDK_HOME processes_to_kill = [ '.*%s.*' % re.escape(google_app_engine_path), ] for p in SUBPROCESSES: p.kill() for p in processes_to_kill: common.kill_processes_based_on_regex(p) common.stop_redis_server()
def preprocess_release(app_name, deploy_data_path): """Pre-processes release files. This function should be called from within release_dir_name defined in execute_deployment function. Currently it does the following: (1) Substitutes files from the per-app deployment data. (2) Changes GCS_RESOURCE_BUCKET in assets/constants.ts. (3) Updates project id for vpc_access_connector in app_dev.yaml. (4) Updates REDISHOST in feconf.py Args: app_name: str. Name of the app to deploy. deploy_data_path: str. Path for deploy data directory. Raises: Exception. Could not find deploy data directory. Exception. Could not find source path. Exception. Could not find destination path. Exception. Constants file has invalid GCS_RESOURCE_BUCKET. Exception. The vpc_access_connector line is missing in app_dev.yaml. """ if not os.path.exists(deploy_data_path): raise Exception('Could not find deploy_data directory at %s' % deploy_data_path) # Copies files in root folder to assets/. for filename in FILES_AT_ROOT: src = os.path.join(deploy_data_path, filename) dst = os.path.join(os.getcwd(), 'assets', filename) if not os.path.exists(src): raise Exception( 'Could not find source path %s. Please check your deploy_data ' 'folder.' % src) if not os.path.exists(dst): raise Exception( 'Could not find destination path %s. Has the code been ' 'updated in the meantime?' % dst) shutil.copyfile(src, dst) # Copies files in images to /assets/images. for dir_name in IMAGE_DIRS: src_dir = os.path.join(deploy_data_path, 'images', dir_name) dst_dir = os.path.join(os.getcwd(), 'assets', 'images', dir_name) if not os.path.exists(src_dir): raise Exception( 'Could not find source dir %s. Please check your deploy_data ' 'folder.' % src_dir) common.ensure_directory_exists(dst_dir) for filename in os.listdir(src_dir): src = os.path.join(src_dir, filename) dst = os.path.join(dst_dir, filename) shutil.copyfile(src, dst) with python_utils.open_file(os.path.join(common.CONSTANTS_FILE_PATH), 'r') as assets_file: common_content = assets_file.read() with python_utils.open_file(os.path.join(APP_DEV_YAML_PATH), 'r') as app_dev_file: app_dev_content = app_dev_file.read() assert '"DEV_MODE": true' in common_content, 'Invalid DEV_MODE' assert '"GCS_RESOURCE_BUCKET_NAME": "None-resources",' in common_content, ( 'Invalid value for GCS_RESOURCE_BUCKET_NAME in %s' % (common.CONSTANTS_FILE_PATH)) assert 'vpc_access_connector:\n name: projects/PROJECT_ID' in ( app_dev_content), ( '"name: projects/PROJECT_ID" string is missing in app_dev.yaml') bucket_name = app_name + BUCKET_NAME_SUFFIX common.inplace_replace_file( common.CONSTANTS_FILE_PATH, r'"GCS_RESOURCE_BUCKET_NAME": "None-resources",', '"GCS_RESOURCE_BUCKET_NAME": "%s",' % bucket_name) updated_app_dev_content = app_dev_content.replace( 'vpc_access_connector:\n name: projects/PROJECT_ID', 'vpc_access_connector:\n name: projects/%s' % app_name) with python_utils.open_file(os.path.join(APP_DEV_YAML_PATH), 'w') as app_dev_file: app_dev_file.write(updated_app_dev_content)
def enable_webpages(): """Enables deactivated webpages for testing.""" pattern = '"ENABLE_ACCOUNT_DELETION": .*' replace = '"ENABLE_ACCOUNT_DELETION": true,' common.inplace_replace_file(common.CONSTANTS_FILE_PATH, pattern, replace)
def preprocess_release(app_name, deploy_data_path): """Pre-processes release files. This function should be called from within release_dir_name defined in execute_deployment function. Currently it does the following: (1) Substitutes files from the per-app deployment data. (2) Change GCS_RESOURCE_BUCKET in assets/constants.ts. Args: app_name: str. Name of the app to deploy. deploy_data_path: str. Path for deploy data directory. Raises: Exception: Could not find deploy data directory. Exception: Could not find source path. Exception: Could not find destination path. """ if not os.path.exists(deploy_data_path): raise Exception('Could not find deploy_data directory at %s' % deploy_data_path) # Copies files in root folder to assets/. for filename in FILES_AT_ROOT: src = os.path.join(deploy_data_path, filename) dst = os.path.join(os.getcwd(), 'assets', filename) if not os.path.exists(src): raise Exception( 'Could not find source path %s. Please check your deploy_data ' 'folder.' % src) if not os.path.exists(dst): raise Exception( 'Could not find destination path %s. Has the code been ' 'updated in the meantime?' % dst) shutil.copyfile(src, dst) # Copies files in images to /assets/images. for dir_name in IMAGE_DIRS: src_dir = os.path.join(deploy_data_path, 'images', dir_name) dst_dir = os.path.join(os.getcwd(), 'assets', 'images', dir_name) if not os.path.exists(src_dir): raise Exception( 'Could not find source dir %s. Please check your deploy_data ' 'folder.' % src_dir) common.ensure_directory_exists(dst_dir) for filename in os.listdir(src_dir): src = os.path.join(src_dir, filename) dst = os.path.join(dst_dir, filename) shutil.copyfile(src, dst) with python_utils.open_file(os.path.join(common.CONSTANTS_FILE_PATH), 'r') as assets_file: content = assets_file.read() assert '"DEV_MODE": true' in content assert '"GCS_RESOURCE_BUCKET_NAME": "None-resources",' in content bucket_name = app_name + BUCKET_NAME_SUFFIX common.inplace_replace_file( common.CONSTANTS_FILE_PATH, r'"GCS_RESOURCE_BUCKET_NAME": "None-resources",', '"GCS_RESOURCE_BUCKET_NAME": "%s",' % bucket_name)