import os
import urllib2 
import time
import subprocess

URL_32=itsm.getParameter('Enter_the_URL_32')# Enter the URL for 32 bit
URL_64=itsm.getParameter('Enter_the_URL_64')# Enter the URL for 64 bit


if 'PROGRAMFILES(X86)' in os.environ.keys():
    URL=URL_64
else:
    URL=URL_32
    
def Download(URL):
    print "Download started"
    fileName =URL.split('/')[-1]
    src_path=os.environ['ProgramData']
    fp = os.path.join(src_path, fileName)
    request = urllib2.Request(URL, headers={'User-Agent' : "Magic Browser"})
    parsed = urllib2.urlopen(request)
    if os.path.exists(src_path):
        print "Path already exists"
    if not os.path.exists(src_path):
        os.makedirs(src_path)
        print "Path created"
    with open(fp, 'wb') as f:
        while True:
            chunk=parsed.read(100*1000*1000)
            if chunk:
                f.write(chunk)
            else:
                break
    print "The file downloaded successfully in specified path"+fp
    try:
        print'Downloaded Application %s Installation Started'%fileName
        os.popen("msiexec /i  %s  /quiet REBOOT=ReallySuppress CESMCONTEXT=1 MAKE_CESM_DEFAULT_CONFIG=1 CES_SANDBOX=1 CES_FIREWALL=1 CES_ANTIVIRUS=1" %(fp)).read()
        time.sleep(100)
        print '%s Application Successfully Installed'%fileName
    except:
        return 'No : '+fp+' is exist'


Download(URL)