-
Notifications
You must be signed in to change notification settings - Fork 16
/
pyqt-admin
executable file
·60 lines (52 loc) · 1.83 KB
/
pyqt-admin
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
56
57
58
59
60
#!/usr/bin/env python3
import os
import shutil
import argparse
import errno
def copy(src, dest):
try:
shutil.copytree(src, dest, ignore=shutil.ignore_patterns('setup.py', 'db.sqlite3', '.*', '__pycache__', 'README.md'))
except OSError as e:
# If the error was caused because the source wasn't a directory
if e.errno == errno.ENOTDIR:
shutil.copy(src, dest)
else:
print('Directory not copied. Error: %s' % e)
def main():
ap = argparse.ArgumentParser()
ap.add_argument("-s", "--startproject", nargs='*')
USAGE = 'usage : pyqt-admin --startproject project_name destination'
try :
args = vars(ap.parse_args())
except:
print('')
print(USAGE)
ap.exit()
if args['startproject']:
home_dir = os.path.expanduser('~')
template_dir = os.path.join(home_dir, '.django-pyqt')
if not os.path.exists(template_dir):
print('Please follow installation instructions')
return
proj_name = ''
destination = ''
proj_name = args["startproject"][0]
if len(args['startproject']) == 1:
print("using default destination for project '{}'".format(home_dir))
destination = home_dir
elif len(args['startproject']) > 1:
destination = args["startproject"][1]
if not os.path.isdir(destination):
print("Destination does not exist, using default destination '{}'".format(home_dir))
destination = home_dir
else :
destination = os.path.abspath(destination)
path = os.path.join(destination, proj_name)
if os.path.exists(path):
shutil.rmtree(path)
copy(template_dir, path)
else:
print(USAGE)
ap.exit()
if __name__ == '__main__':
main()