<s> """<STR_LIT>""" <EOL> __docformat__ = '<STR_LIT>' <EOL> import argparse <EOL> import logging <EOL> import sys <EOL> import os <EOL> import textwrap <EOL> import datalad <EOL> from datalad . log import lgr <EOL> from datalad . cmdline import helpers <EOL> from . . utils import setup_exceptionhook , chpwd <EOL> from . . dochelpers import exc_str <EOL> def _license_info ( ) : <EOL> return """<STR_LIT>""" <EOL> def setup_parser ( ) : <EOL> from . . interface . base import dedent_docstring , get_interface_groups <EOL> parser = argparse . ArgumentParser ( <EOL> fromfile_prefix_chars = '<STR_LIT:@>' , <EOL> description = dedent_docstring ( """<STR_LIT>""" ) , <EOL> epilog = '<STR_LIT>' , <EOL> formatter_class = argparse . RawDescriptionHelpFormatter , <EOL> add_help = False ) <EOL> helpers . parser_add_common_opt ( parser , '<STR_LIT>' ) <EOL> helpers . parser_add_common_opt ( parser , '<STR_LIT>' ) <EOL> helpers . parser_add_common_opt ( parser , '<STR_LIT>' ) <EOL> helpers . parser_add_common_opt ( <EOL> parser , <EOL> '<STR_LIT:version>' , <EOL> version = '<STR_LIT>' % ( datalad . __version__ , _license_info ( ) ) ) <EOL> if __debug__ : <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , action = '<STR_LIT:store_true>' , dest = '<STR_LIT>' , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , action = '<STR_LIT>' , dest = '<STR_LIT>' , metavar = '<STR_LIT>' , <EOL> help = """<STR_LIT>""" ) <EOL> subparsers = parser . add_subparsers ( ) <EOL> grp_short_descriptions = [ ] <EOL> interface_groups = get_interface_groups ( ) <EOL> for grp_name , grp_descr , _interfaces in interface_groups : <EOL> cmd_short_descriptions = [ ] <EOL> for _intfcls in _interfaces : <EOL> _intf = _intfcls ( cmdline = True ) <EOL> cmd_name = _intf . __module__ . split ( '<STR_LIT:.>' ) [ - <NUM_LIT:1> ] . replace ( '<STR_LIT:_>' , '<STR_LIT:->' ) <EOL> if hasattr ( _intf , '<STR_LIT>' ) : <EOL> parser_args = _intf . parser_args <EOL> else : <EOL> parser_args = dict ( formatter_class = argparse . RawDescriptionHelpFormatter ) <EOL> parser_args [ '<STR_LIT:description>' ] = dedent_docstring ( _intf . __doc__ ) <EOL> subparser = subparsers . add_parser ( cmd_name , add_help = False , ** parser_args ) <EOL> helpers . parser_add_common_opt ( <EOL> subparser , '<STR_LIT:version>' , <EOL> version = '<STR_LIT>' % ( cmd_name , datalad . __version__ , <EOL> _license_info ( ) ) ) <EOL> helpers . parser_add_common_opt ( subparser , '<STR_LIT>' ) <EOL> helpers . parser_add_common_opt ( subparser , '<STR_LIT>' ) <EOL> helpers . parser_add_common_opt ( subparser , '<STR_LIT>' ) <EOL> _intf . setup_parser ( subparser ) <EOL> subparser . set_defaults ( func = _intf . call_from_parser , <EOL> logger = logging . getLogger ( _intf . __module__ ) ) <EOL> sdescr = getattr ( _intf , '<STR_LIT>' , <EOL> parser_args [ '<STR_LIT:description>' ] . split ( '<STR_LIT:\n>' ) [ <NUM_LIT:0> ] ) <EOL> cmd_short_descriptions . append ( ( cmd_name , sdescr ) ) <EOL> grp_short_descriptions . append ( cmd_short_descriptions ) <EOL> cmd_summary = [ ] <EOL> for i , grp in enumerate ( interface_groups ) : <EOL> grp_descr = grp [ <NUM_LIT:1> ] <EOL> grp_cmds = grp_short_descriptions [ i ] <EOL> cmd_summary . append ( '<STR_LIT>' % ( grp_descr , ) ) <EOL> for cd in grp_cmds : <EOL> cmd_summary . append ( '<STR_LIT>' <EOL> % ( cd [ <NUM_LIT:0> ] , <EOL> textwrap . fill ( <EOL> cd [ <NUM_LIT:1> ] . rstrip ( '<STR_LIT>' ) , <EOL> <NUM_LIT> , <EOL> subsequent_indent = '<STR_LIT:U+0020>' * <NUM_LIT:8> ) ) ) <EOL> cmd_summary . append ( '<STR_LIT>' ) <EOL> parser . description = '<STR_LIT>' % ( parser . description , <EOL> '<STR_LIT:\n>' . join ( cmd_summary ) , <EOL> textwrap . fill ( dedent_docstring ( """<STR_LIT>""" ) , <EOL> <NUM_LIT> , initial_indent = '<STR_LIT>' , subsequent_indent = '<STR_LIT>' ) ) <EOL> return parser <EOL> def main ( args = None ) : <EOL> parser = setup_parser ( ) <EOL> try : <EOL> import argcomplete <EOL> argcomplete . autocomplete ( parser ) <EOL> except ImportError : <EOL> pass <EOL> cmdlineargs = parser . parse_args ( args ) <EOL> if not cmdlineargs . change_path is None : <EOL> for path in cmdlineargs . change_path : <EOL> chpwd ( path ) <EOL> if cmdlineargs . pbs_runner : <EOL> from . helpers import run_via_pbs <EOL> from . helpers import strip_arg_from_argv <EOL> from . common_args import pbs_runner as pbs_runner_opt <EOL> args_ = strip_arg_from_argv ( args or sys . argv , cmdlineargs . pbs_runner , pbs_runner_opt [ <NUM_LIT:1> ] ) <EOL> run_via_pbs ( args_ , cmdlineargs . pbs_runner ) <EOL> elif cmdlineargs . common_debug : <EOL> setup_exceptionhook ( ) <EOL> cmdlineargs . func ( cmdlineargs ) <EOL> else : <EOL> try : <EOL> cmdlineargs . func ( cmdlineargs ) <EOL> except Exception as exc : <EOL> lgr . error ( '<STR_LIT>' % ( exc_str ( exc ) , exc . __class__ . __name__ ) ) <EOL> sys . exit ( <NUM_LIT:1> ) </s>
