def set_app_ico(lpi_path, edition): (lpi_rootname, lpi_ext) = os.path.splitext(lpi_path) appico_path = lpi_rootname + '.ico' source_ico = setuphelpers.makepath(wapt_root_dir, 'wapt-%s.ico' % edition) if not os.path.isfile(source_ico): source_ico = setuphelpers.makepath(wapt_root_dir, 'wapt.ico') setuphelpers.filecopyto(source_ico, appico_path)
def set_app_ico(lpi_path,edition): (lpi_rootname,lpi_ext) = os.path.splitext(lpi_path) appico_path = lpi_rootname+'.ico' source_ico = setuphelpers.makepath(wapt_root_dir,'wapt-%s.ico'%edition) if not os.path.isfile(source_ico): source_ico = setuphelpers.makepath(wapt_root_dir,'wapt.ico') setuphelpers.filecopyto(source_ico,appico_path)
def build_waptupgrade_package(waptconfigfile, target_directory=None, wapt_server_user=None, wapt_server_passwd=None, key_password=None, sign_digests=None): if target_directory is None: target_directory = tempfile.gettempdir() if not wapt_server_user: wapt_server_user = raw_input('WAPT Server user :'******'WAPT Server password :'******'ascii') wapt = common.Wapt(config_filename=waptconfigfile, disable_update_server_status=True) wapt.dbpath = r':memory:' wapt.use_hostpackages = False if sign_digests is None: sign_digests = wapt.sign_digests if not wapt.personal_certificate_path or not os.path.isfile( wapt.personal_certificate_path): raise Exception( u'No personal certificate provided or not found (%s) for signing waptupgrade package' % wapt.personal_certificate_path) waptget = get_file_properties('wapt-get.exe') entry = PackageEntry(waptfile=makepath(wapt.wapt_base_dir, 'waptupgrade')) patchs_dir = makepath(entry.sourcespath, 'patchs') mkdirs(patchs_dir) filecopyto(makepath(wapt.wapt_base_dir, 'waptdeploy.exe'), makepath(patchs_dir, 'waptdeploy.exe')) entry.package = '%s-waptupgrade' % wapt.config.get( 'global', 'default_package_prefix') rev = entry.version.split('-')[1] entry.version = '%s-%s' % (waptget['FileVersion'], rev) entry.inc_build() entry.save_control_to_wapt() entry.build_package(target_directory=target_directory) certs = wapt.personal_certificate() key = wapt.private_key(private_key_password=key_password) if not certs[0].is_code_signing: raise Exception(u'%s is not a code signing certificate' % wapt.personal_certificate_path) entry.sign_package(private_key=key, certificate=certs, private_key_password=key_password, mds=ensure_list(sign_digests)) wapt.http_upload_package(entry.localpath, wapt_server_user=wapt_server_user, wapt_server_passwd=wapt_server_passwd) return entry.as_dict()
def build_waptupgrade_package(waptconfigfile,target_directory=None,wapt_server_user=None,wapt_server_passwd=None,key_password=None,sign_digests=None,priority='critical'): if target_directory is None: target_directory = tempfile.gettempdir() if not wapt_server_user: wapt_server_user = raw_input('WAPT Server user :'******'WAPT Server password :'******'ascii') wapt = common.Wapt(config_filename=waptconfigfile,disable_update_server_status=True) wapt.dbpath = r':memory:' wapt.use_hostpackages = False # try to get a progress hook inside waptconsole try: import waptconsole progress_hook = waptconsole.UpdateProgress except ImportError: def print_progress(show=False,n=0,max=100,msg=''): if show: print('%s %s/%s\r' % (msg,n,max),end='') else: if not msg: msg='Done' print("%s%s"%(msg,' '*(80-len(msg)))) progress_hook = print_progress wapt.progress_hook = progress_hook if sign_digests is None: sign_digests = wapt.sign_digests if not wapt.personal_certificate_path or not os.path.isfile(wapt.personal_certificate_path): raise Exception(u'No personal certificate provided or not found (%s) for signing waptupgrade package' % wapt.personal_certificate_path) waptget = get_file_properties('wapt-get.exe') entry = PackageEntry(waptfile = makepath(wapt.wapt_base_dir,'waptupgrade')) patchs_dir = makepath(entry.sourcespath,'patchs') mkdirs(patchs_dir) filecopyto(makepath(wapt.wapt_base_dir,'waptdeploy.exe'),makepath(patchs_dir,'waptdeploy.exe')) entry.package = '%s-waptupgrade' % wapt.config.get('global','default_package_prefix') rev = entry.version.split('-')[1] entry.version = '%s-%s' % (waptget['FileVersion'],rev) entry.inc_build() entry.save_control_to_wapt() entry.build_package(target_directory=target_directory) entry.priority = priority certs = wapt.personal_certificate() key = wapt.private_key(private_key_password=key_password) if not certs[0].is_code_signing: raise Exception(u'%s is not a code signing certificate' % wapt.personal_certificate_path) entry.sign_package(private_key=key,certificate = certs,private_key_password=key_password,mds = ensure_list(sign_digests)) wapt.http_upload_package(entry.localpath,wapt_server_user=wapt_server_user,wapt_server_passwd=wapt_server_passwd,progress_hook=progress_hook) return entry.as_dict()
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 set_app_ico(lpi_path, edition): (lpi_rootname, lpi_ext) = os.path.splitext(lpi_path) appico_path = lpi_rootname + '.ico' if not lpi_rootname.endswith('waptself'): source_ico = setuphelpers.makepath(wapt_root_dir, 'wapt-%s.ico' % edition) if not os.path.isfile(source_ico): source_ico = setuphelpers.makepath(wapt_root_dir, 'wapt.ico') else: source_ico = setuphelpers.makepath(wapt_root_dir, 'waptself', 'waptself-%s.ico' % edition.lower()) if not os.path.isfile(source_ico): source_ico = setuphelpers.makepath(wapt_root_dir, 'waptself', 'waptself-community.ico') setuphelpers.filecopyto(source_ico, appico_path)
def build_waptupgrade_package(wapt, mainrepo, sources_directory=None, target_directory=None, wapt_server_user=None, wapt_server_passwd=None, key_password=None, sign_digests=None, priority='critical'): if target_directory is None: target_directory = tempfile.gettempdir() if not wapt_server_user: wapt_server_user = raw_input('WAPT Server user :'******'WAPT Server password :'******'ascii') if sign_digests is None: sign_digests = wapt.sign_digests if not wapt.personal_certificate_path or not os.path.isfile( wapt.personal_certificate_path): raise Exception( u'No personal certificate provided or not found (%s) for signing waptupgrade package' % wapt.personal_certificate_path) waptget = get_file_properties('wapt-get.exe') if sources_directory is None: sources_directory = makepath(wapt.wapt_base_dir, 'waptupgrade') entry = PackageEntry(waptfile=sources_directory) patchs_dir = makepath(entry.sourcespath, 'patchs') mkdirs(patchs_dir) filecopyto(makepath(wapt.wapt_base_dir, 'waptdeploy.exe'), makepath(patchs_dir, 'waptdeploy.exe')) mainrepo.update() entry.package = '%s-waptupgrade' % wapt.config.get( 'global', 'default_package_prefix') existing = mainrepo.packages_matching(PackageRequest(entry.package)) if existing: rev = sorted(existing)[-1].version.split('-')[1] else: rev = entry.version.split('-')[1] entry.version = '%s-%s' % (waptget['FileVersion'], rev) entry.inc_build() entry.priority = priority entry.save_control_to_wapt() entry.build_package(target_directory=target_directory) certs = wapt.personal_certificate() key = wapt.private_key(private_key_password=key_password) if not certs[0].is_code_signing: raise Exception(u'%s is not a code signing certificate' % wapt.personal_certificate_path) entry.sign_package(private_key=key, certificate=certs, private_key_password=key_password, mds=ensure_list(sign_digests)) wapt.http_upload_package(entry.localpath, wapt_server_user=wapt_server_user, wapt_server_passwd=wapt_server_passwd, progress_hook=wapt.progress_hook) mainrepo.update() return entry.as_dict()
def duplicate_from_file(package_filename, new_prefix='test', target_directory=None, authorized_certs=None, set_maturity=None): r"""Duplicate a downloaded package to match prefix defined in waptconfigfile renames all dependencies Returns: str: source directory >>> from common import Wapt >>> wapt = Wapt(config_filename = r'C:\Users\htouvet\AppData\Local\waptconsole\waptconsole.ini') >>> sources = duplicate_from_external_repo(wapt.config_filename,r'C:\tranquilit\wapt\tests\packages\tis-wapttest.wapt') >>> res = wapt.build_upload(sources,wapt_server_user='******',wapt_server_passwd='password') >>> res[0]['package'].depends u'test-wapttestsub,test-7zip' """ def rename_package(oldname, prefix): sp = oldname.split('-', 1) if len(sp) == 2: return "%s-%s" % (prefix, sp[-1]) else: return oldname source_package = PackageEntry(waptfile=package_filename) # authorized_certs is a directoyr instead a list of certificates. if authorized_certs is not None and authorized_certs != '' and not isinstance( authorized_certs, list): bundle = SSLCABundle() bundle.add_pems(makepath(authorized_certs, '*.crt'), trust_first=True) bundle.add_pems(makepath(authorized_certs, '*.cer'), trust_first=True) bundle.add_pems(makepath(authorized_certs, '*.pem'), trust_all=True) else: bundle = authorized_certs or None source_package.unzip_package(target_dir=target_directory, cabundle=bundle) source_package.invalidate_signature() package = PackageEntry(waptfile=source_package.sourcespath) oldname = source_package.package package.package = rename_package(oldname, new_prefix) package.inc_build() if set_maturity is not None: package.maturity = set_maturity result = package['sourcespath'] # renames dependencies if package.depends: newdepends = [] depends = ensure_list(package.depends) for dependname in depends: newname = rename_package(dependname, new_prefix) newdepends.append(newname) package.depends = ','.join(newdepends) # renames conflicts if package.conflicts: newconflicts = [] conflicts = ensure_list(package.conflicts) for dependname in conflicts: newname = rename_package(dependname, new_prefix) newconflicts.append(newname) package.conflicts = ','.join(newconflicts) package.save_control_to_wapt() 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
def duplicate_from_file(package_filename,new_prefix='test',target_directory=None,authorized_certs=None,set_maturity=None): r"""Duplicate a downloaded package to match prefix defined in waptconfigfile renames all dependencies Returns: str: source directory >>> from common import Wapt >>> wapt = Wapt(config_filename = r'C:\Users\htouvet\AppData\Local\waptconsole\waptconsole.ini') >>> sources = duplicate_from_external_repo(wapt.config_filename,r'C:\tranquilit\wapt\tests\packages\tis-wapttest.wapt') >>> res = wapt.build_upload(sources,wapt_server_user='******',wapt_server_passwd='password') >>> res[0]['package'].depends u'test-wapttestsub,test-7zip' """ def rename_package(oldname,prefix): sp = oldname.split('-',1) if len(sp) == 2: return "%s-%s" % (prefix,sp[-1]) else: return oldname source_package = PackageEntry(waptfile = package_filename) # authorized_certs is a directoyr instead a list of certificates. if authorized_certs is not None and authorized_certs != '' and not isinstance(authorized_certs,list): bundle = SSLCABundle() bundle.add_pems(makepath(authorized_certs,'*.crt')) bundle.add_pems(makepath(authorized_certs,'*.cer')) bundle.add_pems(makepath(authorized_certs,'*.pem')) else: bundle = authorized_certs or None source_package.unzip_package(target_dir=target_directory,cabundle=bundle) source_package.invalidate_signature() package = PackageEntry(waptfile = source_package.sourcespath) oldname = source_package.package package.package = rename_package(oldname,new_prefix) package.inc_build() if set_maturity is not None: package.maturity = set_maturity result = package['sourcespath'] # renames dependencies if package.depends: newdepends = [] depends = ensure_list(package.depends) for dependname in depends: newname = rename_package(dependname,new_prefix) newdepends.append(newname) package.depends = ','.join(newdepends) # renames conflicts if package.conflicts: newconflicts = [] conflicts = ensure_list(package.conflicts) for dependname in conflicts: newname = rename_package(dependname,new_prefix) newconflicts.append(newname) package.conflicts = ','.join(newconflicts) package.save_control_to_wapt() return result