-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfire.py
executable file
·78 lines (69 loc) · 2.39 KB
/
fire.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
#!/usr/bin/env python
import os
import sys
import yaml
import subprocess
import shutil
def readConfig(fileName):
fd = open(fileName, "r")
return yaml.load(fd)
def executeCommand(task, conf_dir):
print("")
print("Executing " + task['name'])
command = task['command']
try:
p = subprocess.run(command, cwd=conf_dir, shell=True, check=True)
except:
print(task['name'] + " failed!!")
exit(0)
print("")
if __name__ == "__main__":
print("Firing config manager..")
if input("Are you sure? (y/n): ") != "y":
sys.exit(0)
configFileLocation = 'metadata.yaml'
if len(sys.argv) == 1:
print("Using default: metadata.yaml config")
else:
configFileLocation = sys.argv[1]
if len(sys.argv) != 2:
print("Ignoring extra arguments")
conf_dir = os.path.join(os.getcwd(), configFileLocation.rpartition('/')[0])
cfgObject = readConfig(configFileLocation)
# Preparation commands
for prep_task in cfgObject['pre']:
executeCommand(prep_task, conf_dir)
# Clone repos
for repo in cfgObject['subrepos']:
_location = os.path.join(conf_dir, os.path.expandvars(repo['location']))
_origin = repo['origin']
if os.path.exists(_location):
print("Directory for " + repo['name'] + " already exists.")
if input("[R]eplace?: ") != "R":
continue
shutil.rmtree(_location)
print("Cloning " + repo['name'])
subprocess.call(["git", "clone", "--recursive", _origin, _location])
# Softlinking directories
for direc in cfgObject['directories']:
_placed = os.path.join(conf_dir, os.path.expandvars(direc['placed']))
_location = os.path.expandvars(direc['location'])
try:
os.remove(_location)
except:
pass
print("Softlinking " + direc['name'])
subprocess.call(["ln", "-s", _placed, _location])
# Softlinking files
for f in cfgObject['files']:
_placed = os.path.join(conf_dir, os.path.expandvars(f['placed']))
_location = os.path.expandvars(f['location'])
try:
os.remove(_location)
except:
pass
print("Softlinking " + f['name'])
subprocess.call(["ln", "-s", _placed, _location])
# Finishing Tasks
for post_task in cfgObject['post']:
executeCommand(post_task, conf_dir)