-
Notifications
You must be signed in to change notification settings - Fork 7
/
travis.py
executable file
·96 lines (72 loc) · 3.32 KB
/
travis.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os
import os.path
import xml.dom.minidom
import argparse
class Config():
def __add_server(self, parent_node, settings, server_name):
try:
os.environ["TRAVIS_SECURE_ENV_VARS"]
except KeyError:
print "no secure env vars available, please declare it first"
sys.exit()
serversNodes = settings.getElementsByTagName("servers")
if not serversNodes:
serversNode = parent_node.createElement("servers")
settings.appendChild(serversNode)
else:
serversNode = serversNodes[0]
sonatypeServerNode = parent_node.createElement("server")
sonatypeServerId = parent_node.createElement("id")
sonatypeServerUser = parent_node.createElement("username")
sonatypeServerPass = parent_node.createElement("password")
idNode = parent_node.createTextNode(server_name)
userNode = parent_node.createTextNode(os.environ["SONATYPE_USERNAME"])
passNode = parent_node.createTextNode(os.environ["SONATYPE_PASSWORD"])
sonatypeServerId.appendChild(idNode)
sonatypeServerUser.appendChild(userNode)
sonatypeServerPass.appendChild(passNode)
sonatypeServerNode.appendChild(sonatypeServerId)
sonatypeServerNode.appendChild(sonatypeServerUser)
sonatypeServerNode.appendChild(sonatypeServerPass)
serversNode.appendChild(sonatypeServerNode)
def __add_mirror(self, parent_node, settings):
mirrors = parent_node.createElement("mirrors")
settings.appendChild(mirrors)
mirror = parent_node.createElement("mirror")
mirror_id = parent_node.createElement("id")
mirror_id_text = parent_node.createTextNode("nexus")
mirror_mirrorOf = parent_node.createElement("mirrorOf")
mirror_mirrorOf_text = parent_node.createTextNode("*")
mirror_url = parent_node.createElement("url")
mirror_url_value = parent_node.createTextNode("http://130.206.80.85/nexus/content/groups/public")
mirrors.appendChild(mirror)
mirror_id.appendChild(mirror_id_text)
mirror_mirrorOf.appendChild(mirror_mirrorOf_text)
mirror_url.appendChild(mirror_url_value)
mirror.appendChild(mirror_id)
mirror.appendChild(mirror_mirrorOf)
mirror.appendChild(mirror_url)
def configure_server(self, server=True, mirrors=True, home_dir=os.path.expanduser("~")):
m2 = xml.dom.minidom.parse(home_dir + '/.m2/settings.xml')
settings = m2.getElementsByTagName("settings")[0]
if mirrors:
self.__add_mirror(m2, settings)
if server:
self.__add_server(m2, settings, "repo-release")
self.__add_server(m2, settings, "repo-snapshot")
m2Str = m2.toxml()
f = open(home_dir + '/.m2/settings.xml', 'w')
f.write(m2Str)
f.close()
def main(prog_args):
parser = argparse.ArgumentParser()
parser.add_argument("--deploy", help="add servers tag to settings.xml", action="store_true")
parser.add_argument("--mirrors", help="add mirrors tag to settings.xml", action="store_true")
args = parser.parse_args()
config = Config()
config.configure_server(server=args.deploy, mirrors=args.mirrors)
if __name__ == "__main__":
sys.exit(main(sys.argv))