def __init__(self, config: dict): self.parsed = {} if config.get(self.get_config_key()) is None: logger.error("No %s configuration detected", self.get_config_key()) sys.exit(1) else: self.parse(config)
def stop(self): if not self.status(output=False): logger.info('VM %s is down, nothing to do here', self.virtual_machine.name) return if not os.path.isfile(self.virtual_machine.path): logger.error('VM %s is not found on drive', self.virtual_machine.path) return os.popen('cd {} && "{}" halt'.format(self.virtual_machine.exec, self.virtual_machine.path)) logger.info('VM %s is now stopped', self.virtual_machine.name)
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 start(self): if self.status(output=False): logger.info('VM %s is up, nothing to do here', self.virtual_machine.name) return if not os.path.isfile(self.virtual_machine.path): logger.error('VM %s is not found on drive', self.virtual_machine.path) return os.popen('"{}" start "{}" nogui'.format(self.virtual_machine.exec, self.virtual_machine.path)) logger.info('VM %s is now started', self.virtual_machine.name)
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 _copy_template(project: Project, template_name: str): """ Copy template files for the given project :param project: the project """ if project.type.templates.get(template_name) is None: logger.error('Unknown template %s, valid ones are %s', template_name, ', '.join(project.type.templates.keys())) sys.exit(1) template: Template = project.type.templates.get(template_name) files = os.listdir(project.get_path()) if len(files) > 0: logger.warning("Unable to copy template %s because project is already initialized", template.name) return template.copy(project.get_path())
def invoke(self, ctx: click.Context): name: str = ctx.params.get('project') virtual_machine: bool = ctx.params.get('vm') if not self.exists(name): logger.error('Unable to find %s path', name) sys.exit(1) project_type = self.detect_project_type() if project_type is None: logger.error('Unable to determine %s project type', name) sys.exit(1) logger.info('Project type detected for %s is %s', name, project_type.name) if project_type.is_mutagened(): logger.info("Mutagen configuration detected") mutagen_helper = Manager() mutagen_helper.down(path=project_type.get_folder(), project=name) logger.debug("Project virtual machine is %s", project_type.virtual_machine) if project_type.virtual_machine and virtual_machine: self.stop_virtual_machine(project_type.virtual_machine)
def invoke(self, ctx: click.Context): name: str = ctx.params.get('project') noexec: bool = ctx.params.get('noexec') if not StartCommand.exists(name): logger.error("Unable to find %s path", name) sys.exit(1) project_type = self.detect_project_type() if project_type is None: logger.error("Unable to determine %s project type", name) sys.exit(1) logger.debug("Project virtual machine is %s", project_type.virtual_machine) if project_type.virtual_machine: self.start_virtual_machine(project_type.virtual_machine) logger.info("Project type detected for %s is %s", name, project_type.name) if project_type.is_mutagened(): logger.info("Mutagen configuration detected") mutagen_helper = Manager() mutagen_helper.up(path=project_type.get_folder(), project=name) if not noexec: project_type.exec_commands(self.path(name))