def update_content_version(self, content_ver: str = '', path: str = ''): regex = r'CONTENT_RELEASE_VERSION = .*' if not content_ver: try: with open('content-descriptor.json') as file_: descriptor = json.load(file_) content_ver = descriptor['release'] except (FileNotFoundError, json.JSONDecodeError, KeyError): print_error( 'Invalid descriptor file. make sure file content is a valid json with "release" key.' ) return try: if self.no_update_commonserverpython: return if not path: path = get_common_server_path('.') with open(path, 'r+') as file_: content = file_.read() content = re.sub(regex, f"CONTENT_RELEASE_VERSION = '{content_ver}'", content, re.M) file_.seek(0) file_.write(content) except Exception as ex: print_warning(f'Could not open CommonServerPython File - {ex}')
def copy_common_server_python(self): """copy commonserverpython from the base pack""" if self.common_server: try: common_server_path = get_common_server_path(self.configuration.env_dir) shutil.copy(common_server_path, self.full_output_path) except Exception as err: print_v(f'Could not copy CommonServerPython: {str(err)}')
def update_branch(path: str = ''): regex = r'CONTENT_BRANCH_NAME = .*' branch_name = get_current_working_branch() try: if not path: path = get_common_server_path('.') with open(path, 'r+') as file_: content = file_.read() content = re.sub(regex, f"CONTENT_BRANCH_NAME = '{branch_name}'", content, re.M) file_.seek(0) file_.write(content) except Exception as ex: print_warning(f'Could not open CommonServerPython File - {ex}') return branch_name
def _setup_dev_files_py(self, py_num): # copy demistomock and common server try: shutil.copy( self.configuration.env_dir + '/Tests/demistomock/demistomock.py', self.project_dir) open(self.project_dir + '/CommonServerUserPython.py', 'a').close() # create empty file shutil.rmtree(self.project_dir + '/__pycache__', ignore_errors=True) shutil.copy( self.configuration.env_dir + '/Tests/scripts/dev_envs/pytest/conftest.py', self.project_dir) self.check_api_module_imports(py_num) if "/Scripts/CommonServerPython" not in self.project_dir: # Otherwise we already have the CommonServerPython.py file common_server_path = get_common_server_path( self.configuration.env_dir) shutil.copy(common_server_path, self.project_dir) except Exception as e: print_v( 'Could not copy demistomock and CommonServer files: {}'.format( str(e)))