def build(self, process_data): Logger.i('Building repository: {0}...'.format(self.get_name())) vendor_file_data = self.load_vendor_file_data() if 'vendor' in vendor_file_data: vendor_data = vendor_file_data['vendor'] if 'build' in vendor_data: vendor_data_build = vendor_data['build'] exitcode, stderr, stdout = FileUtil.run( vendor_data_build, self.get_temp_dir(), process_data.get_environ()) if exitcode == 0: Logger.i('Build finished for repository: {0}'.format( self.get_name())) else: if stdout: Logger.i('Build output for repository: {0}'.format( self.get_name())) Logger.clean(stdout) if stderr: Logger.i( 'Error output while build repository: {0}'.format( self.get_name())) Logger.clean(stderr) Logger.f('Failed to build repository: {0}'.format( self.get_name()))
def run(self, process_data, template_data, working_dir): Logger.d('Running task: {0}...'.format(self.get_name())) if process_data: if self.type == self.TYPE_COPY_FILE: from_path = self.params['from'] if self.params['from'] else None to_path = self.params['to'] if self.params['to'] else None FileUtil.copy_file(from_path=from_path, to_path=to_path) elif self.type == self.TYPE_COPY_FILES: to_path = self.params['to'] if self.params['to'] else None file_pattern = self.params[ 'from'] if 'from' in self.params else None file_pattern = process_data.parse_text(file_pattern) found_files = FileUtil.find_files(file_pattern) for f in found_files: if f: FileUtil.copy_file(from_path=f, to_path=os.path.join( to_path, os.path.basename(f))) elif self.type == self.TYPE_PARSE_FILE: file_pattern = self.params[ 'file'] if 'file' in self.params else None file_pattern = process_data.parse_text(file_pattern) found_files = FileUtil.find_files(file_pattern) for f in found_files: if f: template_file = os.path.abspath(f) template_loader = jinja2.FileSystemLoader( searchpath=os.path.dirname(template_file)) template_env = jinja2.Environment( loader=template_loader) template = template_env.get_template( os.path.basename(template_file)) templ_result = template.render(template_data) FileUtil.write_to_file(os.path.dirname(template_file), os.path.basename(template_file), str(templ_result)) elif self.type == self.TYPE_RUN: run_args = self.params[ 'args'] if 'args' in self.params else None if run_args: exitcode, stderr, stdout = FileUtil.run( run_args, working_dir, process_data.get_merged_data_for_runner()) if exitcode == 0: Logger.i('Run finished for task: {0}'.format( self.get_name())) else: if stdout: Logger.i('Run output for task: {0}'.format( self.get_name())) Logger.clean(stdout) if stderr: Logger.i('Error output while run task: {0}'.format( self.get_name())) Logger.clean(stderr) Logger.f('Failed to run task: {0}'.format( self.get_name())) else: Logger.f('Invalid task type') else: Logger.d('Process data is invalid to run task')
def build(self, target_name): from ezored.models.logger import Logger from ezored.models.project import Project project = Project.create_from_project_file() process_data = ProcessData() process_data.reset() process_data.project_name = project.get_config_value('name') if target_name: Logger.i('Build only target: {0}'.format(target_name)) else: Logger.i('Build all targets') target_found = False for target in project.targets: can_build = False if not target_name: can_build = True elif target.get_name() == target_name: can_build = True if can_build: Logger.d('Getting target data by target name: {0}...'.format( target_name)) target_found = True # targets need be deleted to be always fresh with target data from dependencies target.remove() # build the target repository after download target.prepare_from_process_data(process_data) target.repository.download() target.repository.build(process_data) # get all target data from project dependencies target_data = TargetData() target_data.project_config = project.config for dependency in project.dependencies: dependency.prepare_from_process_data(process_data) new_target_data = dependency.get_target_data_by_target_name_and_parse( target.get_name(), process_data) target_data.merge(new_target_data) # back to target data target.prepare_from_process_data(process_data) # copy files from dependencies to target directory FileUtil.copy_files_from_list(target_data.copy_files) # parse files path and it content target_project_file_data = target.load_target_project_file_data( ) if 'target' in target_project_file_data: target_project_data = target_project_file_data['target'] # parse files if 'parse_files' in target_project_data: target_project_data_parse_files = target_project_data[ 'parse_files'] if target_project_data_parse_files: Logger.d('Files to parse from target: {0}'.format( len(target_project_data_parse_files))) target_project_data_parse_files = process_data.parse_text_list( target_project_data_parse_files) for target_project_data_parse_file in target_project_data_parse_files: template_loader = jinja2.FileSystemLoader( searchpath='/') template_env = jinja2.Environment( loader=template_loader) template_file = target_project_data_parse_file template = template_env.get_template( template_file) templ_result = template.render( target=target_data) FileUtil.write_to_file( os.path.dirname( target_project_data_parse_file), os.path.basename( target_project_data_parse_file), str(templ_result)) else: Logger.d('No files need to parse from target: {0}'. format(target.get_name())) # build target if 'build' in target_project_data: Logger.i('Building target: {0}...'.format( target.get_name())) target_project_data_build = target_project_data[ 'build'] exitcode, stderr, stdout = FileUtil.run( target_project_data_build, target.repository.get_vendor_dir(), process_data.get_environ()) if exitcode == 0: Logger.i('Build finished for target: {0}'.format( target.get_name())) else: if stdout: Logger.i('Build output for target: {0}'.format( target.get_name())) Logger.clean(stdout) if stderr: Logger.i( 'Error output while build target: {0}'. format(target.get_name())) Logger.clean(stderr) Logger.f('Failed to build target: {0}'.format( target.get_name())) if not target_found: Logger.f('Target not found: {0}'.format(target_name))