Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Ronny Eichler
dataman
Commits
56e0a251
Commit
56e0a251
authored
Aug 22, 2015
by
Ronny Eichler
Browse files
Basic command line handling
parent
bf277389
Changes
1
Hide whitespace changes
Inline
Side-by-side
dataman/dataman.py
View file @
56e0a251
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# ? is short for builtin help
# ! allows shelling out
from
__future__
import
print_function
import
sys
import
cmd
import
tools
import
logging
from
constants
import
LOG_LEVEL_VERBOSE
__version__
=
0.01
NO_EXIT_CONFIRMATION
=
True
LOG_LEVEL
=
logging
.
INFO
class
DataMan
(
cmd
.
Cmd
):
"""Command line tool for quick data documentation."""
...
...
@@ -22,9 +28,9 @@ class DataMan(cmd.Cmd):
Simple user greeting. When used in combination with a parameter, will
respond with personalized greeting. Yay."""
if
user
:
print
"hello "
,
user
print
(
"hello "
,
user
)
else
:
print
"hi there!"
print
(
"hi there!"
)
def
do_stats
(
self
,
path
):
if
not
len
(
path
):
...
...
@@ -37,11 +43,39 @@ class DataMan(cmd.Cmd):
return
True
def
postloop
(
self
):
print
"Done."
print
(
"Done."
)
if
__name__
==
"__main__"
:
if
len
(
sys
.
argv
)
>
1
:
DataMan
().
onecmd
(
' '
.
join
(
sys
.
argv
[
1
:]))
else
:
# Command line parsing
import
argparse
parser
=
argparse
.
ArgumentParser
(
prog
=
"DataMan"
)
parser
.
add_argument
(
'-d'
,
'--debug'
,
action
=
'store_true'
,
help
=
'Debug mode -- verbose output, no confirmations.'
)
parser
.
add_argument
(
'--version'
,
action
=
'version'
,
version
=
'%(prog)s {version}'
.
format
(
version
=
__version__
))
# sub-parsers
subparsers
=
parser
.
add_subparsers
(
help
=
'sub commands'
,
dest
=
'command'
)
parser_cli
=
subparsers
.
add_parser
(
'cli'
,
help
=
'Interactive CLI session'
)
parser_stats
=
subparsers
.
add_parser
(
'stats'
,
help
=
'Directory statistics'
)
parser_stats
.
add_argument
(
'path'
,
help
=
'Relative or absolute path to directory'
,
default
=
'.'
,
nargs
=
'?'
)
parser_proc
=
subparsers
.
add_parser
(
'proc'
,
help
=
'Data processing'
)
parser_doc
=
subparsers
.
add_parser
(
'doc'
,
help
=
'Data documentation'
)
parser_check
=
subparsers
.
add_parser
(
'check'
,
help
=
'Check/verify data and documentation integrity'
)
cli_args
=
parser
.
parse_args
()
if
cli_args
.
debug
:
NO_EXIT_CONFIRMATION
=
True
logging
.
addLevelName
(
LOG_LEVEL_VERBOSE
,
"VERBOSE"
)
logging
.
basicConfig
(
level
=
LOG_LEVEL_VERBOSE
if
cli_args
.
debug
else
LOG_LEVEL
,
format
=
'%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
log
=
logging
.
getLogger
(
__name__
)
if
cli_args
.
command
==
'cli'
:
DataMan
().
cmdloop
()
else
:
DataMan
().
onecmd
(
' '
.
join
(
sys
.
argv
[
1
:]))
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment