Added some CLI arguments and program structure
This commit is contained in:
parent
a338f78d07
commit
f09e0d27fd
78
csvbyname/csvbyname.py
Normal file
78
csvbyname/csvbyname.py
Normal file
@ -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)
|
37
environment.yaml
Normal file
37
environment.yaml
Normal file
@ -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
|
1
tests/resources/foo.txt
Normal file
1
tests/resources/foo.txt
Normal file
@ -0,0 +1 @@
|
||||
Text
|
1
tests/resources/group1-a-11.txt
Normal file
1
tests/resources/group1-a-11.txt
Normal file
@ -0,0 +1 @@
|
||||
Text
|
2
tests/resources/group1-a-12.txt
Normal file
2
tests/resources/group1-a-12.txt
Normal file
@ -0,0 +1,2 @@
|
||||
|
||||
Text
|
1
tests/resources/group1-a-13.txt
Normal file
1
tests/resources/group1-a-13.txt
Normal file
@ -0,0 +1 @@
|
||||
Text
|
1
tests/resources/group1-b-10.txt
Normal file
1
tests/resources/group1-b-10.txt
Normal file
@ -0,0 +1 @@
|
||||
Text
|
1
tests/resources/group1-b-11.txt
Normal file
1
tests/resources/group1-b-11.txt
Normal file
@ -0,0 +1 @@
|
||||
Text
|
1
tests/resources/group1-b-9.txt
Normal file
1
tests/resources/group1-b-9.txt
Normal file
@ -0,0 +1 @@
|
||||
Text
|
Loading…
x
Reference in New Issue
Block a user