-
Notifications
You must be signed in to change notification settings - Fork 20
/
appinfo.py
72 lines (51 loc) · 1.9 KB
/
appinfo.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
import sys
import os
#add current dir to syspath to import local modules
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
#local imports
from utils import *
def appsinfo(options):
info_cmd = ["rhc-domain-info", "--apps", "--rhlogin=%s" % options.rhlogin]
if options.password != '': info_cmd.append("--password=%s" % options.password)
out, err, ret = shellexecute( info_cmd, msg="Contacting openshift...", debug=options.debug, exit_on_error=True )
return parseuserinfo(out)
def appinfo(options):
apps = appsinfo(options)
if not apps.has_key(options.app): return None
return apps[options.app]
def parseuserinfo(data):
apps, app = {}, None
lines = data.splitlines()
for line in lines:
if ignoreline(line): continue
if isApplication(line):
if app != None: apps[app.name] = app
app = openshift_application(line)
else:
if line.find(":") != -1:
line = line.strip().lower()
key, value = line.split(":", 1)
if key == "creation": app.creation = value.strip()
if key == "framework": app.framework = value.strip()
if key == "git url": app.repo = value.strip()
if key == "public url": app.url = value.strip()
#add last application
if app != None: apps[app.name] = app
return apps
def isApplication(line):
if ignoreline(line): return False
return not line.startswith(" ")
def ignoreline(line):
return line == '' or startswithany(line, ["Contacting", "Application Info", "=="])
def startswithany(text, prefixes):
for prefix in prefixes:
if text.startswith(prefix):
return True
return False
class openshift_application:
def __init__(self, name='', creation='', framework='', repo='', url=''):
self.name, self.creation, self.framework, self.repo, self.url = \
name, creation, framework, repo, url
def __repr__(self):
return 'name: %s, creation: %s, framework: %s, repo: %s, url: %s' % \
(self.name, self.creation, self.framework, self.repo, self.url)