def setup_base(cls): cls.class_name = "arbitrary_class" cls.path = ProjectPaths(SystemTest.get_testing_directory() / "arbitrary_project_name") Project(ProjectParameters(cls.path.root, "arbitrary_author")).create() cls.header_path = cls.path.to_include_directory / (cls.class_name + ".h")
def setUp(self): self.raw_path = Path("arbitrary_path") self.path = ProjectPaths(self.raw_path)
def setup_base(cls): cls.class_name = "arbitrary_class" cls.path = ProjectPaths(SystemTest.get_testing_directory() / "arbitrary_project_name") Project(ProjectParameters(cls.path.root, "arbitrary_author")).create() cls.classCreator = ClassCreator(cls.class_name, cls.path)
def __init__(self, parameters): self.name = parameters.path.name self.path = ProjectPaths(parameters.path) self.author = parameters.author
class Project(): def __init__(self, parameters): self.name = parameters.path.name self.path = ProjectPaths(parameters.path) self.author = parameters.author def create(self): self.create_directory_structure( ) # Must appear first, before any file creation self.create_gitignore_file() self.create_git_repository() self.create_license_file() self.create_class_templates() self.create_license_header_template( ) # Must appear before cmakelists creation self.create_readme_file() self.create_src_cmakelists() self.create_top_level_cmakelists() def create_class_templates(self): path = lambda suffix: self.path.to_templates_directory / ( "class_" + str(suffix) + ".template") suffixToTemplate = { "header": ClassHeaderTemplate, "source": ClassSourceTemplate, "tests": ClassTestsTemplate } for suffix, template in suffixToTemplate.items(): File.write(path(suffix), template.instantiate_with(self.name)) def create_directory_structure(self): for directory in self.path.list_top_down(): Directory().create(directory) def create_gitignore_file(self): to_ignore = [".templates", "build"] content = "" for path in to_ignore: content += path + "\n" File.write(self.path / ".gitignore", content) def create_git_repository(self): subprocess.run(["git", "-C", str(self.path), "init"], stdout=subprocess.DEVNULL) def create_license_file(self): File.copy(cpp_tools_resources_directory / "GPL_v3.txt", self.path / "LICENSE.TXT") def create_license_header_template(self): content = LicenseHeaderTemplate().instantiate_with( self.name, self.author) File.write(self.path.to_license_header_template, content) def create_readme_file(self): content = "# " + self.name + "\n" File.write(self.path / "README.md", content) def create_src_cmakelists(self): content = self.create_license_header() + File.read( cpp_tools_resources_directory / "src_CMakeLists.txt") File.write(self.path.to_source_directory / "CMakeLists.txt", content) def create_top_level_cmakelists(self): content = self.create_license_header( ) + TopLevelCMakeLists.instantiate_with(self.name) File.write(self.path / "CMakeLists.txt", content) def create_license_header(self): return LicenseHeader(File.read(self.path.to_license_header_template) ).instantiate_for_cmakelists()
def add_create_interface_parser(self, subparsers): parser_create_class = subparsers.add_parser("interface") parser_create_class.add_argument("--name", type=str) parser_create_class.set_defaults( func=lambda args: CommandCreateInterface(args.name, ProjectPaths(Path(".").resolve())))