def create_wapt_setup(wapt,default_public_cert='',default_repo_url='',default_wapt_server='',destination='',company=''): r"""Build a customized waptsetup with provided certificate included. Returns filename >>> from common import Wapt >>> wapt = Wapt(config_filename=r'C:\Users\htouvet\AppData\Local\waptconsole\waptconsole.ini') >>> create_wapt_setup(wapt,r'C:\private\ht.crt',destination='c:\\tranquilit\\wapt\\waptsetup') u'c:\\tranquilit\\wapt\\waptsetup\\waptsetup.exe' """ if not company: company = registered_organization() outputfile = '' iss_template = makepath(wapt.wapt_base_dir,'waptsetup','waptsetup.iss') custom_iss = makepath(wapt.wapt_base_dir,'waptsetup','custom_waptsetup.iss') iss = codecs.open(iss_template,'r',encoding='utf8').read().splitlines() new_iss=[] for line in iss: if line.startswith('#define default_repo_url'): new_iss.append('#define default_repo_url "%s"' % (default_repo_url)) elif line.startswith('#define default_wapt_server'): new_iss.append('#define default_wapt_server "%s"' % (default_wapt_server)) elif line.startswith('#define output_dir'): new_iss.append('#define output_dir "%s"' % (destination)) elif line.startswith('#define Company'): new_iss.append('#define Company "%s"' % (company)) elif line.startswith('#define install_certs'): new_iss.append('#define install_certs') elif line.startswith('WizardImageFile='): pass elif not line.startswith('#define signtool'): new_iss.append(line) if line.startswith('OutputBaseFilename'): outputfile = makepath(wapt.wapt_base_dir,'waptsetup','%s.exe' % line.split('=')[1]) source = os.path.normpath(default_public_cert) target = os.path.join(os.path.dirname(iss_template),'..','ssl') if not (os.path.normcase(os.path.abspath( os.path.dirname(source))) == os.path.normcase(os.path.abspath(target))): filecopyto(source,target) codecs.open(custom_iss,'wb',encoding='utf8').write('\n'.join(new_iss)) #inno_directory = '%s\\Inno Setup 5\\Compil32.exe' % programfiles32 inno_directory = makepath(wapt.wapt_base_dir,'waptsetup','innosetup','ISCC.exe') if not os.path.isfile(inno_directory): raise Exception(u"Innosetup n'est pas disponible (emplacement %s), veuillez l'installer" % inno_directory) run('"%s" %s' % (inno_directory,custom_iss)) #print('%s compiled successfully' % (outputfile, )) # create a sha256 file for waptupgrade package result = os.path.abspath(os.path.join(destination,os.path.basename(outputfile))) with open(makepath(wapt.wapt_base_dir,'waptupgrade','waptagent.sha256'),'wb') as f: f.write("%s %s\n" % (sha256_for_file(result),'waptagent.exe')) return result
def create_wapt_setup(wapt, default_public_cert='', default_repo_url='', default_wapt_server='', destination='', company=''): r"""Build a customized waptsetup with provided certificate included. Returns filename >>> from common import Wapt >>> wapt = Wapt(config_filename=r'C:\Users\htouvet\AppData\Local\waptconsole\waptconsole.ini') >>> create_wapt_setup(wapt,r'C:\private\ht.crt',destination='c:\\tranquilit\\wapt\\waptsetup') u'c:\\tranquilit\\wapt\\waptsetup\\waptsetup.exe' """ if not company and sys.platform == 'win32': company = registered_organization() outputfile = '' iss_template = makepath(wapt.wapt_base_dir, 'waptsetup', 'waptsetup.iss') custom_iss = makepath(wapt.wapt_base_dir, 'waptsetup', 'custom_waptsetup.iss') iss = codecs.open(iss_template, 'r', encoding='utf8').read().splitlines() new_iss = [] for line in iss: if line.startswith('#define default_repo_url'): new_iss.append('#define default_repo_url "%s"' % (default_repo_url)) elif line.startswith('#define default_wapt_server'): new_iss.append('#define default_wapt_server "%s"' % (default_wapt_server)) elif line.startswith('#define output_dir'): new_iss.append('#define output_dir "%s"' % (destination)) elif line.startswith('#define Company'): new_iss.append('#define Company "%s"' % (company)) elif line.startswith('#define install_certs'): new_iss.append('#define install_certs') elif line.startswith('WizardImageFile='): pass elif not line.startswith('#define signtool'): new_iss.append(line) if line.startswith('OutputBaseFilename'): outputfile = makepath(wapt.wapt_base_dir, 'waptsetup', '%s.exe' % line.split('=')[1]) source = os.path.normpath(default_public_cert) target = os.path.join(os.path.dirname(iss_template), '..', 'ssl') if not (os.path.normcase(os.path.abspath(os.path.dirname(source))) == os.path.normcase(os.path.abspath(target))): filecopyto(source, target) codecs.open(custom_iss, 'wb', encoding='utf8').write('\n'.join(new_iss)) #inno_directory = '%s\\Inno Setup 5\\Compil32.exe' % programfiles32 inno_directory = makepath(wapt.wapt_base_dir, 'waptsetup', 'innosetup', 'ISCC.exe') if not os.path.isfile(inno_directory): raise Exception( u"Innosetup n'est pas disponible (emplacement %s), veuillez l'installer" % inno_directory) run('"%s" %s' % (inno_directory, custom_iss)) #print('%s compiled successfully' % (outputfile, )) # create a sha256 file for waptupgrade package result = os.path.abspath( os.path.join(destination, os.path.basename(outputfile))) with open(makepath(wapt.wapt_base_dir, 'waptupgrade', 'waptagent.sha256'), 'wb') as f: f.write("%s %s\n" % (sha256_for_file(result), 'waptagent.exe')) return result