-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmkpkg
More file actions
executable file
·43 lines (34 loc) · 1.1 KB
/
mkpkg
File metadata and controls
executable file
·43 lines (34 loc) · 1.1 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
#!/usr/bin/python
import time, argparse
import os, sys
def main(argv):
"""
takes command line arguments, and makes a new python package at (path)
Optionally takes an argument -m, which adds a docstring to the __init__.py
"""
directory = ""
message = "# Created on " + time.strftime("%d/%m/%Y")
parser = argparse.ArgumentParser()
help = "Make a new python package with an optional -m 'message' in the docstring"
parser.add_argument("directory", help=help, type=str)
parser.add_argument("-m", help="optional message string")
args = parser.parse_args()
directory = args.directory
if directory == 'None':
print "No arguments supplied. Usage 'mkpkg [path] (optional) -m 'message'"
sys.exit(2)
return False
directory = argv[0]
try:
os.mkdir(directory)
except:
print "The directory '"+ directory + "' already exists."
sys.exit(2)
return
if args.m != None:
message = message + "\n" + "\"\"\""+ args.m + "\"\"\""
f = open(os.path.join(directory,"__init__.py"), 'w+')
f.write(message)
f.close()
if __name__ == "__main__":
main(sys.argv[1:])