Skip to content

Commit

Permalink
made the plugin a little more talketive
Browse files Browse the repository at this point in the history
  • Loading branch information
WianVos committed Mar 24, 2016
1 parent 0386440 commit 8f2a236
Showing 1 changed file with 49 additions and 4 deletions.
53 changes: 49 additions & 4 deletions src/main/resources/xlr/CreateAndStartSubRelease.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,70 @@

import sys
import time
import pprint

class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'

from xlr.XLReleaseClientUtil import XLReleaseClientUtil

def report_variables(variables):
print bcolors.OKBLUE + bcolors.BOLD + "inbound variables"
print "-----------------------------------"
print bcolors.OKGREEN + "{0:25s}|{1:25s} ".format('key', 'value')
for k,v in variables.items():
print bcolors.BOLD + '{0:25s}| {1:25s}'.format(k,v)



def report_updatable_variables(updatable_variables, final=False):

if final:
print bcolors.OKBLUE + bcolors.BOLD + "final variable mapping"
else:
print bcolors.OKBLUE + bcolors.BOLD + "variables in target template needed to be mapped"

print "-----------------------------------"
print bcolors.OKGREEN + '{0:25s} |{1:25s} |{2:25s}'.format("key", "type", "value")

for var in updatable_variables:
key = var['key'].replace('${', '').replace('}', '')
type = var['type'].replace('DEFAULT', 'string')

print bcolors.BOLD + ' {0:25s}| {1:25s}| {2:15s}'.format(key, type, var['value'])


def process_variables(variables, updatable_variables):

var_map = {}
if variables is not None:
for variable in variables.split(','):
var_map[variable.split('=', 1)[0]]= variable.split('=', 1)[1]

report_variables(var_map)

for updatable_variable in updatable_variables:
key = str(updatable_variable["key"]).strip("${").strip("}")
if key in var_map:
updatable_variable["value"] = var_map[key]
else:
print bcolors.FAIL + "required variable not found : %s " % (key)
system.exit(2)

report_updatable_variables(updatable_variables, final=True)

return str(updatable_variables).replace("u'","'").replace("'", '"').replace("None","null")


if xlrServer is None:
print "No server provided."
print bcolors.FAIL + "No server provided."
sys.exit(1)

xlr_client = XLReleaseClientUtil.createXLReleaseClient(xlrServer, username, password)
Expand All @@ -38,18 +84,17 @@ def process_variables(variables, updatable_variables):
releaseDescription = ""

release_id = xlr_client.create_release(releaseTitle, releaseDescription, vars, repr(template.tags).replace("'",'"'), template.id.split("/")[1])

# Start Release
xlr_client.start_release(release_id)

# Wait for subrelease to be finished (only if asynch is true)
while not asynch:
status = xlr_client.get_release_status(release_id)
if status == "COMPLETED":
print "Subrelease %s completed in XLR" % (release_id)
print bcolors.OKGREEN + "Subrelease %s completed in XLR" % (release_id)
break
if status == "ABORTED":
print "Subrelease %s aborted in XLR" % (release_id)
print bcolors.FAIL + "Subrelease %s aborted in XLR" % (release_id)
sys.exit(1)
time.sleep(5)

0 comments on commit 8f2a236

Please sign in to comment.