diff --git a/csvbyname/csvbyname.py b/csvbyname/csvbyname.py new file mode 100644 index 0000000..3938256 --- /dev/null +++ b/csvbyname/csvbyname.py @@ -0,0 +1,78 @@ +import argparse + + +def collect_files( + path: str, + include_folders: bool, + entire_path: bool, + recursive: bool, + regex_groups: list[str], +): + # TODO Finish collecting all files + pass + + +def write_collected_to_csv(output_path: str, collected: dict[str, dict[str, str]]): + # TODO Finish writing collected files/paths to CSV. + pass + + +def run(args): + collect_files( + args.directory, + args.include_folders, + args.entire_path, + args.recursive, + args.add_regex_property, + ) + + +def main(): + argparser = argparse.ArgumentParser( + "csvbyname", + description="Catalogue a directory of files by patterns in their names into a " + "CSV.", + ) + argparser.add_argument( + "directory", + type=str, + help="The directory containing the files to obtain catalogue names of", + metavar="i", + ) + argparser.add_argument( + "output", type=str, help="The path to the catalogued CSVs.", metavar="o" + ) + argparser.add_argument( + "-l", + "--include-folder", + help="Include folders in the cataloguing process", + action="store_true", + required=False, + default=False, + ) + argparser.add_argument( + "-e", + "--entire-path", + help="Include the full path when applying the groupings to find properties", + action="store_true", + required=False, + default=False, + ) + argparser.add_argument( + "-r", + "--recursive", + help="Catalogue recursively", + action="store_true", + required=False, + default=False, + ) + argparser.add_argument( + "-p", + "--add-regex-property", + help="Add a property in the resulting CSV obtained from the first capture " + "group of the given REGEX in the following format:\n property-name:regex", + nargs="+", + ) + + args = argparser.parse_args() + run(args) diff --git a/environment.yaml b/environment.yaml new file mode 100644 index 0000000..2a6a99a --- /dev/null +++ b/environment.yaml @@ -0,0 +1,37 @@ +name: /home/ydeng/csvbyname/env +channels: + - conda-forge +dependencies: + - _libgcc_mutex=0.1=conda_forge + - _openmp_mutex=4.5=2_gnu + - black=23.3.0=py311h38be061_0 + - bzip2=1.0.8=h7f98852_4 + - ca-certificates=2022.12.7=ha878542_0 + - click=8.1.3=unix_pyhd8ed1ab_2 + - ld_impl_linux-64=2.40=h41732ed_0 + - libexpat=2.5.0=hcb278e6_1 + - libffi=3.4.2=h7f98852_5 + - libgcc-ng=12.2.0=h65d4601_19 + - libgomp=12.2.0=h65d4601_19 + - libnsl=2.0.0=h7f98852_0 + - libsqlite=3.40.0=h753d276_0 + - libuuid=2.38.1=h0b41bf4_0 + - libzlib=1.2.13=h166bdaf_4 + - mypy_extensions=1.0.0=pyha770c72_0 + - ncurses=6.3=h27087fc_1 + - openssl=3.1.0=h0b41bf4_0 + - packaging=23.1=pyhd8ed1ab_0 + - pathspec=0.11.1=pyhd8ed1ab_0 + - pip=23.1=pyhd8ed1ab_0 + - platformdirs=3.2.0=pyhd8ed1ab_0 + - python=3.11.3=h2755cc3_0_cpython + - python_abi=3.11=3_cp311 + - readline=8.2=h8228510_1 + - setuptools=67.6.1=pyhd8ed1ab_0 + - tk=8.6.12=h27826a3_0 + - typing-extensions=4.5.0=hd8ed1ab_0 + - typing_extensions=4.5.0=pyha770c72_0 + - tzdata=2023c=h71feb2d_0 + - wheel=0.40.0=pyhd8ed1ab_0 + - xz=5.2.6=h166bdaf_0 +prefix: /home/ydeng/csvbyname/env diff --git a/tests/resources/foo.txt b/tests/resources/foo.txt new file mode 100644 index 0000000..4add785 --- /dev/null +++ b/tests/resources/foo.txt @@ -0,0 +1 @@ +Text \ No newline at end of file diff --git a/tests/resources/group1-a-11.txt b/tests/resources/group1-a-11.txt new file mode 100644 index 0000000..4add785 --- /dev/null +++ b/tests/resources/group1-a-11.txt @@ -0,0 +1 @@ +Text \ No newline at end of file diff --git a/tests/resources/group1-a-12.txt b/tests/resources/group1-a-12.txt new file mode 100644 index 0000000..71a4e5b --- /dev/null +++ b/tests/resources/group1-a-12.txt @@ -0,0 +1,2 @@ + +Text \ No newline at end of file diff --git a/tests/resources/group1-a-13.txt b/tests/resources/group1-a-13.txt new file mode 100644 index 0000000..4add785 --- /dev/null +++ b/tests/resources/group1-a-13.txt @@ -0,0 +1 @@ +Text \ No newline at end of file diff --git a/tests/resources/group1-b-10.txt b/tests/resources/group1-b-10.txt new file mode 100644 index 0000000..4add785 --- /dev/null +++ b/tests/resources/group1-b-10.txt @@ -0,0 +1 @@ +Text \ No newline at end of file diff --git a/tests/resources/group1-b-11.txt b/tests/resources/group1-b-11.txt new file mode 100644 index 0000000..4add785 --- /dev/null +++ b/tests/resources/group1-b-11.txt @@ -0,0 +1 @@ +Text \ No newline at end of file diff --git a/tests/resources/group1-b-9.txt b/tests/resources/group1-b-9.txt new file mode 100644 index 0000000..4add785 --- /dev/null +++ b/tests/resources/group1-b-9.txt @@ -0,0 +1 @@ +Text \ No newline at end of file