from java import util
from java import io
from java import lang
from java import text

execfile("properties.py")

execfile("adminnode.py")
execfile("jdbcConfiguration.py")
execfile("JMSConfiguration.py")

def changeDebugPort(randomAccessFile,newword,replaceString,offset):
 fpointer = randomAccessFile.getFilePointer()
 nextLine = randomAccessFile.readLine()
 while( nextLine != None):
  fpointer = randomAccessFile.getFilePointer() - len(nextLine) - offset
  occuranceIndex=nextLine.find(newword) 
  if (occuranceIndex >= 0 ):
   print nextLine + 'replaced with '+ replaceString
   randomAccessFile.seek(fpointer);
   randomAccessFile.writeBytes(replaceString);
  nextLine = randomAccessFile.readLine()
print props.getProperty("cds.debug.port")
if(props.getProperty("cds.debug.port") != None):
 domainEnvCmd= io.RandomAccessFile(io.File( props.getProperty("cds.appserver.domaindir")+'/bin/setDomainEnv.cmd'),"rws")
 domainEnvSh = io.RandomAccessFile(io.File( props.getProperty("cds.appserver.domaindir")+'/bin/setDomainEnv.sh'),"rws")
 changeDebugPort(domainEnvCmd,'set DEBUG_PORT     ','set DEBUG_PORT='+props.getProperty("cds.debug.port"),1)
 changeDebugPort(domainEnvSh,'DEBUG_PORT=\"8453\"','DEBUG_PORT=\"'+props.getProperty("cds.debug.port")+'"',0)


  
'''
startNodeManager()
nmConnect('weblogic', 'weblogic', 'localhost', '5556', props.get('cds.appserver.domainname'), props.get('cds.appserver.domaindir'),'ssl')
nmStart(props.getProperty("cds.appserver.domainname")+'.admin')

connect( props.get('cds.appserver.admin.username'),props.get('cds.appserver.admin.password'),props.get('cds.appserver.admin.url'))
start(props.get('cds.appserver.target.server'), 'Server')
'''

