def main(args=None): """ Command line entrypoint """ if args is None: args = sys.argv c = U.cmdline([{'opts': ['-n', '--dry-run'], 'action': 'store_true', 'default': False, 'dest': 'dryrun', 'help': 'just report'}, {'opts': ['-p', '--pattern'], 'action': 'store', 'default': None, 'dest': 'pattern', 'help': 'file matching regexp'}, {'opts': ['-r', '--recursive'], 'action': 'store_true', 'default': False, 'dest': 'recursive', 'help': 'whether to descend directories'} ], usage=usage()) (o, a) = c.parse(args) if 0 == len(a[1:]): cleanup('.', o.dryrun, o.pattern, o.recursive) else: for dir in a[1:]: cleanup(dir, o.dryrun, o.pattern, o.recursive)
def main(argv=None): """ Command line entry point """ if argv is None: argv = sys.argv c = U.cmdline([]) (o, a) = c.parse(argv) try: r = [] while True: expr = raw_input("> ") r.append(eval(expr)) if type(r[-1]) == int: print("r[%d] = %d" % (len(r)-1, r[-1])) elif type(r[-1]) == float: print("r[%d] = %f" % (len(r)-1, r[-1])) elif type(r[-1]) == str: print("r[%d] = %s" % (len(r)-1, r[-1])) else: print("r[%d] = %s" % (len(r)-1, str(r[-1]))) except EOFError: print '' sys.exit(0)
def main(argv=None): """ Entry point for ascii(1) command. """ if argv is None: argv = sys.argv cmd = U.cmdline([], usage=usage()) (opts, args) = cmd.parse(argv) asc = ['NUL', 'SOH', 'STX', 'ETX', 'EOT', 'ENQ', 'ACK', 'BEL', 'BS', 'TAB', 'LF', 'VT', 'FF', 'CR', 'SO', 'SI', 'DLE', 'DC1', 'DC2', 'DC3', 'DC4', 'NAK', 'SYN', 'ETB', 'CAN', 'EM', 'SUB', 'ESC', 'FS', 'GS', 'RS', 'US', 'SPC'] for i in range(33): sys.stdout.write('0x%02x %-3s ' % (i, asc[i])) if (i+1) % 8 == 0: sys.stdout.write('\n') for i in range(33, 127): sys.stdout.write('0x%02x %-3c ' % (i, i)) if (i+1) % 8 == 0: sys.stdout.write('\n') sys.stdout.write("\n")
def main(argv=None): """ Command line entry point """ if argv is None: argv = sys.argv cmd = U.cmdline([]) (_, _) = cmd.parse(argv) try: results = [] while True: expr = raw_input("> ") results.append(eval(expr)) if isinstance(results[-1], int): print("r[%d] = %d" % (len(results)-1, results[-1])) elif isinstance(results[-1], float): print("r[%d] = %f" % (len(results)-1, results[-1])) elif isinstance(results[-1], str): print("r[%d] = %s" % (len(results)-1, results[-1])) else: print("r[%d] = %s" % (len(results)-1, str(results[-1]))) except EOFError: print '' sys.exit(0)
def main(A=None): """ Program entry point """ if A is None: A = sys.argv c = U.cmdline([], usage=usage()) (o, a) = c.parse(A) if 1 < len(a): input = open(a[1], 'r') else: input = sys.stdin align(input)
def main(argl=None): """ Program entry point """ if argl is None: argl = sys.argv cmd = U.cmdline([], usage=usage()) (_, args) = cmd.parse(argl) if 1 < len(args): src = open(args[1], 'r') else: src = sys.stdin align(src)
def bscr_version(args): """version - report the version of this backscratcher instance usage: bscr version """ ap = util.cmdline([{'opts': ['-v', '--verbose'], 'action': 'store_true', 'default': False, 'dest': 'verbose', 'help': 'show more info' } ]) (o, a) = ap.parse(args) print("Backscratcher version %s" % __version__)
def qstat(user=None, queue=None, extra=None, remote=None, process=False): command = "" if remote is not None: command += 'ssh -x {0} '.format(str(remote)) command += "qstat -x -f " if user is not None: command += "-u {0} ".format(str(user)) if queue is not None: command += str(queue) if extra is not None: command += str(extra) qresult = cmdline(command) if process: qresult = qstat_process(qresult) return qresult
def whych(): """ Find stuff """ cmd = U.cmdline([{'name': 'namespace', 'default': '', 'help': 'python (default), perl, or bash'}]) (opts, args) = cmd.parse(sys.argv) if opts.namespace in ['', 'python']: for item in args[1:]: print(python_which(item)) elif opts.namespace == 'perl': for item in args[1:]: print(perl_which(item)) elif opts.namespace == 'bash': for item in args[1:]: print(bash_which(item)) else: raise SystemExit("--namespace argument must be 'python', " + "'perl', or 'bash'")
def main(argv=None): """ Select the function to apply based on the command line options. """ if argv is None: argv = sys.argv cmd = util.cmdline([{'opts': ['-c', '--command'], 'action': 'store', 'dest': 'cmd', 'default': '', 'type': 'string', 'help': 'command to apply to all arguments'}, {'opts': ['-d', '--debug'], 'action': 'store_true', 'dest': 'debug', 'default': False, 'help': 'run under the debugger'}, {'opts': ['-e', '--edit'], 'action': 'store', 'dest': 'edit', 'default': '', 'type': 'string', 'help': 'file rename expression applied to all' ' arguments'}, {'opts': ['-i', '--integer'], 'action': 'store', 'dest': 'irange', 'default': '', 'type': 'string', 'help': 'low:high -- generate range of numbers'}, {'opts': ['-n', '--dry-run'], 'action': 'store_true', 'dest': 'dryrun', 'default': False, 'help': 'dryrun or execute'}, {'opts': ['-q', '--quiet'], 'action': 'store_true', 'dest': 'quiet', 'default': False, 'help': "don't echo commands, just run them"}, {'opts': ['-x', '--xargs'], 'action': 'store_true', 'dest': 'xargs', 'default': False, 'help': 'batch input from stdin into command lines' ' like xargs'}], usage=usage()) (opts, args) = cmd.parse(argv) if opts.debug: pdb.set_trace() # home = os.getenv('HOME') if opts.edit != '': subst_rename(opts, args[1:]) elif opts.irange != '': iterate_command(opts, args[1:]) elif opts.xargs: batch_command(opts, args[1:]) elif opts.cmd != '': subst_command(opts, args[1:]) else: print usage()
def main(argv=None): """ Main entry point for replay program. Run a command repeatedly to view its changing output on a time scheule (say, once every five seconds) or to regenerate an output when a file is updated. """ c = U.cmdline([{'opts': ['-c', '--change'], 'action': 'store_true', 'default': False, 'dest': 'change', 'help': 'update on change', }, {'opts': ['-d', '--debug'], 'action': 'store_true', 'default': False, 'dest': 'debug', 'help': 'run under debugger', }, {'opts': ['-i', '--interval'], 'action': 'store', 'default': 10, 'dest': 'interval', 'help': 'seconds between updates', }, {'opts': ['-p', '--prompt'], 'action': 'store_true', 'default': False, 'dest': 'prompt', 'help': 'update on user input', }, {'opts': ['-t', '--trigger'], 'action': 'store', 'default': '', 'dest': 'pathname', 'help': 'update when mtime on pathname changes', }, ]) (o, a) = c.parse(argv) if o.debug: pdb.set_trace() try: start = time.time() cmd = " ".join(a) old_stuff_s = "" while True: f = os.popen(cmd, "r") stuff = f.readlines() f.close() stuff_s = " ".join(stuff) if o.prompt: report(start, cmd, stuff_s) x = raw_input('Press ENTER to continue...') elif o.change: if stuff_s != old_stuff_s: report(start, cmd, stuff_s) old_stuff_s = stuff_s time.sleep(1.0) elif o.pathname != '': when = U.mtime(o.pathname) report(start, cmd, stuff_s) while when == U.mtime(o.pathname): time.sleep(1.0) else: report(start, cmd, stuff_s) time.sleep(float(o.interval)) except KeyboardInterrupt: print("") sys.exit()