Compare commits
No commits in common. "c579c172ef4127271053403be0fb128329b9d24d" and "73ae49cb89ae081351ed1907d6d3d1032debc094" have entirely different histories.
c579c172ef
...
73ae49cb89
@ -1,84 +0,0 @@
|
||||
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()
|
@ -1,12 +1,11 @@
|
||||
import argparse
|
||||
import csv
|
||||
import os
|
||||
import re
|
||||
from typing import Iterable
|
||||
from csvbyname import exceptions
|
||||
import exceptions
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def matcher(full_path: str, use_full_path: bool, regex_groups: list[str]):
|
||||
captured_properties = {}
|
||||
@ -89,3 +88,83 @@ 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()
|
Loading…
x
Reference in New Issue
Block a user