mirror of
https://github.com/elisspace/autopsy.git
synced 2026-10-02 23:39:50 +00:00
now working to update update script and documentation for excel
This commit is contained in:
@@ -3,44 +3,21 @@ This script requires the python libraries: gitpython and jproperties. As a cons
|
||||
git >= 1.7.0 and python >= 3.4. This script relies on fetching 'HEAD' from current branch. So make sure
|
||||
repo is on correct branch (i.e. develop).
|
||||
"""
|
||||
import collections
|
||||
import sys
|
||||
|
||||
from envutil import get_proj_dir
|
||||
from excelutil import records_to_excel
|
||||
from fileutil import get_filename_addition, OMITTED_ADDITION
|
||||
from excelutil import write_results_to_xlsx
|
||||
from gitutil import get_property_file_entries, get_commit_id, get_git_root
|
||||
from csvutil import records_to_csv
|
||||
from typing import Union, TypedDict, List
|
||||
from csvutil import write_results_to_csv
|
||||
from typing import Union
|
||||
import re
|
||||
import argparse
|
||||
|
||||
|
||||
class ProcessingResult:
|
||||
results: List[List[str]]
|
||||
omitted: Union[List[List[str]], None]
|
||||
|
||||
def __init__(self, results: List[List[str]], omitted: Union[List[List[str]], None]):
|
||||
self.results = results
|
||||
self.omitted = omitted
|
||||
|
||||
|
||||
def write_items_to_csv(results: ProcessingResult, output_path: str):
|
||||
records_to_csv(output_path, results.results)
|
||||
if results.omitted:
|
||||
records_to_csv(get_filename_addition(output_path, OMITTED_ADDITION), results.omitted)
|
||||
|
||||
|
||||
def write_items_to_xlsx(results: ProcessingResult, output_path: str):
|
||||
workbook = collections.OrderedDict([('results', results.results)])
|
||||
if results.omitted:
|
||||
workbook['omitted'] = results.omitted
|
||||
|
||||
records_to_excel(output_path, workbook)
|
||||
from outputresult import OutputResult
|
||||
from outputtype import OutputType
|
||||
|
||||
|
||||
def get_items_to_be_written(repo_path: str, show_commit: bool,
|
||||
value_regex: Union[str, None] = None) -> ProcessingResult:
|
||||
value_regex: Union[str, None] = None) -> OutputResult:
|
||||
"""Determines the contents of '.properties-MERGED' files and writes to a csv file.
|
||||
|
||||
Args:
|
||||
@@ -65,28 +42,37 @@ def get_items_to_be_written(repo_path: str, show_commit: bool,
|
||||
omitted.append(new_entry)
|
||||
|
||||
omitted_to_write = [row_header] + omitted if len(omitted) > 0 else None
|
||||
return ProcessingResult([row_header] + rows, omitted_to_write)
|
||||
return OutputResult([row_header] + rows, omitted_to_write)
|
||||
|
||||
|
||||
def main():
|
||||
# noinspection PyTypeChecker
|
||||
parser = argparse.ArgumentParser(description='Gathers all key-value pairs within .properties-MERGED files into '
|
||||
'one csv file.',
|
||||
'one file.',
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
||||
parser.add_argument(dest='output_path', type=str, help='The path to the output csv file. The output path should be'
|
||||
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.')
|
||||
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('-nc', '--no_commit', dest='no_commit', action='store_true', default=False,
|
||||
required=False, help="Suppresses adding commits to the generated csv header.")
|
||||
required=False, help="Suppresses adding commits to the generated header.")
|
||||
|
||||
args = parser.parse_args()
|
||||
repo_path = args.repo_path if args.repo_path is not None else get_git_root(get_proj_dir())
|
||||
output_path = args.output_path
|
||||
show_commit = not args.no_commit
|
||||
output_type = args.output_type
|
||||
|
||||
write_items_to_csv(repo_path, output_path, show_commit)
|
||||
processing_result = get_items_to_be_written(repo_path, show_commit)
|
||||
|
||||
# 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