def run(self, conf, args, plugins, parser): if args.COMMAND in plugins: renderer = consolemd.Renderer() # Remove empty space at the beginning of lines content = [item.strip() for item in plugins[args.COMMAND].__doc__.splitlines()] renderer.render('\n'.join(content)) else: parser.print_help()
def describe(ctx, asset_name, asset_key): """Display asset description.""" client = get_client(ctx.obj) # method must exist in sdk method = getattr(client, f'describe_{asset_name.lower()}') description = method(asset_key) renderer = consolemd.Renderer() renderer.render(description)
def parseREADME(self): with open(os.path.expanduser(Conf.DEFAULTS['TEMP_DIR'] + 'README'), 'r') as file: file_content = file.read() renderer = consolemd.Renderer() renderer.render(file_content) os.remove(os.path.expanduser(Conf.DEFAULTS['TEMP_DIR'] + 'README'))
def cli(ctx, input, **kw): """ render some markdown """ rename_proc('consolemd') md = input.read() import consolemd renderer = consolemd.Renderer(style_name=kw['style']) renderer.render(md, **kw)
def print_entry(self, entry): en_table = PrettyTable([colored(KeePass.TITLE, "yellow"), entry.Strings.ReadSafe(KeePass.TITLE)]) en_table.align = "l" en_table.border = False for x in entry.Strings: if x.Key != KeePass.TITLE and x.Key != KeePass.NOTES: value = self.get_value(entry, x.Key) if value: if PxDefs.IsPxEntry(entry): en_table.add_row([colored(PxDefs.DecodeKey(x.Key), "yellow"), self.get_value(entry, x.Key)]) else: en_table.add_row([colored(x.Key, "yellow"), self.get_value(entry, x.Key)]) print(en_table) #print(entry.Strings.ReadSafe(KeePass.NOTES)) text = entry.Strings.ReadSafe(KeePass.NOTES) kwargs = {} renderer = consolemd.Renderer() renderer.render(text, **kwargs)
def print_entries(entries): renderer = consolemd.Renderer() print() for entry in entries: print_entry(entry, renderer)
def command_help(*args): consolemd.Renderer().render(readme_content)
def main(cliargs: Optional[List[str]] = None) -> int: if cliargs is None: cliargs = sys.argv[1:] args = parser.parse_args(cliargs) if args.version: print("gitlab-simple 1.2") return 0 config = load_config() gl = gitlab.Gitlab(config["server"], private_token=config["token"]) if args.list_projects: list_args: Dict[str, Any] = {"all": True} header = ["IID", "Name"] rows = [[str(p.id), p.name] for p in gl.projects.list(**list_args)] print_table(str(len(rows)) + " project(s)", header, rows, 1) return 0 if args.new_snippet: message: Optional[str] if args.from_stdin: message = sys.stdin.read() else: message = retrieve_message() if message is None: return 1 title = args.title if args.title else "insert title here" file_type = args.file_type if args.file_type else "txt" snippet = gl.snippets.create({ "title": title, "file_name": "file." + file_type, "content": message }) print(snippet.web_url) return 0 if args.project: print("using project from command line") project_id = args.project elif "GITLAB_SIMPLE_PROJECT" in os.environ: print("using project from envvar") project_id = os.environ["GITLAB_SIMPLE_PROJECT"] elif "project" in config: print("using project from config") project_id = gl.projects.get(config["project"]) else: print("Couldn't find a project in...\n\n" + "- GITLAB_SIMPLE_PROJECT environment variable\n" + "- the configuration file\n" + "- via --project on the command line\n\n" + "exiting...") return 1 project = gl.projects.get(project_id) if args.list_milestones: print_table( "Milestones", ["ID", "State", "Title", "Due date", "Description"], sorted( [[ms.id, ms.state, ms.title, ms.due_date, ms.description] for ms in project.milestones.list(state="active")], key=lambda x: x[3], ), 4, ) return 0 if args.latest_trace: jobs = [j for j in project.jobs.list() if j.status == "failed"] jobs.sort(key=lambda x: x.id, reverse=True) print(jobs[0].trace().decode("utf-8")) return 0 if args.edit_issue: if not args.iid: print("please specify an issue id") return 1 issue = project.issues.get(args.iid) if args.title: issue.title = args.title if args.milestone: issue.milestone_id = args.milestone if args.editor: message = retrieve_message() if message is None: return 1 issue.description = message if args.assign: user = find_user(project, args.assign) if user is None: print('user "' + args.assign + '" not found') return 1 issue.assignee_id = user if args.labels: issue.labels = args.labels.split(",") issue.save() print("Edited issue") return 0 if args.new_issue: if not args.title: print("please supply a title using --title") return 1 d = {"title": args.title} if args.milestone: d["milestone_id"] = args.milestone if args.labels: d["labels"] = args.labels.split(",") if args.assign: user = find_user(project, args.assign) if user is None: print('user "' + args.assign + '" not found') return 1 d["assignee_id"] = user if args.editor: message = retrieve_message() if message is None: return 1 d["description"] = message created = project.issues.create(d) print("Created #" + str(created.iid)) if args.close_issues is not None: issues = [a.strip() for a in args.close_issues.split(",")] for issue in (project.issues.get(issue) for issue in issues): issue.state_event = "close" issue.save() print("all closed") if args.comment_issue: if not args.iid: print("please specify an issue id") return 1 i = project.issues.get(args.iid) i.notes.create({"body": args.comment_issue}) print("Comment created") if args.long_comment_issue: if not args.iid: print("please specify an issue id") return 1 message = retrieve_message() if message is None: return 1 i = project.issues.get(args.iid) i.notes.create({"body": message}) print("Comment created") return 0 if args.iid and args.view_issue is not None and args.view_issue: i = project.issues.get(args.iid) result = "# *{}* [ {} ]\n".format(i.title, i.state) result += "## metadata\n" result += ("by " + i.author["username"] + ", 🕑" + humanize_time(i.created_at) + " ago\n") if i.milestone is not None: result += "milestone: " + i.milestone["title"] + "\n" if i.assignees: result += "assigned to: " + i.assignees[0]["username"] + "\n" if i.labels: result += "labels: " + " ".join(i.labels) + "\n" result += "## description\n" result += i.description + "\n" comments = i.notes.list() if comments: result += "## comments\n" for c in comments: result += "### {} 🕑{} ago\n".format( c.author["username"], humanize_time(c.created_at)) result += c.body + "\n" renderer = consolemd.Renderer(style_name="emacs") renderer.render(result) if args.list_issues is not None and args.list_issues: list_args = {"state": "opened", "all": True} if args.assign is not None: assignee_id: Optional[int] = next( (u.id for u in project.users.list() if u.name == args.assign), None) if assignee_id is not None: list_args["assignee_id"] = str(assignee_id) if args.labels is not None: list_args["labels"] = args.labels.split(",") header = ["IID", "Title", "Tags"] rows = [[ str(issue.iid), issue.title, "" if not issue.labels else " ".join(issue.labels), ] for issue in project.issues.list(**list_args)] print_table(str(len(rows)) + " issue(s)", header, rows, 1) return 0