mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-06 21:00:22 +00:00
updates to include updated
This commit is contained in:
parent
f8cff3ff1d
commit
f836176009
@ -5,9 +5,10 @@ repo is on correct branch (i.e. develop).
|
||||
"""
|
||||
|
||||
import sys
|
||||
|
||||
from envutil import get_proj_dir
|
||||
from gitutil import get_property_file_entries, get_commit_id
|
||||
from csvutil import records_to_csv
|
||||
import pathlib
|
||||
import argparse
|
||||
|
||||
|
||||
@ -25,6 +26,7 @@ def write_items_to_csv(repo_path: str, output_path: str, show_commit: bool):
|
||||
row_header.append(get_commit_id(repo_path, 'HEAD'))
|
||||
|
||||
rows = [row_header]
|
||||
|
||||
for entry in get_property_file_entries(repo_path):
|
||||
rows.append([entry.rel_path, entry.key, entry.value])
|
||||
|
||||
@ -32,8 +34,9 @@ def write_items_to_csv(repo_path: str, output_path: str, show_commit: bool):
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description='Gathers all key-value pairs within .properties-MERGED files into ' +
|
||||
'one csv file.')
|
||||
parser = argparse.ArgumentParser(description='Gathers all key-value pairs within .properties-MERGED files into '
|
||||
'one csv file.',
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
||||
parser.add_argument(dest='output_path', type=str, help='The path to the output csv file.')
|
||||
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.')
|
||||
@ -41,7 +44,7 @@ def main():
|
||||
required=False, help="Suppresses adding commits to the generated csv header.")
|
||||
|
||||
args = parser.parse_args()
|
||||
repo_path = args.repo_path if args.repo_path is not None else str(pathlib.Path(__file__).parent.absolute())
|
||||
repo_path = args.repo_path if args.repo_path is not None else get_proj_dir()
|
||||
output_path = args.output_path
|
||||
show_commit = not args.no_commit
|
||||
|
||||
|
@ -4,6 +4,8 @@ gitpython and jproperties. As a consequence, it also requires git >= 1.7.0 and
|
||||
"""
|
||||
|
||||
import sys
|
||||
|
||||
from envutil import get_proj_dir
|
||||
from gitutil import get_property_files_diff, get_commit_id
|
||||
from itemchange import ItemChange
|
||||
from csvutil import records_to_csv
|
||||
@ -37,8 +39,8 @@ def write_diff_to_csv(repo_path: str, output_path: str, commit_1_id: str, commit
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="determines the updated, added, and deleted properties from the " +
|
||||
"'.properties-MERGED' files and generates a csv file containing " +
|
||||
parser = argparse.ArgumentParser(description="determines the updated, added, and deleted properties from the "
|
||||
"'.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.')
|
||||
@ -46,18 +48,18 @@ def main():
|
||||
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('-fc', '--first-commit', dest='commit_1_id', type=str, required=False,
|
||||
help='The commit for previous release. This flag or the language flag need to be specified' +
|
||||
help='The commit for previous release. This flag or the language flag need to be specified'
|
||||
' in order to determine a start point for the difference.')
|
||||
parser.add_argument('-lc', '--latest-commit', dest='commit_2_id', type=str, default='HEAD', required=False,
|
||||
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('-l', '--language', dest='language', type=str, default='HEAD', required=False,
|
||||
help='Specify the language in order to determine the first commit to use (i.e. \'ja\' for ' +
|
||||
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.')
|
||||
|
||||
args = parser.parse_args()
|
||||
repo_path = args.repo_path if args.repo_path is not None else str(pathlib.Path(__file__).parent.absolute())
|
||||
repo_path = args.repo_path if args.repo_path is not None else get_proj_dir()
|
||||
output_path = args.output_path
|
||||
commit_1_id = args.commit_1_id
|
||||
if args.language is not None:
|
||||
|
17
release_scripts/localization_scripts/envutil.py
Normal file
17
release_scripts/localization_scripts/envutil.py
Normal file
@ -0,0 +1,17 @@
|
||||
"""Functions relating to the project environment.
|
||||
"""
|
||||
|
||||
import pathlib
|
||||
from typing import Union
|
||||
|
||||
|
||||
def get_proj_dir(path: Union[pathlib.PurePath, str] = __file__) -> str:
|
||||
"""
|
||||
Gets parent directory of this file (and subsequently, the project).
|
||||
Args:
|
||||
path: Can be overridden to provide a different file. This will return the parent of that file in that instance.
|
||||
|
||||
Returns:
|
||||
The project folder or the parent folder of the file provided.
|
||||
"""
|
||||
return str(pathlib.Path(path).parent.absolute())
|
@ -1,3 +1,6 @@
|
||||
"""Functions relating to using git and GitPython with an existing repo.
|
||||
"""
|
||||
|
||||
from git import Repo, Diff, Blob
|
||||
from typing import List, Union, Iterator, Tuple, Any
|
||||
from itemchange import ItemChange, get_changed
|
||||
|
@ -1,27 +1,35 @@
|
||||
"""Functions handling retrieving and storing when a language was last updated.
|
||||
"""
|
||||
|
||||
from typing import Union
|
||||
from propsutil import get_entry_dict
|
||||
import pathlib
|
||||
from envutil import get_proj_dir
|
||||
from propsutil import get_entry_dict_from_path, update_entry_dict
|
||||
from os import path
|
||||
|
||||
|
||||
LANG_FILENAME = 'lastupdated.properties'
|
||||
|
||||
def get_last_update_key(language: str) -> str:
|
||||
return "bundles.{lang}.lastupdated".format({lang=language})
|
||||
|
||||
def _get_last_update_key(language: str) -> str:
|
||||
return "bundles.{lang}.lastupdated".format(lang=language)
|
||||
|
||||
|
||||
def _get_props_path():
|
||||
return path.join(get_proj_dir(), LANG_FILENAME)
|
||||
|
||||
|
||||
def get_commit_for_language(language: str) -> Union[str, None]:
|
||||
this_path = path.join(get_props_file_path(), LANG_FILENAME)
|
||||
lang_dict = get_entry_dict_from_path(_get_props_path())
|
||||
if lang_dict is None:
|
||||
return None
|
||||
|
||||
if path.isfile(this_path):
|
||||
lang_dict = get_entry_dict(this_path)
|
||||
key = get_last_update_key(language)
|
||||
if key in lang_dict:
|
||||
return lang_dict[key]
|
||||
key = _get_last_update_key(language)
|
||||
if key not in lang_dict:
|
||||
return None
|
||||
|
||||
return lang_dict[key]
|
||||
|
||||
return None
|
||||
|
||||
def set_commit_for_language(language: str, latest_commit: str):
|
||||
pass
|
||||
|
||||
def get_props_file_path() -> str:
|
||||
return str(pathlib.Path(__file__).parent.absolute())
|
||||
key = _get_last_update_key(language)
|
||||
update_entry_dict({key: latest_commit}, _get_props_path())
|
||||
|
@ -37,6 +37,23 @@ def get_entry_dict(file_contents: Union[str, IO]) -> Dict[str, str]:
|
||||
return props.properties
|
||||
|
||||
|
||||
def get_entry_dict_from_path(props_path: str) -> Union[Dict[str, str], None]:
|
||||
"""
|
||||
Retrieves a dictionary mapping the properties represented in the string or None if no properties file can be found
|
||||
at that path.
|
||||
Args:
|
||||
props_path: The path to the properties file.
|
||||
|
||||
Returns: The entry dictionary for that properties file.
|
||||
|
||||
"""
|
||||
if os.path.isfile(props_path):
|
||||
with open(props_path, "rb") as f:
|
||||
return get_entry_dict(f)
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
def set_entry_dict(contents: Dict[str, str], file_path: str):
|
||||
"""Sets the property file to the key-value pairs of the contents dictionary.
|
||||
|
||||
|
@ -6,12 +6,12 @@ from typing import List, Dict, Tuple, Callable, Iterator
|
||||
import sys
|
||||
import os
|
||||
|
||||
from envutil import get_proj_dir
|
||||
from langpropsutil import set_commit_for_language
|
||||
from propsutil import set_entry_dict, get_entry_dict, get_lang_bundle_name
|
||||
from csvutil import csv_to_records
|
||||
from propentry import PropEntry
|
||||
import argparse
|
||||
import pathlib
|
||||
|
||||
|
||||
def write_prop_entries(entries: Iterator[PropEntry], repo_path: str):
|
||||
@ -42,10 +42,8 @@ def update_prop_entries(entries: Iterator[PropEntry], repo_path: str):
|
||||
for rel_path, (entries, to_delete) in items_by_file.items():
|
||||
abs_path = os.path.join(repo_path, rel_path)
|
||||
|
||||
if os.path.isfile(abs_path):
|
||||
with open(abs_path, "rb") as f:
|
||||
prop_items = get_entry_dict(f)
|
||||
else:
|
||||
prop_items = get_entry_dict(abs_path)
|
||||
if prop_items is None:
|
||||
prop_items = {}
|
||||
|
||||
for key_to_delete in to_delete:
|
||||
@ -184,9 +182,14 @@ def get_new_rel_path(orig_path: str, new_filename: str) -> str:
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description='Updates properties files in the autopsy git repo.')
|
||||
parser = argparse.ArgumentParser(description='Updates properties files in the autopsy git repo.',
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
||||
|
||||
parser.add_argument(dest='csv_file', type=str, help='The path to the csv file.')
|
||||
parser.add_argument(dest='csv_file', type=str, help='The path to the csv file. The default format for the csv '
|
||||
'file has columns of relative path, properties file key, '
|
||||
'properties file value, and commit id for how recent these '
|
||||
'updates are. A header row is expected by default and the '
|
||||
'commit id, if specified, should only be in the first row.')
|
||||
|
||||
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.')
|
||||
@ -197,26 +200,26 @@ def main():
|
||||
parser.add_argument('-v', '--value-idx', dest='value_idx', action='store', type=int, default=2, required=False,
|
||||
help='The column index in the csv file providing the value within the properties file.')
|
||||
parser.add_argument('-d', '--should-delete-idx', dest='should_delete_idx', action='store', type=int, default=None,
|
||||
required=False, help='The column index in the csv file providing whether or not the file ' +
|
||||
required=False, help='The column index in the csv file providing whether or not the file '
|
||||
'should be deleted. Any non-blank content will be treated as True.')
|
||||
parser.add_argument('-c', '--commit-idx', dest='latest_commit_idx', action='store', type=int, default=3,
|
||||
required=False, help='The column index in the csv file providing the commit for which this ' +
|
||||
required=False, help='The column index in the csv file providing the commit for which this '
|
||||
'update applies. The commit should be located in the header row. ')
|
||||
parser.add_argument('-f', '--file-rename', dest='file_rename', action='store', type=str, default=None,
|
||||
required=False, help='If specified, the properties file will be renamed to the argument' +
|
||||
required=False, help='If specified, the properties file will be renamed to the argument'
|
||||
' preserving the specified relative path.')
|
||||
parser.add_argument('-z', '--has-no-header', dest='has_no_header', action='store_true', default=False,
|
||||
required=False, help='Specify whether or not there is a header within the csv file.')
|
||||
parser.add_argument('-o', '--should-overwrite', dest='should_overwrite', action='store_true', default=False,
|
||||
required=False, help="Whether or not to overwrite the previously existing properties files" +
|
||||
required=False, help="Whether or not to overwrite the previously existing properties files"
|
||||
" ignoring previously existing values.")
|
||||
parser.add_argument('-l', '--language', dest='language', type=str, default='HEAD', required=False,
|
||||
help='Specify the language in order to update the last updated properties file and rename ' +
|
||||
help='Specify the language in order to update the last updated properties file and rename '
|
||||
'files within directories. This flag overrides the file-rename flag.')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
repo_path = args.repo_path if args.repo_path is not None else str(pathlib.Path(__file__).parent.absolute())
|
||||
repo_path = args.repo_path if args.repo_path is not None else get_proj_dir()
|
||||
input_path = args.csv_file
|
||||
path_idx = args.path_idx
|
||||
key_idx = args.key_idx
|
||||
|
Loading…
x
Reference in New Issue
Block a user