def create_link(self, name, no_input=False): if name == 'all': link_config = Config.get('link', 'list', default=dict()) if not no_input: if not self.confirm('전체 링크 작업을 실행하시겠습니까?', default=True): self.line_error('실행 거부') return False for name in link_config.keys(): self.create_link(name, no_input=True) self.line('Done') else: link_path = Config.link(name) if not link_path: raise CommandError('link config not found: {}'.format(name)) if not no_input: if not self.confirm('{} 링크 작업을 실행하시겠습니까?'.format(name), default=True): self.line_error('실행 거부') return False if type(link_path[0]) is str: if len(link_path) == 2: return self.generate_link(link_path[0], link_path[1]) elif type(link_path[0]) in (list, tuple, set): for i in link_path: if len(i) != 2: raise CommandError('Invalid format of link config: {}'.format(name)) self.generate_link(i[0], i[1]) return True raise CommandError('Invalid format of link config: {}'.format(name))
def get_executer(self, name): runner = self.argument('exec') if runner: return runner config = Config.script(name) runner = config.get('exec') return runner or self.default_executer
def full_file_path(self, file): script_root = Config.script_root() if script_root and file[0] != '/': file_path = script_root / file else: file_path = file return str(file_path)
def run_script(self, name): config = Config.script(name) script_root = Config.script_root() if not config: raise CommandError('No such script: {}'.format(name)) file = config.get('file') if not file: raise CommandError('Script does not have file') if script_root and file[0] != '/': file_path = script_root / file else: file_path = file runner = self.get_executer(name) command = '{} {}'.format(runner, file_path) self.line('Run command: {}'.format(command)) self.shell_call(command) return True
def generate_link(self, source, target): link_root = Config.link_root() if type(source) is not str or type(target) is not str: raise CommandError('Type error: source is not str type') if link_root and source[0] != '/': # 루트에서 시작하면 그냥 넘어가기 source_path = link_root / source else: source_path = source command = 'ln -sf {} {}'.format( source_path, target, ) self.line(command) self.shell_call(command) return True
def url_parsing(repository_name, protocol='ssh'): split_names = repository_name.split('/') if len(split_names) == 1: username = Config.get('github', 'username') repository_name = "{}/{}".format(username, repository_name) else: username = split_names[0] repository_name = "{}/{}".format(username, "-".join(split_names[1:])) if repository_name.find('.git') < 0: repository_name += '.git' if protocol == 'ssh': repository_name = '[email protected]:{}'.format(repository_name) elif protocol == 'https': repository_name = 'https://github.com/{}'.format(repository_name) else: raise ValueError('Invalid protocol name: {}'.format(protocol)) return repository_name
def handle(self): name = self.argument('name') if name: self.run_script(name) elif self.option('list'): script_config = Config.get('script', 'list', default=dict()) table = self.table() table.set_header_row(['name', 'desc', 'script file']) for name, config in script_config.items(): if not config: table.add_row([ name, '<error>Invalid</error>', '<error>Invalid</error>' ]) file = config.get('file', '') filepath = '' if not file else self.full_file_path(file) desc = config.get('desc', '') table.add_row([name, desc, filepath]) table.render(self.io) else: self.line_error('올바른 명령어를 입력해주세요.')
def handle(self): name = self.argument('name') if name: self.create_link(name, self.option('no-input')) elif self.option('list'): link_config = Config.get('link', 'list', default=dict()) table = self.table() table.set_header_row(['name', 'source', 'target']) for name, config in link_config.items(): if not config: table.add_row([name, '<error>Invalid</error>', '<error>Invalid</error>']) if type(config[0]) in (list, tuple, set): self.add_list_row(table, name, config[0]) for t in config[1:]: self.add_list_row(table, '', t) elif type(config[0]) is str: self.add_list_row(table, name, config) else: table.add_row([name, '<error>Invalid</error>', '<error>Invalid</error>']) table.render(self.io) else: self.line_error('올바른 명령어를 입력해주세요.')
def get_default_data(cls): default_data = cls.default_data default_data.update(Config.get('storage', 'default', default=dict())) return default_data
def handle(self): all_names = list(Config.get('docker', default={}).keys()) self.line('\n'.join(all_names))
def handle(self): name = self.argument('name') command = Config.docker(name) self.shell_call(command)
def __init__(self): ocel_path = Config.get('ocel', 'path') self.ocel_path = Path(ocel_path) if ocel_path else self.default_path if not self.ocel_path.exists(): self.clone_ocel()
def init(): if not path.KAL_HOME_DIR.exists(): os.makedirs(path.KAL_HOME_DIR) Config.initialize() Storage.initialize()