def models(params=False): """Lists all models with some additional info""" config = dg.Config() if len(config.models) == 0: return longest = max(map(len, config.models.keys())) for model_id, model in config.models.items(): spaces = ' ' * (longest - len(model_id) + 15) if model.__doc__ is not None: doc = model.__doc__.splitlines()[0] else: doc = model.__class__.__name__ cprint(f'{model_id}:{spaces}[blue]{doc}[normal]\n', parse=True) if params: indent = len(model_id) + len(spaces) + 1 width = 50 + indent wrapper = TextWrapper(width=width, initial_indent=' ' * indent, subsequent_indent=' ' * indent, break_long_words=False, replace_whitespace=True, break_on_hyphens=False) text = wrapper.fill(', '.join(model.get_params().keys())) cprint(f'[cyan]{text}[normal]\n', parse=True)
def all_repositories(self): workspace = self.active_workspace if workspace is None: cprint('None of the workspaces is selected as current\n', Color.red) raise ConfigurationError('No current workspace') repos = [] for name in sorted(workspace['repositories']): repo = workspace['repositories'][name] username, password = self.credentials_for(repo['source']) repos.append(Repository(name=name, path=os.path.abspath(os.path.join(workspace['path'], name)), source=repo['source'], username=username, password=password)) return repos
def all_repositories(self): workspace = self.active_workspace if workspace is None: cprint('None of the workspaces is selected as current\n', Color.red) raise ConfigurationError('No current workspace') repos = [] for name in sorted(workspace['repositories']): repo = workspace['repositories'][name] username, password = self.credentials_for(repo['source']) repos.append( Repository(name=name, path=os.path.abspath( os.path.join(workspace['path'], name)), source=repo['source'], username=username, password=password)) return repos
def open(self, what, path): path = os.path.abspath(path) if what == 'cmd': if platform.is_a(platform.WINDOWS): os.system('start cmd /k cd /d "%s"' % path) elif platform.is_a(platform.DARWIN): result = os.system('open -a iTerm "%s"' % path) if result != 0: os.system('open -a Terminal "%s"' % path) elif what == 'fm': import webbrowser if platform.is_a(platform.DARWIN): webbrowser.open('file://' % path) else: webbrowser.open(path) elif what == 'thg': executable = self.config.executables[what] status, output, _ = execute(executable, '--repository', path) if status != 0: cprint('Unable to opet tortoiseHg.\n', Color.red) cprint('%s' % output)
def format_text(self, style, text): fg, fg_dark = style['fg'] bg, bg_dark = style['bg'] cprint(text, fg=fg, bg=bg, fg_dark=fg_dark, bg_dark=bg_dark)
def error(self, message, newline=True): cprint('%s%s' % (message, '\n' if newline else ''), Color.red)
def warn(self, message, newline=True): cprint('%s%s' % (message, '\n' if newline else ''), Color.yellow)
def info(self, message, newline=True): cprint('%s%s' % (message, '\n' if newline else ''), Color.blue)
def message(self, message, newline=True): cprint('%s%s' % (message, '\n' if newline else ''), Color.normal)