-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPythonTemplate.py
More file actions
55 lines (41 loc) · 1.25 KB
/
PythonTemplate.py
File metadata and controls
55 lines (41 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
import io
import os
import re
import sys
from argparse import ArgumentParser
import subprocess
NAME = ""
VERBOSE = False
FILE = False
def run(cmd):
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
out = p.stdout.read().strip()
return out
def parse(argv):
global NAME, VERBOSE, FILE
p = ArgumentParser(description="A Python template for the shell.",
prog="python {}".format(NAME),
usage= "{} [option] [filename]".format(NAME))
p.add_argument("--verbose", "-v",
action = "store_true",
help="cause {} to be verbose, showing all \
operations".format(NAME),
default=False)
p.add_argument("--file", "-f",
action = "store_true",
help="read from file",
default=False)
args = p.parse_args()
if args.verbose:
VERBOSE = True
def main(argc, argv):
global NAME, FILE
NAME = argv[0]
parse(argv)
f = io.open(argv[1], "r", encoding="utf8") if argc > 1 else sys.stdin
for line in f:
sys.stdout.write(line)
f.close()
if __name__ == "__main__":
main(len(sys.argv), sys.argv)