mirror of
https://github.com/elisspace/autopsy.git
synced 2026-08-31 00:22:00 +00:00
now working to update update script and documentation for excel
This commit is contained in:
@@ -2,47 +2,22 @@
|
||||
and generates a csv file containing the items changed. This script requires the python libraries:
|
||||
gitpython and jproperties. As a consequence, it also requires git >= 1.7.0 and python >= 3.4.
|
||||
"""
|
||||
import collections
|
||||
import re
|
||||
import sys
|
||||
from envutil import get_proj_dir
|
||||
from excelutil import records_to_excel
|
||||
from fileutil import get_filename_addition, OMITTED_ADDITION, DELETED_ADDITION
|
||||
from excelutil import write_results_to_xlsx
|
||||
from gitutil import get_property_files_diff, get_commit_id, get_git_root
|
||||
from itemchange import ItemChange, ChangeType
|
||||
from csvutil import records_to_csv
|
||||
from csvutil import write_results_to_csv
|
||||
import argparse
|
||||
from typing import Union, TypedDict, List
|
||||
from typing import Union
|
||||
from langpropsutil import get_commit_for_language, LANG_FILENAME
|
||||
|
||||
|
||||
class DiffResult:
|
||||
results: List[List[str]]
|
||||
deleted: Union[List[List[str]], None]
|
||||
omitted: Union[List[List[str]], None]
|
||||
|
||||
|
||||
def write_items_to_csv(results: DiffResult, output_path: str):
|
||||
records_to_csv(output_path, results.results)
|
||||
if results.deleted:
|
||||
records_to_csv(get_filename_addition(output_path, DELETED_ADDITION), results.deleted)
|
||||
if results.omitted:
|
||||
records_to_csv(get_filename_addition(output_path, OMITTED_ADDITION), results.omitted)
|
||||
|
||||
|
||||
def write_items_to_xlsx(results: DiffResult, output_path: str):
|
||||
workbook = collections.OrderedDict([('results', results.results)])
|
||||
if results.deleted:
|
||||
workbook['deleted'] = results.deleted
|
||||
|
||||
if results.omitted:
|
||||
workbook['omitted'] = results.omitted
|
||||
|
||||
records_to_excel(output_path, workbook)
|
||||
from outputresult import OutputResult
|
||||
from outputtype import OutputType
|
||||
|
||||
|
||||
def get_diff_to_write(repo_path: str, commit_1_id: str, commit_2_id: str, show_commits: bool, separate_deleted: bool,
|
||||
value_regex: Union[str, None] = None) -> DiffResult:
|
||||
value_regex: Union[str, None] = None) -> OutputResult:
|
||||
"""Determines the changes made in '.properties-MERGED' files from one commit to another commit and returns results.
|
||||
|
||||
Args:
|
||||
@@ -66,7 +41,7 @@ def get_diff_to_write(repo_path: str, commit_1_id: str, commit_2_id: str, show_c
|
||||
|
||||
for entry in get_property_files_diff(repo_path, commit_1_id, commit_2_id):
|
||||
entry_row = entry.get_row()
|
||||
if entry.type == ChangeType.DELETION:
|
||||
if separate_deleted and entry.type == ChangeType.DELETION:
|
||||
deleted.append(entry_row)
|
||||
if value_regex is not None and re.match(value_regex, entry.cur_val):
|
||||
omitted.append(entry_row)
|
||||
@@ -76,13 +51,7 @@ def get_diff_to_write(repo_path: str, commit_1_id: str, commit_2_id: str, show_c
|
||||
omitted_result = [row_header] + omitted if len(omitted) > 0 else None
|
||||
deleted_result = [row_header] + deleted if len(deleted) > 0 else None
|
||||
|
||||
return {
|
||||
'results': [row_header] + rows,
|
||||
'omitted': omitted_result,
|
||||
'deleted': deleted_result
|
||||
}
|
||||
|
||||
|
||||
return OutputResult([row_header] + rows, omitted_result, deleted_result)
|
||||
|
||||
|
||||
def main():
|
||||
@@ -91,9 +60,9 @@ def main():
|
||||
"'.properties-MERGED' files and generates a csv file containing "
|
||||
"the items changed.",
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
||||
parser.add_argument(dest='output_path', type=str, help='The path to the output csv file. The output path should '
|
||||
parser.add_argument(dest='output_path', type=str, help='The path to the output file. The output path should '
|
||||
'be specified as a relative path with the dot slash notation'
|
||||
' (i.e. \'./outputpath.csv\') or an absolute path.')
|
||||
' (i.e. \'./outputpath.xlsx\') or an absolute path.')
|
||||
|
||||
parser.add_argument('-r', '--repo', dest='repo_path', type=str, required=False,
|
||||
help='The path to the repo. If not specified, path of script is used.')
|
||||
@@ -104,6 +73,8 @@ def main():
|
||||
help='The commit for current release.')
|
||||
parser.add_argument('-nc', '--no-commits', dest='no_commits', action='store_true', default=False,
|
||||
required=False, help="Suppresses adding commits to the generated csv header.")
|
||||
parser.add_argument('-o', '--output-type', dest='output_type', type=OutputType, choices=list(OutputType),
|
||||
required=False, help="The output type. Currently supports 'csv' or 'xlsx'.", default='xlsx')
|
||||
parser.add_argument('-l', '--language', dest='language', type=str, default=None, required=False,
|
||||
help='Specify the language in order to determine the first commit to use (i.e. \'ja\' for '
|
||||
'Japanese. This flag overrides the first-commit flag.')
|
||||
@@ -112,6 +83,8 @@ def main():
|
||||
repo_path = args.repo_path if args.repo_path is not None else get_git_root(get_proj_dir())
|
||||
output_path = args.output_path
|
||||
commit_1_id = args.commit_1_id
|
||||
output_type = args.output_type
|
||||
|
||||
lang = args.language
|
||||
if lang is not None:
|
||||
commit_1_id = get_commit_for_language(lang)
|
||||
@@ -125,7 +98,13 @@ def main():
|
||||
commit_2_id = args.commit_2_id
|
||||
show_commits = not args.no_commits
|
||||
|
||||
write_diff_to_csv(repo_path, output_path, commit_1_id, commit_2_id, show_commits)
|
||||
processing_result = get_diff_to_write(repo_path, commit_1_id, commit_2_id, show_commits)
|
||||
|
||||
# based on https://stackoverflow.com/questions/60208/replacements-for-switch-statement-in-python
|
||||
{
|
||||
OutputType.csv: write_results_to_csv,
|
||||
OutputType.xlsx: write_results_to_xlsx
|
||||
}[output_type](processing_result, output_path)
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user