def main(): try: config = Configuration(sys.argv[1:]) Requirements(config).check() except EnvironmentError as ee: warnings.warn("Environment exception occurred: {}".format(ee)) sys.exit(1) print('Git path: %s' % config.git_repository_path) print('Collecting data...') repository_statistics = GitStatistics(config.git_repository_path) output_path = config.statistics_output_path print('Output path: %s' % output_path) os.makedirs(output_path, exist_ok=True) print('Generating HTML report...') HTMLReportCreator(config, repository_statistics).create(output_path) print_exec_times() url = os.path.join(output_path, 'general.html').replace("'", "'\\''") if config.do_open_in_browser(): webbrowser.open(url, new=2) else: print("You may open your report in a browser. Path: {}".format(url))
def test_gnuplot_version_faild_not_exists(self): expected_project_name = "UTEST HTML Project" cli_params = list([ '--project_name=' + expected_project_name, self.repo_folder, self.output_folder ]) config = Configuration(cli_params) # rewrite fields with test data self.assertFalse(config.is_valid_gnuplot_version('-'))
def test_gnuplot_version_failed_lower(self): expected_project_name = "UTEST HTML Project" cli_params = list([ '--project_name=' + expected_project_name, self.repo_folder, self.output_folder ]) config = Configuration(cli_params) # rewrite fields with test data config.GNUPLOT_VERSION_STRING = '5.0' config.GNUPLOT_MINIMAL_VERSION = '5.2' self.assertFalse(config.is_valid_gnuplot_version())
def __init__(self, config: Configuration, repository: GitRepository): self.path = None self.configuration = config self.assets_path = os.path.join(HERE, self.assets_subdir) self.git_repository_statistics = repository self.has_tags_page = config.do_process_tags() self._time_sampling_interval = "W" self._do_generate_index_page = False self._is_blame_data_allowed = False self._max_orphaned_extensions_count = 0 templates_dir = os.path.join(HERE, self.templates_subdir) 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 colors = colormaps.colormaps[self.configuration['colormap']] self.j2_env.filters[ 'to_heatmap'] = lambda val, max_val: "%d, %d, %d" % colors[int( float(val) / max_val * (len(colors) - 1))]
def test_configuration_argparse_parse(self): cli_params = list([ '--project_name=UTEST Project', '--output_format=csv', self.repo_folder, self.output_folder ]) args = Configuration(cli_params).get_args() print(args.project_name) print(args)
def test_configuration_invalid_output_dir(self): cli_params = list([ '--project_name=UTEST Project', '--output_format=csv', self.repo_folder, self.read_only_folder ]) with self.assertRaises(argparse.ArgumentTypeError) as context: configuration = Configuration(cli_params) self.assertTrue( isinstance(context.exception, argparse.ArgumentTypeError))
def test_partial_json_config_parser(self): # test config with partially filled json config file cli_params = list([ '--project_name=UTEST Project', '--output_format=csv', '--config_file=partial-config-test.json', self.repo_folder, self.output_folder ]) config = Configuration(cli_params) args = config.get_args() self.assertEqual( args.git_repo, self.repo_folder, "test_json_config_parser result git_repo is different than expected" ) self.assertEqual( args.output_path, self.output_folder, "test_json_config_parser result output_path is different than expected" ) self.assertEqual( args.project_name, 'UTEST Project', "test_json_config_parser result project_name is different than expected" ) self.assertEqual( args.output_format, 'csv', "test_json_config_parser result output_format is different than expected" ) # default self.assertEqual( args.authors_top, 5, "test_json_config_parser result authors_top is different than expected" ) # from partial config json self.assertEqual( args.max_domains, 9, "test_json_config_parser result max_domains is different than expected" ) # from partial config json self.assertEqual( args.max_authors, 1, "test_json_config_parser result max_authors is different than expected" )
def test_process_and_validate_params_html_success(self): expected_project_name = "UTEST HTML Project" cli_params = list([ '--project_name=' + expected_project_name, self.repo_folder, self.output_folder ]) config = Configuration(cli_params) args = config.get_args() self.assertEqual( args.git_repo, self.repo_folder, "test_process_and_validate_params_csv_success result git_repo is different than expected" ) self.assertEqual( args.output_path, self.output_folder, "test_process_and_validate_params_csv_success result output_path is different than expected" ) self.assertEqual( args.project_name, expected_project_name, "test_process_and_validate_params_csv_success result project_name is different than expected" ) self.assertTrue(config.is_html_output()) self.assertFalse(config.is_csv_output()) self.assertFalse(config.is_append_csv())
def test_process_and_validate_params_csv_success(self): # append_csv param added cli_params = list([ '--project_name=UTEST Project', '--output_format=csv', '--append_csv', self.repo_folder, self.output_folder ]) config = Configuration(cli_params) args = config.get_args() self.assertEqual( args.git_repo, self.repo_folder, "test_process_and_validate_params_csv_success result git_repo is different than expected" ) self.assertEqual( args.output_path, self.output_folder, "test_process_and_validate_params_csv_success result output_path is different than expected" ) self.assertEqual( args.project_name, 'UTEST Project', "test_process_and_validate_params_csv_success result project_name is different than expected" ) self.assertEqual( args.output_format, 'csv', "test_process_and_validate_params_csv_success result output is different than expected" ) # Check options override init configuration self.assertTrue(config.is_csv_output()) self.assertFalse(config.is_html_output()) # append_csv param True expected self.assertTrue(config.is_append_csv())
def test_json_config_parser_defaults(self): # test config without json config file cli_params = list([ '--project_name=UTEST Project', '--output_format=csv', self.repo_folder, self.output_folder ]) config = Configuration(cli_params) args = config.get_args() self.assertEqual( args.git_repo, self.repo_folder, "test_json_config_parser result git_repo is different than expected" ) self.assertEqual( args.output_path, self.output_folder, "test_json_config_parser result output_path is different than expected" ) self.assertEqual( args.project_name, 'UTEST Project', "test_json_config_parser result project_name is different than expected" ) self.assertEqual( args.output_format, 'csv', "test_json_config_parser result output_format is different than expected" ) # Check default config values without config json self.assertEqual( args.authors_top, 5, "test_json_config_parser result authors_top is different than expected" ) self.assertEqual( args.max_domains, 10, "test_json_config_parser result max_domains is different than expected" ) self.assertEqual( args.max_authors, 7, "test_json_config_parser result max_authors is different than expected" ) self.assertFalse(args.append_csv)
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 __init__(self, config: Configuration, repo_stat): self.path = None self.configuration = config self.assets_path = os.path.join(HERE, self.assets_subdir) self.git_repo_statistics = repo_stat self.has_tags_page = config.do_process_tags() self.common_rendering_data = { "assets_path": self.assets_path, "has_tags_page": self.has_tags_page } templates_dir = os.path.join(HERE, self.templates_subdir) 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:]) except EnvironmentError as ee: warnings.warn("Environment exception occurred: {}".format(ee)) sys.exit(1) print('Git path: %s' % config.git_repository_path) print('Collecting data...') repository_statistics = GitRepository(config.git_repository_path) output_path = config.statistics_output_path print('Output path: %s' % output_path) os.makedirs(output_path, exist_ok=True) print('Generating HTML report...') report = HTMLReportCreator(config, repository_statistics) report.set_time_sampling(config.get_time_sampling())\ .generate_index_page(config.do_generate_index_page())\ .set_max_orphaned_extensions_count(config.get_max_orphaned_extensions_count()) if config.do_calculate_contribution(): report.allow_blame_data() report.create(output_path) exec_time_seconds = get_execution_time() print('Report generated in %.2f secs.' % exec_time_seconds) url = os.path.join(output_path, 'general.html').replace("'", "'\\''") if config.do_open_in_browser(): webbrowser.open(url, new=2) else: print("You may open your report in a browser. Path: {}".format(url))
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()
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): self.gnuplot_version = version.LooseVersion( config.get_gnuplot_version()) self.python_version = version.LooseVersion(sys.version.split()[0])
from setuptools import setup from tools.configuration import Configuration with open("README.md", "r") as fh: long_description = fh.read() with open('requirements.txt', "r") as req_file: requirements = req_file.read().splitlines() # such name for package is used here because 'repostat' is already occupied by https://pypi.org/project/repostat/ setup(name='repostat-app', version=Configuration.get_release_data_info()['develop_version'], description='Desktop git repository analyser and report creator.', keywords='git analysis statistics vcs python visualization', url='https://github.com/vifactor/repostat', author='Viktor Kopp', author_email='*****@*****.**', license='GPLv3', long_description=long_description, long_description_content_type="text/markdown", classifiers=[ "Development Status :: 5 - Production/Stable", "Environment :: Console", "Intended Audience :: Developers", "Intended Audience :: Science/Research", "Intended Audience :: Education", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)", "Topic :: Software Development :: Version Control", "Topic :: Utilities",
def test_configuration_argparse_usage(self): # FIXME: this mainly tests third-party argparse library parser = Configuration.get_gitstat_parser() parser.print_usage() print() parser.print_help()