# Egaia -- ethnographic archives toolkit
# Copyright 2015-2017 Eric Thrift
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
"""Main dispatching module for the command-line interface."""
import sys
import importlib
import pkgutil
from docopt import docopt
import egaia_root
import version
[docs]def tracefunc(frame, event, arg, indent=[0]):
"""Trace function calls, for debugging purposes."""
# see https://stackoverflow.com/a/8315566
if event == "call":
indent[0] += 2
print "-" * indent[0] + "> call function", frame.f_code.co_name
return tracefunc
def _cli():
"""egaia
Egaia provides a set of command-line archival processing tools designed to
help professional anthropologists and others with the management of
ethnographic records.
Usage:
egaia --help
egaia --version
egaia [ --debug ] COMMAND [ ARGS... ]
Options:
--help show this help text and exit
--version show the version number of this program
--debug print trace information
COMMAND a sub-command (see below)
ARGS arguments to the sub-command
Type ``egaia COMMAND --help`` for usage details on any command.
For full instructions see the README file and tutorial that accompany this
program, or view documentation online at <http://mcdrc.org/egaia/html/>.
"""
args = docopt(_cli.__doc__,
version=version.get_version(pep440=False),
options_first=True)
if args['--debug']:
sys.settrace(tracefunc)
if args['COMMAND']:
try:
cmd = importlib.import_module('egaia.egaia_%s' % args['COMMAND'])
except:
exit("%r is not a recognized command. See 'egaia --help'." % args['COMMAND'])
# Reset the arguments dict to use the subcommand help string
# Note this does not allow for global arguments
args = docopt(cmd._cli.__doc__)
cmd._cli(args)
if __name__ == '__main__':
_cli()