def run(self, args_orig): try: config = Configuration(args_orig) args = config.get_args() except ConfigurationException as ce: warnings.warn("Configuration exception occurred:") warnings.warn(ce) sys.exit(1) # check gnuplot version needed to HTML reports if config.is_html_output() and not config.is_valid_gnuplot_version(): warnings.warn("Invalid gnuplot version. Required " "minimal version: %s. Current version: %s" % (Configuration.GNUPLOT_MINIMAL_VERSION, config.get_gnuplot_version())) sys.exit(1) output_path = args.output_path run_dir = config.get_run_dir() print('Output path: %s' % output_path) cachefile = os.path.join(output_path, 'gitstats.cache') data = GitDataCollector(config.get_args_dict()) data.load_cache(cachefile) # todo: Check loop result. It seems every loop rewrite the collected information in data object. # Is this loop really needed? # for git_repo in args.git_repo: print('Git path: %s' % args.git_repo) prevdir = os.getcwd() os.chdir(args.git_repo) print('Collecting data...') data.collect(args.git_repo) os.chdir(prevdir) print('Refining data...') # data.saveCache(cachefile) data.refine() os.chdir(run_dir) print('Generating report...') # fixme: pass GitStatistics object directly when obsolete GitDataCollector is removed if config.is_html_output(): print('Generating HTML report...') report = HTMLReportCreator(config, data.repo_statistics) report.create(data, output_path) if sys.stdin.isatty(): print('You may now run:') print('') print(' sensible-browser \'%s\'' % os.path.join(output_path, 'general.html').replace("'", "'\\''")) print('') elif config.is_csv_output(): print('Generating CSV report...') report = CSVReportCreator() report.create(data.repo_statistics, output_path, config.get_args_dict(), config.is_append_csv()) print('CSV report created here: %s' % output_path) self.get_times()
def __init__(self, config: Configuration, repo_stat): self.data = None self.path = None self.configuration = config self.conf = config.get_args_dict() self.git_repo_statistics = repo_stat templates_dir = os.path.join(self.configuration.repostat_root_dir, 'templates') self.j2_env = Environment(loader=FileSystemLoader(templates_dir), trim_blocks=True) self.j2_env.filters[ 'to_month_name_abr'] = lambda im: calendar.month_abbr[im] self.j2_env.filters['to_weekday_name'] = lambda i: calendar.day_name[i] self.j2_env.filters['to_ratio'] = lambda val, max_val: (float( val) / max_val) if max_val != 0 else 0 self.j2_env.filters['to_percentage'] = lambda val, max_val: ( 100 * float(val) / max_val) if max_val != 0 else 0 self.j2_env.filters['to_intensity'] = lambda val, max_val: 127 + int( (float(val) / max_val) * 128)
def main(): try: config = Configuration(sys.argv[1:]) args = config.get_args() except ConfigurationException as ce: warnings.warn("Configuration exception occurred:") warnings.warn(ce) sys.exit(1) # check gnuplot version needed to HTML reports if config.is_html_output() and not config.is_valid_gnuplot_version(): warnings.warn("Invalid gnuplot version. Required " "minimal version: %s. Current version: %s" % (Configuration.GNUPLOT_MINIMAL_VERSION, config.get_gnuplot_version())) sys.exit(1) print('Git path: %s' % args.git_repo) print('Collecting data...') repository_statistics = GitStatistics(args.git_repo) output_path = args.output_path print('Output path: %s' % output_path) os.chdir(config.get_run_dir()) if config.is_html_output(): print('Generating HTML report...') report = HTMLReportCreator(config, repository_statistics) report.create(output_path) if sys.stdin.isatty(): print('You may now run:') print('') print(' sensible-browser \'%s\'' % os.path.join(output_path, 'general.html').replace("'", "'\\''")) print('') elif config.is_csv_output(): print('Generating CSV report...') report = CSVReportCreator() report.create(repository_statistics, output_path, config.get_args_dict(), config.is_append_csv()) print('CSV report created here: %s' % output_path) print_exec_times()