From dffb3ca0fa89cc0f915f34c7e9ebb72a5de23f5e Mon Sep 17 00:00:00 2001 From: Heikki Hokkanen Date: Sat, 16 Jan 2010 15:21:38 +0200 Subject: [PATCH] Cleanup: moved rest of the code to a new class. --- gitstats | 68 ++++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/gitstats b/gitstats index 9735487..9dc9c27 100755 --- a/gitstats +++ b/gitstats @@ -1073,49 +1073,53 @@ plot 'lines_of_code.dat' using 1:2 w lines """) -usage = """ +class GitStats: + def run(self, args): + if len(args) < 2: + print """ Usage: gitstats [options] Options: """ + sys.exit(0) -if len(sys.argv) < 3: - print usage - sys.exit(0) + gitpath = args[0] + outputpath = os.path.abspath(args[1]) + rundir = os.getcwd() -gitpath = sys.argv[1] -outputpath = os.path.abspath(sys.argv[2]) -rundir = os.getcwd() + try: + os.makedirs(outputpath) + except OSError: + pass + if not os.path.isdir(outputpath): + print 'FATAL: Output path is not a directory or does not exist' + sys.exit(1) + + print 'Git path: %s' % gitpath + print 'Output path: %s' % outputpath -try: - os.makedirs(outputpath) -except OSError: - pass -if not os.path.isdir(outputpath): - print 'FATAL: Output path is not a directory or does not exist' - sys.exit(1) + os.chdir(gitpath) -print 'Git path: %s' % gitpath -print 'Output path: %s' % outputpath + cachefile = os.path.join(outputpath, 'gitstats.cache') -os.chdir(gitpath) + print 'Collecting data...' + data = GitDataCollector() + data.loadCache(cachefile) + data.collect(gitpath) + print 'Refining data...' + data.saveCache(cachefile) + data.refine() -cachefile = os.path.join(outputpath, 'gitstats.cache') + os.chdir(rundir) -print 'Collecting data...' -data = GitDataCollector() -data.loadCache(cachefile) -data.collect(gitpath) -print 'Refining data...' -data.saveCache(cachefile) -data.refine() + print 'Generating report...' + report = HTMLReportCreator() + report.create(data, outputpath) -os.chdir(rundir) + time_end = time.time() + exectime_internal = time_end - time_start + print 'Execution time %.5f secs, %.5f secs (%.2f %%) in external commands)' % (exectime_internal, exectime_external, (100.0 * exectime_external) / exectime_internal) -print 'Generating report...' -report = HTMLReportCreator() -report.create(data, outputpath) +g = GitStats() +g.run(sys.argv[1:]) -time_end = time.time() -exectime_internal = time_end - time_start -print 'Execution time %.5f secs, %.5f secs (%.2f %%) in external commands)' % (exectime_internal, exectime_external, (100.0 * exectime_external) / exectime_internal) -- 2.11.4.GIT