| 82 | parser.set_defaults(_command=PipelineCMD) |
| 83 | |
| 84 | def create_template(self): |
| 85 | if self.args.tpl_file_path not in os.listdir(template_path): |
| 86 | tpl_file_path = self.args.tpl_file_path |
| 87 | else: |
| 88 | tpl_file_path = os.path.join(template_path, |
| 89 | self.args.tpl_file_path) |
| 90 | if not os.path.exists(tpl_file_path): |
| 91 | raise ValueError('%s not exists!' % tpl_file_path) |
| 92 | |
| 93 | save_file_path = self.args.save_file_path if self.args.save_file_path != './' else os.getcwd( |
| 94 | ) |
| 95 | os.makedirs(save_file_path, exist_ok=True) |
| 96 | if not self.args.filename.endswith('.py'): |
| 97 | raise ValueError('the FILENAME must end with .py ') |
| 98 | save_file_name = self.args.filename |
| 99 | save_pkl_path = os.path.join(save_file_path, save_file_name) |
| 100 | |
| 101 | if not self.args.configuration_path.endswith('/'): |
| 102 | self.args.configuration_path = self.args.configuration_path + '/' |
| 103 | |
| 104 | lines = [] |
| 105 | with open(tpl_file_path) as tpl_file: |
| 106 | tpl = Template(tpl_file.read()) |
| 107 | lines.append(tpl.substitute(**vars(self.args))) |
| 108 | |
| 109 | with open(save_pkl_path, 'w') as save_file: |
| 110 | save_file.writelines(lines) |
| 111 | |
| 112 | logger.info('>>> Configuration be saved in %s/%s' % |
| 113 | (self.args.configuration_path, 'configuration.json')) |
| 114 | logger.info('>>> Task_name: %s, Created in %s' % |
| 115 | (self.args.task_name, save_pkl_path)) |
| 116 | logger.info('Open the file < %s >, update and run it.' % save_pkl_path) |
| 117 | |
| 118 | def execute(self): |
| 119 | if self.args.action == 'create': |