def constructor(self, name, image, about, quote, color, contributors=None): embed = discord.Embed(color=self.colors[color]) embed.set_author(name=name.capitalize(), icon_url=image) embed.set_thumbnail(url=image) embed.description = f"*{quote}*" embed.add_field(name="Favorite Color", value=color) embed.add_field(name="Contributors", value=contributors or 'None') embed.add_field(name="About", value='\n'.join(parawrap.wrap(about, 50))) return embed
async def mind(self, ctx, text1: str, text2: str, text3: str): """Mind blown""" if len(text1) or len(text2) or len(text3) > 50: return await ctx.send("50 chars on each!") text1_pos = (65, 76) text2_pos = (65, 462) text3_pos = (65, 869) text1_ = parawrap.wrap(text1, 16) text2_ = parawrap.wrap(text2, 16) text3_ = parawrap.wrap(text3, 16) async with ctx.typing(): def write(): font = ImageFont.truetype("Infamous/fonts/Arial.ttf", 72) image = Image.open("Infamous/img/highermind.jpg") draw = ImageDraw.Draw(image) draw.text(text1_pos, '\n'.join(text1_), fill='black', font=font) draw.text(text2_pos, '\n'.join(text2_), fill='black', font=font) draw.text(text3_pos, '\n'.join(text3_), fill='black', font=font) b = BytesIO() b.seek(0) image.save(b, "png") return b.getvalue() fp = await self.bot.loop.run_in_executor(None, write) file = discord.File(filename="mind.png", fp=fp) await ctx.send(file=file)
def main(): parser = argparse.ArgumentParser( prog='release_notes', description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument("library", metavar='path', action="store", help="library directory, for example" " 'openstack/cliff'", ) parser.add_argument("start_revision", metavar='revision', action="store", help="start revision, for example '1.8.0'", ) parser.add_argument("end_revision", metavar='revision', action="store", nargs='?', help="end revision, for example '1.9.0'" " (default: HEAD)", default="HEAD") parser.add_argument('--changes-only', action='store_true', default=False, help='List only the change summary, without details', ) parser.add_argument("--notable-changes", metavar='path', action="store", help="a file containing any notable changes") parser.add_argument("--skip-requirement-merges", action='store_true', default=False, help="skip requirement update commit messages" " (default: False)") parser.add_argument("--show-dates", action='store_true', default=False, help="show dates in the change log") args = parser.parse_args() library_path = os.path.abspath(args.library) if not os.path.isfile(os.path.join(library_path, "setup.py")): sys.stderr.write("No 'setup.py' file found in %s\n" % library_path) sys.stderr.write("This will not end well...\n") return 1 # Get the python library/program description... cmd = [sys.executable, 'setup.py', '--description'] stdout, stderr = run_cmd(cmd, cwd=library_path) description = stdout.strip() # Get the python library/program name cmd = [sys.executable, 'setup.py', '--name'] stdout, stderr = run_cmd(cmd, cwd=library_path) library_name = stdout.strip() # Get the commits that are in the desired range... git_range = "%s..%s" % (args.start_revision, args.end_revision) if args.show_dates: format = "--format=%h %ci %s" else: format = "--oneline" cmd = ["git", "log", "--no-color", format, "--no-merges", git_range] stdout, stderr = run_cmd(cmd, cwd=library_path) changes = [] for commit_line in stdout.splitlines(): commit_line = commit_line.strip() if not commit_line or is_skippable_commit(args, commit_line): continue else: changes.append(commit_line) # Filter out any requirement file changes... requirement_changes = [] requirement_files = list(glob.glob(os.path.join(library_path, '*requirements*.txt'))) if requirement_files: cmd = ['git', 'diff', '-U0', '--no-color', git_range] cmd.extend(requirement_files) stdout, stderr = run_cmd(cmd, cwd=library_path) requirement_changes = [line.strip() for line in stdout.splitlines() if line.strip()] # Get statistics about the range given... cmd = ['git', 'diff', '--stat', '--no-color', git_range] stdout, stderr = run_cmd(cmd, cwd=library_path) diff_stats = [] for line in stdout.splitlines(): line = line.strip() if not line or line.find("tests") != -1 or line.startswith("doc"): continue diff_stats.append(line) # Find what the bug url is... bug_url = '' with open(os.path.join(library_path, 'README.rst'), 'r') as fh: for line in fh: pieces = line.split("Bugs:", 1) if len(pieces) == 2: bug_url = pieces[1].strip() break if not bug_url: raise IOError("No bug url found in '%s'" % os.path.join(library_path, 'README.rst')) notables = '' if args.notable_changes: with open(args.notable_changes, 'r') as fh: notables = fh.read().rstrip() lp_url = bug_url.replace("bugs.", "").rstrip("/") milestone_url = lp_url + "/+milestone/%s" % args.end_revision change_header = ["Changes in %s %s" % (library_name, git_range)] change_header.append("-" * len(change_header[0])) params = { 'project': os.path.basename(library_path), 'description': description, 'end_rev': args.end_revision, 'range': git_range, 'lib': library_path, 'milestone_url': milestone_url, 'skip_requirement_merges': args.skip_requirement_merges, 'bug_url': bug_url, 'changes': changes, 'requirement_changes': requirement_changes, 'diff_stats': diff_stats, 'notables': notables, 'change_header': "\n".join(change_header), 'emotion': random.choice(EMOTIONS), } if args.changes_only: print(expand_template(CHANGES_ONLY_TPL, params)) else: header = expand_template(HEADER_RELEASE_TPL.strip(), params) for line in parawrap.wrap(header): print(line) print(expand_template(CHANGE_RELEASE_TPL, params)) return 0
def main(): parser = argparse.ArgumentParser( prog='release_notes', description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument("library", metavar='path', action="store", help="library directory, for example" " 'openstack/cliff'", ) parser.add_argument("start_revision", metavar='revision', action="store", help="start revision, for example '1.8.0'", ) parser.add_argument("end_revision", metavar='revision', action="store", nargs='?', help="end revision, for example '1.9.0'" " (default: HEAD)", default="HEAD") parser.add_argument('--changes-only', action='store_true', default=False, help='List only the change summary, without details', ) parser.add_argument("--noteable-changes", metavar='path', action="store", help="a file containing any noteable changes") parser.add_argument("--skip-requirement-merges", action='store_true', default=False, help="skip requirement update commit messages" " (default: False)") args = parser.parse_args() library_path = os.path.abspath(args.library) if not os.path.isfile(os.path.join(library_path, "setup.py")): sys.stderr.write("No 'setup.py' file found in %s\n" % library_path) sys.stderr.write("This will not end well...\n") return 1 # Get the python library/program description... cmd = [sys.executable, 'setup.py', '--description'] stdout, stderr = run_cmd(cmd, cwd=library_path) description = stdout.strip() # Get the commits that are in the desired range... git_range = "%s..%s" % (args.start_revision, args.end_revision) cmd = ["git", "log", "--no-color", "--oneline", "--no-merges", git_range] stdout, stderr = run_cmd(cmd, cwd=library_path) changes = [] for commit_line in stdout.splitlines(): commit_line = commit_line.strip() if not commit_line or is_skippable_commit(args, commit_line): continue else: changes.append(commit_line) # Filter out any requirement file changes... requirement_changes = [] requirement_files = list(glob.glob(os.path.join(library_path, '*requirements*.txt'))) if requirement_files: cmd = ['git', 'diff', '-U0', '--no-color', git_range] cmd.extend(requirement_files) stdout, stderr = run_cmd(cmd, cwd=library_path) requirement_changes = [line.strip() for line in stdout.splitlines() if line.strip()] # Get statistics about the range given... cmd = ['git', 'diff', '--stat', '--no-color', git_range] stdout, stderr = run_cmd(cmd, cwd=library_path) diff_stats = [] for line in stdout.splitlines(): line = line.strip() if not line or line.find("tests") != -1 or line.startswith("doc"): continue diff_stats.append(line) # Find what the bug url is... bug_url = '' with open(os.path.join(library_path, 'README.rst'), 'r') as fh: for line in fh: pieces = line.split("Bugs:", 1) if len(pieces) == 2: bug_url = pieces[1].strip() break if not bug_url: raise IOError("No bug url found in '%s'" % os.path.join(library_path, 'README.rst')) noteables = '' if args.noteable_changes: with open(args.noteable_changes, 'r') as fh: noteables = fh.read() lp_url = bug_url.replace("bugs.", "").rstrip("/") milestone_url = lp_url + "/+milestone/%s" % args.end_revision change_header = ["Changes in %s %s" % (library_path, git_range)] change_header.append("-" * len(change_header[0])) params = { 'project': os.path.basename(library_path), 'description': description, 'end_rev': args.end_revision, 'range': git_range, 'lib': library_path, 'milestone_url': milestone_url, 'skip_requirement_merges': args.skip_requirement_merges, 'bug_url': bug_url, 'changes': changes, 'requirement_changes': requirement_changes, 'diff_stats': diff_stats, 'noteables': noteables, 'change_header': "\n".join(change_header), } if args.changes_only: print(expand_template(CHANGES_ONLY_TPL, params)) else: header = expand_template(HEADER_RELEASE_TPL.strip(), params) for line in parawrap.wrap(header): print(line) print(expand_template(CHANGE_RELEASE_TPL, params)) return 0
{{ author }} """ # Example: # # python tools/virtual_sprint.py "taskflow" "next tuesday" "Joshua Harlow" if len(sys.argv) != 4: print("%s project when author" % sys.argv[0]) sys.exit(1) # Something like 'next tuesday' is expected... d = delorean.Delorean() when = getattr(d, sys.argv[2].replace(" ", "_")) project = sys.argv[1] author = sys.argv[3] params = { 'team': 'oslo', 'project': project, 'channel': 'openstack-oslo', 'docs': 'http://docs.openstack.org/developer/%s/' % project, 'when': when().datetime.strftime('%A %m-%d-%Y'), 'starts_at': '16:00 UTC', 'duration': 8, 'author': author, 'git_tree': 'http://git.openstack.org/cgit/openstack/%s/tree' % project, } params['for'] = params['project'] + ' ' + 'subproject' for line in parawrap.wrap(expand_template(TPL.strip(), params)): print(line)
def test_wrap(self): self.assertEqual(wrap('1234567890', width=5), ['12345', '67890'])
import parawrap text = "In late summer 1945, guests are gathered for the wedding reception of Don Vito Corleone's daughter Connie (Talia Shire) and Carlo Rizzi (Gianni Russo). Vito (Marlon Brando), the head of the Corleone Mafia family, is known to friends and associates as Godfather. He and Tom Hagen (Robert Duvall), the Corleone family lawyer, are hearing requests for favors because, according to Italian tradition, no Sicilian can refuse a request on his daughter's wedding day. One of the men who asks the Don for a favor is Amerigo Bonasera, a successful mortician and acquaintance of the Don, whose daughter was brutally beaten by two young men because she refused their advances; the men received minimal punishment from the presiding judge. The Don is disappointed in Bonasera, who'd avoided most contact with the Don due to Corleone's nefarious business dealings. The Don's wife is godmother to Bonasera's shamed daughter, a relationship the Don uses to extract new loyalty from the undertaker. The Don agrees to have his men punish the young men responsible (in a non-lethal manner) in return for future service if necessary." print(parawrap.wrap(text, 10))