def _parse_hexdump_argv(argv): """Parse the command line""" args = argdoc.parse_args(argv[1:]) args.classic = (args.bytes is False) and (args.charset is False) # args.stride = 1 if (args.bytes is not None) and (args.bytes is not False): args.stride = int(args.bytes, 0) # args.encoding = args.C or (args.charset is not False) args.decoding = None far_codec_hint = "utf-8" if args.charset is not False: args.decoding = True if args.charset: far_codec_hint = args.charset if args.bytes is not False: stderr_print(argdoc.format_usage().rstrip()) stderr_print( "hexdump.py: error: choose --charset or --bytes, not both") sys.exit(2) # exit 2 from rejecting usage "".encode(far_codec_hint) # may raise LookupError: unknown encoding near_codec_hint = far_codec_hint.replace("-", "_").lower() ascii_codec_hints = "ascii 646 us_ascii" utf_8_codec_hints = "utf_8 u8 utf utf8 cp65001".split() latin_1_codec_hints = ( "latin_1 iso_8859_1 iso8859_1 8859 cp819 latin latin1 l1".split()) args.codec = far_codec_hint if near_codec_hint in ascii_codec_hints: args.codec = "ascii" elif near_codec_hint in latin_1_codec_hints: args.codec = "latin-1" elif near_codec_hint in utf_8_codec_hints: args.codec = "utf-8" else: stderr_print(argdoc.format_usage().rstrip()) stderr_print( "hexdump.py: error: choose --charset from: ascii, latin-1, utf-8") sys.exit(2) # exit 2 from rejecting usage # return args
def main(): """Run from the command line""" args = argdoc.parse_args() if not args.t: stderr_print(argdoc.format_usage().rstrip()) stderr_print("column.py: error: no arguments not implemented") sys.exit(2) # exit 2 from rejecting usage # Fetch all of Stdin prompt_tty_stdin() lines = sys.stdin.readlines() # Divide each line into words split_lines = list(_.split() for _ in lines) # Discard empty lines rows = list(row for row in split_lines if row) # Justify the cells in each column justified_rows = justify_cells_in_rows(complete_rows(rows, cell="")) for justified_row in justified_rows: print(" ".join(justified_row).rstrip())
def main(argv): chmod_argv_tail = argv[1:] if argv[1:]: if argv[1].startswith("-") and not argv[1].startswith("-R"): chmod_argv_tail[0:0] = ["--"] args = argdoc.parse_args(chmod_argv_tail) sys.stderr.write("{}\n".format(args)) sys.stderr.write("{}\n".format(argdoc.format_usage().rstrip())) sys.stderr.write("chmod.py: error: not implemented\n") sys.exit(2) # exit 2 from rejecting usage
def main(argv): """Run from the command line""" args = argdoc.parse_args(argv[1:]) main.args = args stderr_print(args) stderr_print(argdoc.format_usage().rstrip()) stderr_print("watch.py: error: not implemented") sys.exit(2) # exit 2 from rejecting usage main.era = datetime.datetime.now() last_result = None next_call = main.era while True: when_called = datetime.datetime.now() result = check_transcript(args.words) when_returned = datetime.datetime.now() if result != last_result: last_result = result sys.stdout.write( "\x1B[H\x1B[2J") # Ansi Clear from $(clear | cat -tv) sys.stdout.write( "\n") # end the line to keep the 'screen' text 'grep'pable (exit_status, out_bytes) = result print("{} + N * {}".format( when_called, datetime.timedelta(seconds=args.interval))) print() print("+ {}".format(shlex_join(args.words))) sys.stdout.write(out_bytes) print("+ exit {}".format(exit_status)) print() print("{} - {}".format(when_returned, (when_returned - when_called))) sys.stdout.flush() while next_call < datetime.datetime.now(): next_call += datetime.timedelta(seconds=args.interval) next_call += datetime.timedelta(seconds=args.interval) sleepy = (next_call - datetime.datetime.now()).total_seconds() assert sleepy > 0 time.sleep(sleepy)
def main(argv): args = argdoc.parse_args() if not args.interact: stderr_print(argdoc.format_usage().rstrip()) stderr_print("bash.py: error: choose --interact") sys.exit(2) # exit 2 from rejecting usage # Print banner stderr_print() stderr_print("Pybashish 0.x.y for Linux and Mac OS Terminals") stderr_print('Type "help" and press Return for more information.') stderr_print( 'Type "exit" and press Return to quit, or press ⌃D EOF to quit') stderr_print() # Serve till exit main.returncode = None while True: # Pull one line of input prompt = calc_ps1() try: shline = read.readline(prompt) except KeyboardInterrupt: continue # Exit at end-of-file # Exit with same subprocess.CompletedProcess.returncode=1 as Bash exit at EOF if not shline: sys.exit(1) # Compile and execute the line returncode = compile_and_run_shline(shline) main.returncode = returncode if returncode: # trace nonzero a la Zsh "print_exit_value" stderr_print("bash.py: warning: exit {}".format(returncode))
def main(): args = argdoc.parse_args() main.args = args if (args.force, args.interact) == (0, 0): stderr_print(argdoc.format_usage().rstrip()) stderr_print("cspsh.py: error: choose --force or --interact") sys.exit(2) # exit 2 from rejecting usage lines = list() if args.force: lines = textwrap.dedent(TEST_LINES).strip().splitlines(keepends=True) lines.append("") if args.command is not None: lines.append(args.command + "\n") lines.append("") run_cspvm(lines, args=args)
def main(): args = argdoc.parse_args() sys.stderr.write("{}\n".format(args)) sys.stderr.write("{}\n".format(argdoc.format_usage().rstrip())) sys.stderr.write("sort.py: error: not implemented\n") sys.exit(2) # exit 2 from rejecting usage
def main(argv): # FIXME FIXME # noqa C901 """Run a command line""" args = argdoc.parse_args() # Choose to edit the os copy-paste clipboard, or not if args.edit_clipboard and args.edit_stdio: sys.stderr.write("{}\n".format(argdoc.format_usage().rstrip())) sys.stderr.write( "hearme.py: error: " "choose '--edit-clipboard' or '--edit-stdio' or neither, never both\n" ) sys.exit(2) # exit 2 from rejecting usage if args.edit_clipboard: edit_clipboard = True elif args.edit_stdio: edit_clipboard = False else: edit_clipboard = True if not sys.stdin.isatty(): edit_clipboard = False if not sys.stdout.isatty(): edit_clipboard = False if not edit_clipboard: prompt_tty_stdin() # Create an empty Awk program awk = argparse.Namespace() awk.lines = list() awk.prints = list() awk.end_prints = list() # Parse each hint for hint in args.hints: try: add_awk_hint(awk, hint=hint) except Exception: sys.stderr.write( "error: hearme.py: meaningless hint {!r}\n".format(hint)) sys.exit(1) # Option to source from the clipboard shline = "" if edit_clipboard: shline = "pbpaste | " # Plan to print each of the "awk.prints", else infer a print of the Awk line awk_lines = awk.lines if awk.prints or not awk.lines: awk_print_line = "print " + ", ".join(awk.prints) awk_lines = awk.lines + [awk_print_line.rstrip()] else: awk_lines.append("print") # Form the Bash line shline += "awk '" shline += "//{" shline += "; ".join(awk_lines) shline += "}" if awk.end_prints: shline += " END{" shline += "print " + ", ".join(awk.end_prints) shline += "}" shline += "'" # Option to sink back into the clipboard # Note: We need "pbpaste" and/or "pbcopy" to sponge a whole copy if edit_clipboard: shline += "| pbcopy" # Just show it, don't run it, if cut short by doubled "-ii" if args.interact > 1: if not args.quiet: sys.stderr.write("+ # {}\n".format(shline)) sys.exit() # Show it, unless silenced by "-q" if not args.quiet: sys.stderr.write("+ {}\n".format(shline)) # Ask to run it, before running it, if slowed by "-i" if args.interact: sys.stderr.write("Press Return to continue, else Control+C to quit\n") try: sys.stdin.readline() except KeyboardInterrupt: print("KeyboardInterrupt") sys.exit(1) # Run it ran = subprocess.run(shline, shell=True) sys.exit(ran.returncode)