示例#1
0
 def copy_file(self, file_name, output_directory):
     source_file_path = '{}/{}'.format(self.templates_path, file_name)
     output_file_path = self.root_path
     if output_directory != '':
         output_file_path += '/{}'.format(output_directory)
     output_file_path += '/{}'.format(file_name)
     source_content = read_file(source_file_path)
     write_file(output_file_path, source_content)
     print(output_file_path)
示例#2
0
 def output_file(self, file_name, output_directory, variables):
     template_file_path = '{}/{}.template'.format(
         self.templates_path, file_name)
     output_file_path = self.root_path
     if output_directory != '':
         output_file_path += '/{}'.format(output_directory)
     output_file_path += '/{}'.format(file_name)
     template_content = read_file(template_file_path)
     output_content = Template(template_content).substitute(variables)
     write_file(output_file_path, output_content)
     print(output_file_path)
示例#3
0
 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
             ))