Fixed packaging
Some checks failed
ydeng/csvbyname/pipeline/head There was a failure building this commit

This commit is contained in:
Harrison Deng 2023-04-21 13:51:12 -05:00
parent 73ae49cb89
commit e5bab5b12d
3 changed files with 89 additions and 83 deletions

84
csvbyname/cli.py Normal file
View File

@ -0,0 +1,84 @@
import argparse
import logging
from csvbyname.generate import collect_files, write_collected_to_csv
def run(args):
logger.info('Collecting files from "%s"', args.directory)
collected, pkeys = collect_files(
args.directory,
args.include_folders,
args.entire_path,
args.recursive,
args.add_re_property,
)
write_collected_to_csv(args.output, collected, pkeys)
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-folders",
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-re-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.\n"
"Alternatively, use named REGEX groups.",
nargs="+",
type=str,
)
argparser.add_argument(
"-V",
"--verbosity",
help="Set the verbosity of the logging",
type=str,
required=False,
default="INFO",
)
args = argparser.parse_args()
logging.basicConfig(level=args.verbosity.upper())
global logger
logger = logging.getLogger(__name__)
run(args)
if __name__ == "__main__":
main()

View File

@ -1,11 +1,12 @@
import argparse
import csv import csv
import os import os
import re import re
from typing import Iterable from typing import Iterable
import exceptions from csvbyname import exceptions
import logging import logging
logger = logging.getLogger(__name__)
def matcher(full_path: str, use_full_path: bool, regex_groups: list[str]): def matcher(full_path: str, use_full_path: bool, regex_groups: list[str]):
captured_properties = {} captured_properties = {}
@ -88,83 +89,3 @@ def write_collected_to_csv(
), ),
] ]
) )
def run(args):
logger.info('Collecting files from "%s"', args.directory)
collected, pkeys = collect_files(
args.directory,
args.include_folders,
args.entire_path,
args.recursive,
args.add_re_property,
)
write_collected_to_csv(args.output, collected, pkeys)
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-folders",
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-re-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.\n"
"Alternatively, use named REGEX groups.",
nargs="+",
type=str,
)
argparser.add_argument(
"-V",
"--verbosity",
help="Set the verbosity of the logging",
type=str,
required=False,
default="INFO",
)
args = argparser.parse_args()
logging.basicConfig(level=args.verbosity.upper())
global logger
logger = logging.getLogger(__name__)
run(args)
if __name__ == "__main__":
main()

View File

@ -1,10 +1,11 @@
[metadata] [metadata]
name = csvbyname name = csvbyname
version = 0.0.2 version = 0.0.2
author = Harrison
[options] [options]
packages = csvbyname packages = csvbyname
[options.entry_points] [options.entry_points]
console_scripts = console_scripts =
csvbyname = csvbyname.csvbyname:main csvbyname = csvbyname.cli:main