def run(self, args): spec_path = '{}/{}/spec.py'.format( self.status.current_directory, os.path.basename(self.status.current_directory) ) if not os.path.exists(spec_path): print_error( 'Here is not maid application directory.' + 'spec.py not found.') exit(1) application_name = self.get_application_name(spec_path) command_name = None if args.add is not None: command_name = args.add if args.delete is not None: command_name = args.delete class_name = command_name[0].upper() + command_name[1:] + 'Command' lc_class_name = class_name.lower() import_line = 'from {}.commands.{} import {}\n'.format( application_name, lc_class_name, class_name) command_factory_line = ' {},\n'.format(class_name) first_line = '# This file is generated by maid. Do not modify.\n' command_factories_start_line = 'command_factories = [\n' lines = [] with open(spec_path, 'r') as f: for line in f: if line == first_line and args.add is not None: lines.append(line) lines.append(import_line) continue if line == command_factories_start_line and \ args.add is not None: lines.append(line) lines.append(command_factory_line) continue if line == import_line and args.delete is not None: continue if line == command_factory_line and args.delete is not None: continue lines.append(line) write_file(spec_path, ''.join(lines)) if args.add is not None: self.output_file( '{}.py'.format(lc_class_name), '{}/commands'.format(application_name), dict( class_name=class_name, name=command_name ))
def validate_key(self, key): if key not in self.keys: print_error('"{}" is not exist.'.format(key)) exit(1)