forked from htinney/hops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.py
102 lines (79 loc) · 2.88 KB
/
install.py
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import argparse
import os
import re
import shutil
import json
def get_user_hfs(force=False):
hdirs = [ hdir for hdir in os.listdir(os.environ["HOME"])
if os.path.isdir(hdir) and
if re.match("^houdini[0-9]+.[0-9]+$", hdir) ]
if len(hdirs) < 1:
print "No houdini preferences found in user folder."
return None
if len(hdirs == 1):
return hdirs[0]
if force:
return max([hdir for hdir in hdirs],
key=lambda hdir: float(hdir.replace("houdini", "")))
print "\nHOUDINI PREFS FOLDERS:\n\n"
for i, hdir in enumerate(hdirs):
print "[{0}] {1}\n".format(i, hdir)
print "\nChoose a Houdini version\n\n"
valid_input = False
while True:
selection = raw_input("Number between {0}-{1}, or q to quit: "
.format(0, len(dirs) - 1))
if selection == "q":
return None
try:
num = int(selection)
if num < 0 or num >= len(houdinidirs):
print "Not in range.\n"
continue
return hdirs[num]
except ValueError:
print "Not a valid number.\n"
continue
parser = argparse.ArgumentParser(description="Install or update HOPs")
parser.add_argument("--fromuser", "-u", action="store_true",
help="Pull changes from user's folder")
parser.add_argument("--hdadir", "-d", action="store",
help="Install to a specific hda directory")
parser.add_argument("--force", "-f", action="store_true",
help="Ask for no user input, chooses defaults where it can")
args = parser.parse_args()
hdadir = os.hdadir
if not hdadir:
hfs = get_user_hfs(force=bool(args.force))
if not hfs:
quit()
hdadir = os.path.join(hfs, "otls")
src_hdadir = os.path.join(os.path.dirname(__file__), "hdas")
history = {}
if args.fromuser:
history_file = os.path.join(src_hdadir, "hops_data", "history.json")
else:
history_file = os.path.join(hdadir, "hops_data", "history.json")
with open(history_file, "r") as f:
history = json.loads(f)
version = 0
about_file = os.path.join(src_hdadir, "hops_data", "about.json")
with open(about_file, "r") as f:
about = json.loads(f)
if args.fromuser:
about["version"] += 1
version = about["version"]
# shutil.copytree(src_hdadir, hdadir)
with open(about_file, "w") as f:
f.write(json.dumps(version))
import getpass, socket, datetime
user = getpass.getuser()
hostname = socket.gethostname()
time = datetime.datetime.now().isoformat()
history.update({"type" : "development" if args.fromuser else "deployment",
"version" : version,
"user" : user,
"host" : hostname,
"time" : time })
with open(history_file, "w") as f:
f.write(json.dumps(history))