From e5bab5b12db37f4ad6ec45f310707490e00bf32b Mon Sep 17 00:00:00 2001 From: Harrison Date: Fri, 21 Apr 2023 13:51:12 -0500 Subject: [PATCH] Fixed packaging --- csvbyname/cli.py | 84 ++++++++++++++++++++++++ csvbyname/{csvbyname.py => generate.py} | 85 +------------------------ setup.cfg | 3 +- 3 files changed, 89 insertions(+), 83 deletions(-) create mode 100644 csvbyname/cli.py rename csvbyname/{csvbyname.py => generate.py} (59%) diff --git a/csvbyname/cli.py b/csvbyname/cli.py new file mode 100644 index 0000000..4a815f5 --- /dev/null +++ b/csvbyname/cli.py @@ -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() diff --git a/csvbyname/csvbyname.py b/csvbyname/generate.py similarity index 59% rename from csvbyname/csvbyname.py rename to csvbyname/generate.py index 4aa6163..6be5eb9 100644 --- a/csvbyname/csvbyname.py +++ b/csvbyname/generate.py @@ -1,11 +1,12 @@ -import argparse import csv import os import re from typing import Iterable -import exceptions +from csvbyname import exceptions import logging +logger = logging.getLogger(__name__) + def matcher(full_path: str, use_full_path: bool, regex_groups: list[str]): 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() diff --git a/setup.cfg b/setup.cfg index af3c8f6..817cd26 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,10 +1,11 @@ [metadata] name = csvbyname version = 0.0.2 +author = Harrison [options] packages = csvbyname [options.entry_points] console_scripts = - csvbyname = csvbyname.csvbyname:main \ No newline at end of file + csvbyname = csvbyname.cli:main \ No newline at end of file