print "*** Beginning of Deploy Script"

if len(sys.argv) != 1:
    print "Usage: wsadmin -lang jython -f WebSphereDeploy.py PARAMFILE"
    print "    PARAMFILE is a file containing 'name = value' assignments for"
    print "        configuration variables like 'FIPER_HOME'."
    sys.exit(1)

# Read param file into dictionary 'param'
param = {}
f = open(sys.argv[0])
while 1:
    line = f.readline()
    if line is None or line == '': break
    line = line.strip()
    if len(line) == 0 or line.startswith('#'): continue
    (key, value) = line.split('=', 1)
    key=key.strip()
    value=value.strip()
    param[key] = value
    #print key + ' = ' + value + ';'

f.close()

# Assign parameters to global variables.
# The following will throw KeyError if one of the required names is missing.

fiperHome      = param['FIPER_HOME']
WEBTOP_INSTALL = param['WEBTOP_INSTALL']
WEBDASH_INSTALL= param['WEBDASH_INSTALL']
B2B_INSTALL    = param['B2B_INSTALL']
WAS_SECURITY   = param['ACS_SECURITY']

##----------------------------------------
# Set the application values 
#----------------------------------------
wasServerName = "server1"
appName1 = "FIPER"
appInstallFile1 = fiperHome + "/reffiles/SMAFIPserver/websphere/fiper.ear"
webtopContextRoot = "webtop"
webtopWarFile = fiperHome + "/reffiles/SMAFIPserver/websphere/webtop.war"
dashboardContextRoot = "webdashboard"
dashboardWarFile = fiperHome + "/reffiles/SMAFIPserver/websphere/webdashboard.war"


#----------------------------------------
#  Install ear
#----------------------------------------
print ""
print "*** Installing ACS"
print "   app name = " + appName1
print "   ear file = " + appInstallFile1
installEar(appName1, appInstallFile1)


if param['WEBTOP_INSTALL'] != '':
    print ""
    print "*** Installing WebTop"
    print "   war file = " + webtopWarFile
    print "   webtop context = " + webtopContextRoot
    AdminApp.install(webtopWarFile, ["-contextroot", webtopContextRoot])

if param['WEBDASH_INSTALL'] != '':
    print ""
    print "*** Installing Web Dashboard"
    print "   war file = " + dashboardWarFile
    print "   dashboard context = " + dashboardContextRoot
    AdminApp.install(dashboardWarFile, ["-contextroot", dashboardContextRoot])

if param['B2B_INSTALL'] != '':
    print "*** Installing B2B feature"
    print "###TODO B2B is not yet supported"

#----------------------------------------
# IMPORTANT
# Save the configuration changes made
#----------------------------------------
saveConfiguration()

#
# and start the application
startApp(appName1, wasServerName)

