forked from kernelci/lava-ci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
66 lines (49 loc) · 1.54 KB
/
utils.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
#!/usr/bin/python
import os
import shutil
import urlparse
import xmlrpclib
import json
def write_file(file, name, directory):
with open(os.path.join(directory, name), 'w') as f:
f.write(file)
def write_json(name, directory, data):
with open(os.path.join(directory, name), 'w') as f:
json.dump(data, f, indent=4, sort_keys=True)
def load_json(json_file):
with open(json_file, 'r') as f:
return json.load(f)
def mkdir(directory):
if not ensure_dir(directory):
shutil.rmtree(directory)
os.makedirs(directory)
def ensure_dir(directory):
if not os.path.exists(directory):
os.makedirs(directory)
return True
else:
return False
def in_bundle_attributes(bundle_atrributes, key):
if key in bundle_atrributes:
return True
else:
return False
def validate_input(username, token, server):
url = urlparse.urlparse(server)
if url.path.find('RPC2') == -1:
print "LAVA Server URL must end with /RPC2"
exit(1)
return url.scheme + '://' + username + ':' + token + '@' + url.netloc + url.path
def connect(url):
try:
print "Connecting to Server..."
connection = xmlrpclib.ServerProxy(url)
print "Connection Successful!"
print "connect-to-server : pass"
return connection
except (xmlrpclib.ProtocolError, xmlrpclib.Fault, IOError) as e:
print "CONNECTION ERROR!"
print "Unable to connect to %s" % url
print e
print "connect-to-server : fail"
exit(1)