def getargs(args=None): from argparse import ArgumentParser P = ArgumentParser() P.add_argument('--user', action='store_true', default=os.geteuid() != 0, help='Consider user config') P.add_argument('--system', dest='user', action='store_false', help='Consider system config') P.add_argument('-v', '--verbose', action='count', default=0) SP = P.add_subparsers() S = SP.add_parser('status', help='List procServ instance state') S.set_defaults(func=status) S = SP.add_parser('list', help='List procServ instances') S.set_defaults(func=syslist) S = SP.add_parser('add', help='Create a new procServ instance') S.add_argument('-C', '--chdir', default=os.getcwd(), help='Run directory for instance') S.add_argument('-P', '--port', help='telnet port') S.add_argument('-U', '--user', dest='username') S.add_argument('-G', '--group') S.add_argument('-f', '--force', action='store_true', default=False) S.add_argument('-A', '--autostart', action='store_true', default=False, help='Automatically start after adding') S.add_argument('name', help='Instance name') S.add_argument('command', nargs='+', help='Command') S.set_defaults(func=addproc) S = SP.add_parser('remove', help='Remove a procServ instance') S.add_argument('-f', '--force', action='store_true', default=False) S.add_argument('name', help='Instance name') S.set_defaults(func=delproc) S = SP.add_parser('write-procs-cf', help='Write conserver config') S.add_argument('-f', '--out', default='/etc/conserver/procs.cf') S.add_argument('-R', '--reload', action='store_true', default=False) S.set_defaults(func=writeprocs) A = P.parse_args(args=args) if not hasattr(A, 'func'): P.print_help() sys.exit(1) return A
def getargs(): from argparse import ArgumentParser, REMAINDER P = ArgumentParser(description='CI core dump analyzer.'\ +' Run install prior to exec of suspect code.'\ +' Then report afterwards.'\ +' install and uninstall require root (eg. sudo).') P.add_argument('--outdir', default=os.path.join(tempfile.gettempdir(), 'cores'), help='Write backtraces to this directory') P.add_argument('-v', '--verbose', dest='level', default=logging.INFO, action='store_const', const=logging.DEBUG) plat = platform.system() _log.debug('platform %s', plat) if plat == 'Linux': from .linux import LinuxDumper as Dumper elif plat == 'Windows': from .windows import WindowsDumper as Dumper elif plat == 'Darwin': from .osx import DarwinDumper as Dumper else: Dumper = CommonDumper P.set_defaults(target=Dumper) SP = P.add_subparsers() CMD = SP.add_parser('install') CMD.add_argument('--gdb', dest='debugger') CMD.set_defaults(func=Dumper.install) CMD = SP.add_parser('uninstall') CMD.set_defaults(func=Dumper.uninstall) CMD = SP.add_parser('report') CMD.set_defaults(func=Dumper.report) CMD = SP.add_parser('exec') CMD.add_argument('command') CMD.add_argument('args', nargs=REMAINDER) CMD.set_defaults(func=Dumper.doexec) return P
def getargs(): from argparse import ArgumentParser P = ArgumentParser() P.add_argument('--user', action='store_true', default=os.geteuid()!=0, help='Consider user config') P.add_argument('--system', dest='user', action='store_false', help='Consider system config') P.add_argument('-v','--verbose', action='count', default=0) SP = P.add_subparsers() S = SP.add_parser('status', help='List procServ instance state') S.set_defaults(func=status) S = SP.add_parser('list', help='List procServ instances') S.set_defaults(func=syslist) S = SP.add_parser('add', help='Create a new procServ instance') S.add_argument('-C','--chdir', default=os.getcwd(), help='Run directory for instance') S.add_argument('-P','--port', help='telnet port') S.add_argument('-U','--user', dest='username') S.add_argument('-G','--group') S.add_argument('-f','--force', action='store_true', default=False) S.add_argument('-A','--autostart',action='store_true', default=False, help='Automatically start after adding') S.add_argument('name', help='Instance name') S.add_argument('command', nargs='+', help='Command') S.set_defaults(func=addproc) S = SP.add_parser('remove', help='Remove a procServ instance') S.add_argument('-f','--force', action='store_true', default=False) S.add_argument('name', help='Instance name') S.set_defaults(func=delproc) S = SP.add_parser('write-procs-cf', help='Write conserver config') S.add_argument('-f','--out',default='/etc/conserver/procs.cf') S.add_argument('-R','--reload', action='store_true', default=False) S.set_defaults(func=writeprocs) A = P.parse_args() if not hasattr(A, 'func'): P.print_help() sys.exit(1) return A
def parse_args(argv): """Parse arguments.""" parser = argparse.ArgumentParser( prog=argv[0], description="Big Local News Python Client", formatter_class=argparse.ArgumentDefaultsHelpFormatter, ) sub = parser.add_subparsers(help="commands", dest="command") upload = sub.add_parser( "upload", help="upload files to a project", formatter_class=argparse.ArgumentDefaultsHelpFormatter, ) if is_git(sys.argv[0]): upload.add_argument( "-p", "--project_id", help="project ID on Big Local News platform" "; if not specified, will use projectId in ~/.git/bln.json", ) else: # regular `bln` command upload.add_argument( "project_id", help="project ID on Big Local News platform", ) upload.add_argument( "files", nargs="+", help="list of files to upload", ) upload.add_argument( "-k", "--api_key", help="if not specified, looks for one at ~/.bln/api_key", ) upload.add_argument( "-t", "--tier", help='which tier; external parties will only be able to use "prod"', default="prod", ) return parser.parse_args(argv[1:])
def getargs(args=None): from argparse import ArgumentParser, REMAINDER P = ArgumentParser() P.add_argument('--user', action='store_true', default=os.geteuid() != 0, help='Consider user config') P.add_argument('--system', dest='user', action='store_false', help='Consider system config') P.add_argument('-v', '--verbose', action='count', default=0) SP = P.add_subparsers() S = SP.add_parser('status', help='Report state of procServ instances') S.set_defaults(func=status) S = SP.add_parser('list', help='List procServ instances') S.add_argument('--all', action='store_true', default=False) S.set_defaults(func=syslist) S = SP.add_parser('add', help='Create a new procServ instance') S.add_argument('-C', '--chdir', default=os.getcwd(), help='Run directory for instance') S.add_argument('-P', '--port', help='telnet port') S.add_argument('-U', '--user', dest='username') S.add_argument('-G', '--group') S.add_argument('-e', '--environment', action='append', help='Add an environment variable') S.add_argument('-E', '--env-file', help='Environment file path') S.add_argument('-f', '--force', action='store_true', default=False) S.add_argument('-A', '--autostart', action='store_true', default=False, help='Automatically start after adding') S.add_argument('name', help='Instance name') S.add_argument('command', help='Command') S.add_argument('args', nargs=REMAINDER) S.set_defaults(func=addproc) S = SP.add_parser('remove', help='Remove a procServ instance') S.add_argument('-f', '--force', action='store_true', default=False) S.add_argument('name', help='Instance name').completer = instances_completer S.set_defaults(func=delproc) S = SP.add_parser( 'rename', help='Rename a procServ instance. The instance will be stopped.') S.add_argument('-f', '--force', action='store_true', default=False) S.add_argument('-A', '--autostart', action='store_true', default=False, help='Automatically start after renaming') S.add_argument( 'name', help='Current instance name').completer = instances_completer S.add_argument('new_name', help='Desired instance name') S.set_defaults(func=renameproc) S = SP.add_parser('write-procs-cf', help='Write conserver config') S.add_argument('-f', '--out', default='/etc/conserver/procs.cf') S.add_argument('-R', '--reload', action='store_true', default=False) S.set_defaults(func=writeprocs) S = SP.add_parser('start', help='Start a procServ instance') S.add_argument('name', help='Instance name').completer = instances_completer S.set_defaults(func=startproc) S = SP.add_parser('stop', help='Stop a procServ instance') S.add_argument('name', help='Instance name').completer = instances_completer S.set_defaults(func=stopproc) S = SP.add_parser('restart', help='Restart a procServ instance') S.add_argument('name', help='Instance name').completer = instances_completer S.set_defaults(func=restartproc) S = SP.add_parser('logs', help='Open logs of a procServ instance') S.add_argument('-f', '--follow', action='store_true', default=False) S.add_argument('name', help='Instance name').completer = instances_completer S.set_defaults(func=showlogs) S = SP.add_parser('attach', help='Attach to a procServ instance') S.add_argument("name", help='Instance name').completer = instances_completer S.add_argument('extra', nargs=REMAINDER, help='extra args for telnet') S.set_defaults(func=attachproc) try: from argcomplete import autocomplete autocomplete(P) except ImportError: pass A = P.parse_args(args=args) if not hasattr(A, 'func'): P.print_help() sys.exit(1) return A
def prepare_parser(sp, cmd): name = cmd.get_name() parser = sp.add_parser(name) return parser
def getargs(args=None): from argparse import ArgumentParser, REMAINDER P = ArgumentParser() P.add_argument('--user', action='store_true', default=os.geteuid() != 0, help='Consider user config') P.add_argument('--system', dest='user', action='store_false', help='Consider system config') P.add_argument('-v', '--verbose', action='count', default=0) SP = P.add_subparsers() S = SP.add_parser('status', help='Report state of procServ instances') S.set_defaults(func=status) S = SP.add_parser('list', help='List procServ instances') S.add_argument('--all', action='store_true', default=False) S.set_defaults(func=syslist) S = SP.add_parser('add', help='Create a new procServ instance') S.add_argument('-C', '--chdir', default=os.getcwd(), help='Run directory for instance') S.add_argument('-P', '--port', help='telnet port') S.add_argument('-U', '--user', dest='username') S.add_argument('-G', '--group') S.add_argument('-e', '--environment', action='append', help='Add an environment variable') S.add_argument('-E', '--env-file', help='Environment file path') S.add_argument('-L', '--logfile', help='Write the console output to this file') S.add_argument('-f', '--force', action='store_true', default=False) S.add_argument('-A', '--autostart', action='store_true', default=False, help='Automatically start after adding') S.add_argument('name', help='Instance name') S.add_argument('command', help='Command') S.add_argument('args', nargs=REMAINDER) S.set_defaults(func=addproc) S = SP.add_parser('remove', help='Remove a procServ instance') S.add_argument('-f', '--force', action='store_true', default=False) S.add_argument('name', help='Instance name') S.set_defaults(func=delproc) S = SP.add_parser('write-procs-cf', help='Write conserver config') S.add_argument('-f', '--out', default='/etc/conserver/procs.cf') S.add_argument('-R', '--reload', action='store_true', default=False) S.set_defaults(func=writeprocs) S = SP.add_parser('start', help='Start a procServ instance') S.add_argument('name', help='Instance name') S.set_defaults(func=startproc) S = SP.add_parser('stop', help='Stop a procServ instance') S.add_argument('name', help='Instance name') S.set_defaults(func=stopproc) S = SP.add_parser('attach', help='Attach to a procServ instance') S.add_argument("name", help='Instance name') S.add_argument('extra', nargs=REMAINDER, help='extra args for telnet') S.set_defaults(func=attachproc) S = SP.add_parser('logs', help='Display the logs of a procServ instance') S.add_argument( '-t', '--tail', dest='tail', help="Output the specified number of lines at the end of the logfile") S.add_argument("name", help='Instance name') S.set_defaults(func=logsproc) A = P.parse_args(args=args) if not hasattr(A, 'func'): P.print_help() sys.exit(1) return A
def getargs(): from argparse import ArgumentParser P = ArgumentParser() P.add_argument('--user', action='store_true', default=os.geteuid() != 0, help='Consider user config') P.add_argument('--system', dest='user', action='store_false', help='Consider system config') P.add_argument('-v', '--verbose', action='count', default=0) SP = P.add_subparsers() S = SP.add_parser('status', help='List procServ instance state') S.set_defaults(func=status) S = SP.add_parser('list', help='List procServ instances') S.set_defaults(func=syslist) S = SP.add_parser('add', help='Create a new procServ instance') S.add_argument('-C', '--chdir', default=os.getcwd(), help='Run directory for instance') S.add_argument('-P', '--port', help='telnet port') S.add_argument('-U', '--user', dest='username') S.add_argument('-G', '--group') S.add_argument('-H', '--host', help='Target IOC hostname', default='localhost') S.add_argument('-S', '--site', help='Allow site-specific configuration') S.add_argument('-f', '--force', action='store_true', default=False) S.add_argument('-A', '--autostart', action='store_true', default=False, help='Automatically start the service after adding it') S.add_argument('-w', '--writeconf', action='store_true', default=True, help='Automatically update Conserver configuration') S.add_argument('-D', '--outsysd', default=systemd_dir) S.add_argument('-d', '--writesysd', action='store_true', default=True, help='Create systemd service files') S.add_argument('-R', '--reload', action='store_true', default=False, help='Restart conserver-server') S.add_argument( '--command', help='Command script or executable, without path (chdir is added later)' ) S.add_argument('name', help='Instance name') #S.add_argument('command', nargs='+', help='Command script or executable, without path (chdir is added later)') S.set_defaults(func=addproc) S = SP.add_parser('remove', help='Remove a procServ instance') S.add_argument('-f', '--force', action='store_true', default=False) S.add_argument('-w', '--writeconf', action='store_true', default=True, help='Automatically update Conserver configuration') S.add_argument('-D', '--outsysd', default=systemd_dir) S.add_argument('-d', '--writesysd', action='store_true', default=True, help='Create systemd service files') S.add_argument('-R', '--reload', action='store_true', default=False, help='Restart conserver-server') S.add_argument('name', help='Instance name') S.set_defaults(func=delproc) S = SP.add_parser('write-procs-cf', help='Write conserver config') S.add_argument('-f', '--out', default=conserver_conf) S.add_argument('-R', '--reload', action='store_true', default=False, help='Restart conserver-server') S.set_defaults(func=writeprocs) A = P.parse_args() if not hasattr(A, 'func'): P.print_help() sys.exit(1) return A