Last active
August 29, 2015 14:05
-
-
Save cybertk/c11c3a31b59f46aa6961 to your computer and use it in GitHub Desktop.
Render github issue with link
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import optparse | |
import sys | |
import re | |
class WrongNumberOfArgumentsException(Exception): | |
pass | |
def log(msg): | |
if not verbose: | |
return | |
print msg | |
def DoMain(argv): | |
parser = optparse.OptionParser() | |
usage = 'Usage: %prog <input_file>' | |
parser.set_usage(usage) | |
options, arglist = parser.parse_args(argv) | |
if len(arglist) == 0: | |
raise WrongNumberOfArgumentsException('<input_file> required.') | |
regex = re.compile(r'([^\[])#([0-9]+)([^\]])') | |
f = open(arglist[0], 'r+') | |
lines = f.readlines() | |
f.seek(0) | |
for line in lines: | |
m = regex.search(line) | |
if m: | |
line = regex.sub(r'\1[#\2](%s\2)\3' % "../../issues/", line) | |
f.write(line) | |
f.close() | |
def main(argv): | |
try: | |
result = DoMain(argv[1:]) | |
except WrongNumberOfArgumentsException, e: | |
print >>sys.stderr, e | |
return 1 | |
if result: | |
print result | |
return 0 | |
if __name__ == '__main__': | |
sys.exit(main(sys.argv)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment