Skip to content
This repository has been archived by the owner on Jul 11, 2024. It is now read-only.

Commit

Permalink
env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
deadc0de6 committed Jan 31, 2024
1 parent eb0a628 commit 1f1ea8d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ Five different types of entry are present in a catalog:
* **file node**: this is a file
* **archive node**: this is a file contained in an archive (tar, zip, etc)

Following environment variables are supported:

* `CATCLI_CATALOG_PATH`: define the catalog path (`--catalog=<path>`)
* `CATCLI_NO_BANNER`: disable the banner (`--no-banner`)
* `CATCLI_VERBOSE`: enable verbose mode (`--verbose`)
* `CATCLI_FORMAT`: define the output format (`-F --format=<fmt>`)

## Index data

Let's say the DVD or external hard drive that needs to be indexed
Expand Down
32 changes: 23 additions & 9 deletions catcli/catcli.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,21 @@

NAME = 'catcli'
CUR = os.path.dirname(os.path.abspath(__file__))
CATALOGPATH = os.getenv('CATCLI_CATALOG_PATH', f'{NAME}.catalog')
GRAPHPATH = f'/tmp/{NAME}.dot'
FORMATS = ['native', 'csv', 'csv-with-header', 'fzf-native', 'fzf-csv']

# env variables
ENV_CATALOG_PATH = 'CATCLI_CATALOG_PATH'
ENV_NOBANNER = 'CATCLI_NO_BANNER'
ENV_VERBOSE = 'CATCLI_VERBOSE'
ENV_FORMAT = 'CATCLI_FORMAT'

# default paths
DEFAULT_CATALOGPATH = os.getenv(ENV_CATALOG_PATH, default=f'{NAME}.catalog')
DEFAULT_GRAPHPATH = f'/tmp/{NAME}.dot'
DEFAULT_NOBANNER = os.getenv(ENV_NOBANNER) is not None
DEFAULT_VERBOSEMODE = os.getenv(ENV_VERBOSE) is not None
DEFAULT_FORMAT = os.getenv(ENV_FORMAT, default='native')

BANNER = f""" +-+-+-+-+-+-+
|c|a|t|c|l|i|
+-+-+-+-+-+-+ v{VERSION}"""
Expand Down Expand Up @@ -64,22 +75,22 @@
{NAME} --version
Options:
--catalog=<path> Path to the catalog [default: {CATALOGPATH}].
--catalog=<path> Path to the catalog [default: {DEFAULT_CATALOGPATH}].
--meta=<meta> Additional attribute to store [default: ].
-a --archive Handle archive file [default: False].
-B --no-banner Do not display the banner [default: False].
-B --no-banner Do not display the banner [default: {str(DEFAULT_NOBANNER)}].
-b --script Output script to manage found file(s) [default: False].
-C --no-color Do not output colors [default: False].
-c --hash Calculate md5 hash [default: False].
-d --directory Only directory [default: False].
-F --format=<fmt> see \"print_supported_formats\" [default: native].
-F --format=<fmt> see \"print_supported_formats\" [default: {DEFAULT_FORMAT}].
-f --force Do not ask when updating the catalog [default: False].
-l --lpath=<path> Path where changes are logged [default: ]
-p --path=<path> Start path.
-r --recursive Recursive [default: False].
-s --raw-size Print raw size [default: False].
-S --sortsize Sort by size, largest first [default: False].
-V --verbose Be verbose [default: False].
-V --verbose Be verbose [default: {str(DEFAULT_VERBOSEMODE)}].
-v --version Show version.
-h --help Show this screen.
""" # nopep8
Expand Down Expand Up @@ -126,6 +137,8 @@ def cmd_index(args: Dict[str, Any],
node.parent = None

start = datetime.datetime.now()
if debug:
Logger.debug('debug mode enabled')
walker = Walker(noder, usehash=usehash, debug=debug)
attr = args['--meta']
root = noder.new_storage_node(name, path, top, attr)
Expand Down Expand Up @@ -244,7 +257,7 @@ def cmd_graph(args: Dict[str, Any],
"""graph action"""
path = args['<path>']
if not path:
path = GRAPHPATH
path = DEFAULT_GRAPHPATH
cmd = noder.to_dot(top, path)
Logger.info(f'create graph with \"{cmd}\" (you need graphviz)')

Expand Down Expand Up @@ -403,11 +416,12 @@ def init(argv: List[str]) -> Tuple[Dict[str, Any],
print_supported_formats()
sys.exit(0)

if args['--verbose']:
if args['--verbose'] or DEFAULT_VERBOSEMODE:
print('verbose mode enabled')
print(f'args: {args}')

# print banner
if not args['--no-banner']:
if not args['--no-banner'] and DEFAULT_NOBANNER:
banner()

# set colors
Expand Down

0 comments on commit 1f1ea8d

Please sign in to comment.