/
update.py
182 lines (149 loc) · 6.2 KB
/
update.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import os
import skytap
import sys
from update_scripts import update_aliases
from update_scripts import update_india
from update_scripts import update_write_SP
from update_scripts import update_purge
from update_scripts import update_services
from update_scripts import update_public_ips
from update_scripts import update_shutdown_times
from update_scripts import update_write
def write(args, envs, config_data, number, name=None):
"""Begin process of writing wiki pages."""
os.system("clear")
if len(args) < 3:
if number == 1 or args[1] == "write":
print ("Writing wiki pages.")
update_write.start(envs, config_data)
return
elif number == 2:
name = raw_input("Enter a single word. All environments with this "
"word in their title will be updated:")
# If a name was not given by the user, establish the input arg as the name.
if not name:
name = args[2]
print ("Writing wiki pages for all environments with \""
"" + name + "\" in the name.")
update_write.start(envs, config_data, name)
def purge(envs, config_data):
"""Begin process of purging pages for nonexistent environments."""
os.system("clear")
print ("Purging wiki pages for nonexistent environments.")
update_purge.start(envs, config_data)
def htmlout(args, envs, config_data,number,name=None):
"""Begin process of writing wiki pages."""
os.system("clear")
if len(args) < 3:
if args[1] == "htmlout":
print ("Writing Individual wiki pages for upload to SharePoint.")
update_write_SP.start(envs, config_data)
return
elif number == 9:
name = raw_input("Enter a single word. All environments with this "
"word in their title will be updated:")
# If a name was not given by the user, establish the input arg as the name.
if not name:
name = args[2]
print ("Writing HTML pages for all environments with \""
"" + name + "\" in the name.")
update_write_SP.start(envs, config_data, name)
def india(envs, config_data):
"""Begin process of updating India environments page."""
os.system("clear")
print ("Writing India wiki page.")
update_india.start(envs, config_data)
def services(envs, config_data):
"""Begin process of updating published services page."""
os.system("clear")
print ("Writing Services wiki page.")
update_services.start(envs, config_data)
def ips(envs, config_data):
"""Begin process of updating public IPs page."""
os.system("clear")
print ("Writing Public IPs wiki page.")
update_public_ips.start(envs, config_data)
def aliases(envs, config_data):
"""Begin process of updating DNS aliases page."""
os.system("clear")
print ("Writing Aliases wiki page.")
update_aliases.start(envs, config_data)
def shutdown_times(envs, config_data):
"""Begin process of updating shutdown times pages."""
os.system("clear")
print ("Writing Shutdown Times wiki page.")
update_shutdown_times.start(envs, config_data)
def start(args):
"""Redirect to update function based on input given."""
# Get all environments from Skytap
envs = skytap.Environments()
# Import yaml and yada yada yada
try:
import yaml
except ImportError:
sys.stderr.write("You do not have the 'yaml' module installed. "
"Please see http://pyyaml.org/wiki/PyYAMLDocumentation"
" for more information.")
exit(1)
try:
f = open("config.yml")
config_data = yaml.safe_load(f)
f.close()
except IOError:
sys.stderr.write("There is no config.yml in the directory. Create one "
"and then try again.\nFor reference, check config_"
"template.yml and follow the listed guidelines.\n")
exit(1)
number = None
# Welcome text, if user types "python update.py"
if (len(args) == 1):
args.append(None) # Putting a dummy element in args for later on
options = 9 # Number of options available here
os.system("clear")
print ("Welcome to Autodocs!")
print ("To run a function, please enter the appropriate number below.")
print ("\n------------------\n")
print ("1 - Update wiki pages and DNS settings")
print ("2 - Update the wiki page and DNS settings of specific "
"environment(s)")
print ("3 - Purge wiki space of pages for nonexistent environments")
print ("4 - Update India environments wiki page")
print ("5 - Update published services wiki page")
print ("6 - Update public IPs wiki page")
print ("7 - Update DNS aliases wiki page")
print ("8 - Update shutdown times wiki pages")
print ("9 - Write HTML pages to post to SharePoint")
print ("\n------------------\n")
while not number:
number = raw_input("Type the number of the function you wish to "
"run:")
try:
number = int(number)
if number > options:
number = None
except ValueError:
print ("Dude.")
number = None
# Go to specific functions based on passed arguments
# Ex. "python update.py write" or "python update.py services"
if ((number == 1 or number == 2) or args[1] == "write"):
write(args, envs, config_data, number)
elif (number == 3 or args[1] == "purge"):
purge(envs, config_data)
elif (number == 4 or args[1] == "india"):
india(envs, config_data)
elif (number == 5 or args[1] == "services"):
services(envs, config_data)
elif (number == 6 or args[1] == "ips"):
ips(envs, config_data)
elif (number == 7 or args[1] == "aliases"):
aliases(envs, config_data)
elif (number == 8 or args[1] == "shutdown_times"):
shutdown_times(envs, config_data)
elif (number == 9 or args[1] == "htmlout"):
htmlout(args, envs, config_data, number)
else:
print ("Command not recognized.")
print ("\n\nJob\'s done.\n")
if __name__ == '__main__':
start(sys.argv)