mirror of
https://github.com/elisspace/autopsy.git
synced 2026-08-29 15:43:50 +00:00
omitted files work
This commit is contained in:
@@ -7,6 +7,7 @@ repo is on correct branch (i.e. develop).
|
||||
import sys
|
||||
|
||||
from envutil import get_proj_dir
|
||||
from fileutil import get_filename_addition, OMITTED_ADDITION
|
||||
from gitutil import get_property_file_entries, get_commit_id, get_git_root
|
||||
from csvutil import records_to_csv
|
||||
from typing import Union
|
||||
@@ -29,13 +30,20 @@ def write_items_to_csv(repo_path: str, output_path: str, show_commit: bool, valu
|
||||
if show_commit:
|
||||
row_header.append(get_commit_id(repo_path, 'HEAD'))
|
||||
|
||||
rows = [row_header]
|
||||
rows = []
|
||||
omitted = []
|
||||
|
||||
for entry in get_property_file_entries(repo_path):
|
||||
new_entry = [entry.rel_path, entry.key, entry.value]
|
||||
if value_regex is None or re.match(value_regex, entry.value):
|
||||
rows.append([entry.rel_path, entry.key, entry.value])
|
||||
rows.append(new_entry)
|
||||
else:
|
||||
omitted.append(new_entry)
|
||||
|
||||
records_to_csv(output_path, rows)
|
||||
records_to_csv(output_path, [row_header] + rows)
|
||||
|
||||
if len(omitted) > 0:
|
||||
records_to_csv(get_filename_addition(output_path, OMITTED_ADDITION), [row_header] + omitted)
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
@@ -2,17 +2,15 @@
|
||||
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 re
|
||||
import sys
|
||||
|
||||
from envutil import get_proj_dir
|
||||
from fileutil import get_filename_addition, OMITTED_ADDITION
|
||||
from gitutil import get_property_files_diff, get_commit_id, get_git_root
|
||||
from itemchange import ItemChange
|
||||
from itemchange import ItemChange, ChangeType
|
||||
from csvutil import records_to_csv
|
||||
import argparse
|
||||
from typing import Union
|
||||
import re
|
||||
|
||||
from langpropsutil import get_commit_for_language, LANG_FILENAME
|
||||
|
||||
|
||||
@@ -34,15 +32,20 @@ def write_diff_to_csv(repo_path: str, output_path: str, commit_1_id: str, commit
|
||||
if show_commits:
|
||||
row_header += [get_commit_id(repo_path, commit_1_id), get_commit_id(repo_path, commit_2_id)]
|
||||
|
||||
rows = [row_header]
|
||||
rows = []
|
||||
omitted = []
|
||||
|
||||
item_changes = get_property_files_diff(repo_path, commit_1_id, commit_2_id)
|
||||
if value_regex is not None:
|
||||
item_changes = filter(lambda item_change: re.match(value_regex, item_change.cur_val) is not None, item_changes)
|
||||
for entry in get_property_files_diff(repo_path, commit_1_id, commit_2_id):
|
||||
new_entry = [entry.rel_path, entry.key, entry.value]
|
||||
if value_regex is not None and (entry.type == ChangeType.DELETION or (not re.match(value_regex, entry.value))):
|
||||
omitted.append(new_entry)
|
||||
else:
|
||||
rows.append(new_entry)
|
||||
|
||||
rows += map(lambda item_change: item_change.get_row(), item_changes)
|
||||
records_to_csv(output_path, [row_header] + rows)
|
||||
|
||||
records_to_csv(output_path, rows)
|
||||
if len(omitted) > 0:
|
||||
records_to_csv(get_filename_addition(output_path, OMITTED_ADDITION), [row_header] + omitted)
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
from typing import Iterator, List, Union
|
||||
from propsutil import get_entry_dict
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class ChangeType(Enum):
|
||||
"""Describes the nature of a change in the properties file."""
|
||||
ADDITION = 'ADDITION'
|
||||
DELETION = 'DELETION'
|
||||
CHANGE = 'CHANGE'
|
||||
|
||||
|
||||
class ItemChange:
|
||||
@@ -7,7 +15,7 @@ class ItemChange:
|
||||
key: str
|
||||
prev_val: str
|
||||
cur_val: str
|
||||
type: str
|
||||
type: ChangeType
|
||||
|
||||
def __init__(self, rel_path: str, key: str, prev_val: str, cur_val: str):
|
||||
"""Describes the change that occurred for a particular key of a properties file.
|
||||
@@ -23,11 +31,11 @@ class ItemChange:
|
||||
self.prev_val = prev_val
|
||||
self.cur_val = cur_val
|
||||
if ItemChange.has_str_content(cur_val) and not ItemChange.has_str_content(prev_val):
|
||||
self.type = 'ADDITION'
|
||||
self.type = ChangeType.ADDITION
|
||||
elif not ItemChange.has_str_content(cur_val) and ItemChange.has_str_content(prev_val):
|
||||
self.type = 'DELETION'
|
||||
self.type = ChangeType.DELETION
|
||||
else:
|
||||
self.type = 'CHANGE'
|
||||
self.type = ChangeType.CHANGE
|
||||
|
||||
@staticmethod
|
||||
def has_str_content(content: str):
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
from typing import TypeVar, Callable, Tuple
|
||||
|
||||
|
||||
def is_match(content: str, regex: str) -> bool:
|
||||
pass
|
||||
|
||||
T = TypeVar('T')
|
||||
|
||||
def is_match_on_field(obj: T, prop_retriever: Callable[T, str]) -> bool:
|
||||
pass
|
||||
|
||||
class SeparationResult:
|
||||
|
||||
def __init__(self, ):
|
||||
|
||||
def separate(obj: T, prop_retriever: Callable[T, str]) ->
|
||||
@@ -7,6 +7,7 @@ import sys
|
||||
import os
|
||||
|
||||
from envutil import get_proj_dir
|
||||
from fileutil import get_new_path
|
||||
from gitutil import get_git_root
|
||||
from langpropsutil import set_commit_for_language
|
||||
from propsutil import set_entry_dict, get_entry_dict_from_path, get_lang_bundle_name
|
||||
@@ -166,22 +167,6 @@ def get_should_deleted(row_items: List[str], requested_idx: int) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
def get_new_rel_path(orig_path: str, new_filename: str) -> str:
|
||||
"""Obtains a new relative path. This tries to determine if the provided path is a directory or filename (has an
|
||||
extension containing '.') then constructs the new path with the old parent directory and the new filename.
|
||||
|
||||
Args:
|
||||
orig_path (str): The original path.
|
||||
new_filename (str): The new filename to use.
|
||||
|
||||
Returns:
|
||||
str: The new path.
|
||||
"""
|
||||
potential_parent_dir, orig_file = os.path.split(orig_path)
|
||||
parent_dir = orig_path if '.' not in orig_file else potential_parent_dir
|
||||
return os.path.join(parent_dir, new_filename)
|
||||
|
||||
|
||||
def main():
|
||||
# noinspection PyTypeChecker
|
||||
parser = argparse.ArgumentParser(description='Updates properties files in the autopsy git repo.',
|
||||
@@ -243,10 +228,10 @@ def main():
|
||||
# provides the means of renaming the bundle file
|
||||
if args.language is not None:
|
||||
def path_converter(orig_path: str):
|
||||
return get_new_rel_path(orig_path, get_lang_bundle_name(args.language))
|
||||
return get_new_path(orig_path, get_lang_bundle_name(args.language))
|
||||
elif args.file_rename is not None:
|
||||
def path_converter(orig_path: str):
|
||||
return get_new_rel_path(orig_path, args.file_rename)
|
||||
return get_new_path(orig_path, args.file_rename)
|
||||
else:
|
||||
path_converter = None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user