def invoke(self, ctx: click.Context): type_name = ctx.params.get('project_type') name = ctx.params.get('project') vcs_type = ctx.params.get('vcs') template = ctx.params.get('template') CreateCommand.validate_project_type(type_name) CreateCommand.validate_vcs_type(vcs_type) project_type = config.get('project_type').get(type_name) if vcs_type is None: vcs_config = None else: vcs_config = config.get('vcs').get(vcs_type) project = Project(name, project_type, vcs_config) self._create_folder(project=project) if template is not None: self._copy_template(project=project, template_name=template) repo_url = None repo_name = None vcs = None if vcs_config is not None: vcs = get_vcs(vcs_config=vcs_config) if vcs is not None: repo_url = vcs.create_project(project) repo_name = vcs.get_repository_name(project) gitignore_content = vcs.get_gitignore_template(project) if gitignore_content is not None: project.add_file('.gitignore', gitignore_content) project.add_file('README.md', '\n'.join([ repo_name, '===', 'This project have been generated with [darkanakin41/project-toolbox]' '(https://github.com/darkanakin41/project-toolbox)' ])) if repo_url is not None: self._init_git(project, repo_url) if vcs is not None and repo_name is not None: webbrowser.open('/'.join([vcs.get_base_url(), repo_name])) if project.type.virtual_machine is not None: self.start_virtual_machine(project.type.virtual_machine) if project.type.is_mutagened(): logger.info("Mutagen configuration detected") mutagen_helper = Manager() mutagen_helper.up(path=project.type.get_folder(), project=name) project.type.exec_commands(path=project.get_path())
def get_virtual_machine(virtual_machine_name: str) -> VirtualMachine: """ Get the selected virtual machine :param virtual_machine_name: :return: VirtualMachine """ if virtual_machine_name not in config.get('virtual_machine').keys(): logger.error('Unknown virtual_machine, valid ones are %s', ', '.join(config.get('virtual_machine').keys())) sys.exit(1) return config.get('virtual_machine').get(virtual_machine_name)
def detect_project_type(): """ Detect the type of the project :return: """ cwd = os.getcwd() for type_name in config.get('project_type').keys(): project_type: ProjectType = config.get('project_type').get( type_name) if project_type.get_folder() in cwd: return project_type return None
def get_gitignore_template(self, project: Project) -> str: """ Retrieve the gitignore template for the given project :param project: The project :return: the content of the gitignore """ gitignore_content = [] if project.type.gitignore is not None: gitignore_content.append( self.get_gitignore_template_from_connector( project.type.gitignore)) if config.get('gitignore') is not None: gitignore_content.extend(config.get('gitignore')) return '\n'.join(gitignore_content)
def _get_project_types(project_type: str = None): """ Get project types :param project_type: name of project_type :return: """ if project_type is not None: project_type_config = config.get('project_type').get(project_type) project_types = [project_type_config] else: project_types = list( map(lambda pt: pt[1], config.get('project_type').items())) return project_types
def get_folder(self) -> str: """ Get the absolute folder of the project type :return: """ from toolbox.config import config return os.path.join(config.get('base_folder'), self.folder)
def validate_vcs_type(type_name: str = None, kill: bool = True): """ Validate that the given type is valid :param type_name: the type to check :param kill: wether it should kill the process or not :return: boolean """ if type is None: return True if type_name not in config.get('vcs').keys(): logger.error('Unknown vcs, valid ones are %s', ', '.join(config.get('vcs').keys())) if kill: sys.exit(1) return False return True
def invoke(self, ctx: click.Context): type_name: str = ctx.params.get('project_type') project_type = config.get('project_type').get(type_name) logger.debug("Project Type virtual machine is %s", project_type.virtual_machine) if project_type.virtual_machine: self.start_virtual_machine(project_type.virtual_machine)
def invoke(self, ctx: click.Context): type_name: str = ctx.params.get('project_type') StatusCommand.validate_project_type(type_name) project_type = config.get('project_type').get(type_name) if project_type.virtual_machine is None: print('No virtual machine for given project type') return virtual_machine = self.get_virtual_machine(project_type.virtual_machine) manager = get_virtual_machine_manager(virtual_machine) if manager.status(False): print("VM " + virtual_machine.name + " is on") else: print("VM " + virtual_machine.name + " is off")