There may be a better module for this in the bzrlib in general but I have not been able to find it. I would like to be able to return the output of the bzrlib function: log.show_log()
as a script so that I could then use the python re.search
function to find specific information within the human readable version of the log.
I have tried using the simple str()
function but with no luck. I only get NONE as my feedback.
Here is my code:
parser = argparse.ArgumentParser()
parser.add_argument('-r', '--revnum', type=int, metavar='', required=True, help='Baseline revision number')
parser.add_argument('-d', '--directory',type=str, metavar='',required=True,help='Directory that repository in question is located')
args = parser.parse_args()
r1= args.revnum
d1= args.directory
print ''
print 'Directory containing repository: '+ (d1)
print ''
print ("Input revision number: %s" %(r1))
print ''
b = Branch.open (d1)
lf = log.LongLogFormatter(to_file=sys.stdout, levels=0)
h = log.show_log(b, lf, verbose=False, start_revision=r1, end_revision=r1)
mystring = str (h)
print mystring
result2 = re.findall(r'\d+\.\d+\.\d+ \[merge\]', mystring)
print result2
show_log() doesn't return anything, but it instead writes to the log formatter that it accepts as its second argument.
You're specifying to_file=sys.stdout
, so the output is going to standard output.
You probably want to pass in a io.StringIO() object as to_file instead, and then call .getvalue() on it to get the output.