def repackage_installer(topsrcdir, tag, setupexe, package, output): if package and not zipfile.is_zipfile(package): raise Exception("Package file %s is not a valid .zip file." % package) # We need the full path for the tag and output, since we chdir later. tag = mozpath.realpath(tag) output = mozpath.realpath(output) ensureParentDir(output) tmpdir = tempfile.mkdtemp() old_cwd = os.getcwd() try: if package: z = zipfile.ZipFile(package) z.extractall(tmpdir) z.close() # Copy setup.exe into the root of the install dir, alongside the # package. shutil.copyfile(setupexe, mozpath.join(tmpdir, mozpath.basename(setupexe))) # archive_exe requires us to be in the directory where the package is # unpacked (the tmpdir) os.chdir(tmpdir) sfx_package = mozpath.join(topsrcdir, 'other-licenses/7zstub/firefox/7zSD.sfx') package_name = 'firefox' if package else None archive_exe(package_name, tag, sfx_package, output) finally: os.chdir(old_cwd) shutil.rmtree(tmpdir)
def include_file(self, path): '''Include one file in the sandbox. Users of this class probably want to use `run` instead. Note: this will execute all template invocations, as well as @depends functions that depend on '--help', but nothing else. ''' if self._paths: path = mozpath.join(mozpath.dirname(self._paths[-1]), path) path = mozpath.normpath(path) if not mozpath.basedir(path, (mozpath.dirname(self._paths[0]),)): raise ConfigureError( 'Cannot include `%s` because it is not in a subdirectory ' 'of `%s`' % (path, mozpath.dirname(self._paths[0]))) else: path = mozpath.realpath(mozpath.abspath(path)) if path in self._all_paths: raise ConfigureError( 'Cannot include `%s` because it was included already.' % path) self._paths.append(path) self._all_paths.add(path) source = open(path, 'rb').read() code = compile(source, path, 'exec') exec_(code, self) self._paths.pop(-1)
def include_file(self, path): '''Include one file in the sandbox. Users of this class probably want Note: this will execute all template invocations, as well as @depends functions that depend on '--help', but nothing else. ''' if self._paths: path = mozpath.join(mozpath.dirname(self._paths[-1]), path) path = mozpath.normpath(path) if not mozpath.basedir(path, (mozpath.dirname(self._paths[0]),)): raise ConfigureError( 'Cannot include `%s` because it is not in a subdirectory ' 'of `%s`' % (path, mozpath.dirname(self._paths[0]))) else: path = mozpath.realpath(mozpath.abspath(path)) if path in self._all_paths: raise ConfigureError( 'Cannot include `%s` because it was included already.' % path) self._paths.append(path) self._all_paths.add(path) source = open(path, 'rb').read() code = compile(source, path, 'exec') exec_(code, self) self._paths.pop(-1)
def exec_file(self, path): '''Execute one file within the sandbox. Users of this class probably want to use `run` instead.''' if self._paths: path = mozpath.join(mozpath.dirname(self._paths[-1]), path) if not mozpath.basedir(path, (mozpath.dirname(self._paths[0]),)): raise ConfigureError( 'Cannot include `%s` because it is not in a subdirectory ' 'of `%s`' % (path, mozpath.dirname(self._paths[0]))) else: path = mozpath.realpath(mozpath.abspath(path)) if path in self._paths: raise ConfigureError( 'Cannot include `%s` because it was included already.' % path) self._paths.append(path) source = open(path, 'rb').read() code = compile(source, path, 'exec') exec(code, self) self._paths.pop(-1)
def exec_file(self, path): '''Execute one file within the sandbox. Users of this class probably want to use `run` instead.''' if self._paths: path = mozpath.join(mozpath.dirname(self._paths[-1]), path) if not mozpath.basedir(path, (mozpath.dirname(self._paths[0]), )): raise ConfigureError( 'Cannot include `%s` because it is not in a subdirectory ' 'of `%s`' % (path, mozpath.dirname(self._paths[0]))) else: path = mozpath.realpath(mozpath.abspath(path)) if path in self._paths: raise ConfigureError( 'Cannot include `%s` because it was included already.' % path) self._paths.append(path) source = open(path, 'rb').read() code = compile(source, path, 'exec') exec(code, self) self._paths.pop(-1)
def repackage_msi(topsrcdir, wsx, version, locale, arch, setupexe, candle, light, output): if sys.platform != 'win32': raise Exception("repackage msi only works on windows") if not os.path.isdir(topsrcdir): raise Exception("%s does not exist." % topsrcdir) if not os.path.isfile(wsx): raise Exception("%s does not exist." % wsx) if version is None: raise Exception("version name must be provided.") if locale is None: raise Exception("locale name must be provided.") if arch is None or arch not in _MSI_ARCH.keys(): raise Exception("arch name must be provided and one of {}.".format( _MSI_ARCH.keys())) if not os.path.isfile(setupexe): raise Exception("%s does not exist." % setupexe) if candle is not None and not os.path.isfile(candle): raise Exception("%s does not exist." % candle) if light is not None and not os.path.isfile(light): raise Exception("%s does not exist." % light) embeddedVersion = '0.0.0.0' # Version string cannot contain 'a' or 'b' when embedding in msi manifest. if 'a' not in version and 'b' not in version: if version.endswith('esr'): parts = version[:-3].split('.') else: parts = version.split('.') while len(parts) < 4: parts.append('0') embeddedVersion = '.'.join(parts) wsx = mozpath.realpath(wsx) setupexe = mozpath.realpath(setupexe) output = mozpath.realpath(output) ensureParentDir(output) if sys.platform == 'win32': tmpdir = tempfile.mkdtemp() old_cwd = os.getcwd() try: wsx_file = os.path.split(wsx)[1] shutil.copy(wsx, tmpdir) temp_wsx_file = os.path.join(tmpdir, wsx_file) temp_wsx_file = mozpath.realpath(temp_wsx_file) pre_values = { 'Vendor': 'Mozilla', 'BrandFullName': 'Mozilla Firefox', 'Version': version, 'AB_CD': locale, 'Architecture': _MSI_ARCH[arch], 'ExeSourcePath': setupexe, 'EmbeddedVersionCode': embeddedVersion } # update wsx file with inputs from newfile = update_wsx(temp_wsx_file, pre_values) wix_object_file = os.path.join(tmpdir, 'installer.wixobj') env = os.environ.copy() if candle is None: candle = 'candle.exe' cmd = [candle, '-out', wix_object_file, newfile] subprocess.check_call(cmd, env=env) wix_installer = wix_object_file.replace(".wixobj", ".msi") if light is None: light = 'light.exe' light_cmd = [ light, "-cultures:neutral", "-sw1076", "-sw1079", '-out', wix_installer, wix_object_file ] subprocess.check_call(light_cmd, env=env) os.remove(wix_object_file) # mv file to output dir shutil.move(wix_installer, output) finally: os.chdir(old_cwd) shutil.rmtree(tmpdir)
def repackage_msi(topsrcdir, wsx, version, locale, arch, setupexe, candle, light, output): if sys.platform != 'win32': raise Exception("repackage msi only works on windows") if not os.path.isdir(topsrcdir): raise Exception("%s does not exist." % topsrcdir) if not os.path.isfile(wsx): raise Exception("%s does not exist." % wsx) if version is None: raise Exception("version name must be provided.") if locale is None: raise Exception("locale name must be provided.") if arch is None or arch not in ['x86', 'x64']: raise Exception("arch name must be provided and either x86 or x64.") if not os.path.isfile(setupexe): raise Exception("%s does not exist." % setupexe) if candle is not None and not os.path.isfile(candle): raise Exception("%s does not exist." % candle) if light is not None and not os.path.isfile(light): raise Exception("%s does not exist." % light) wsx = mozpath.realpath(wsx) setupexe = mozpath.realpath(setupexe) output = mozpath.realpath(output) ensureParentDir(output) if sys.platform == 'win32': tmpdir = tempfile.mkdtemp() old_cwd = os.getcwd() try: wsx_file = os.path.split(wsx)[1] shutil.copy(wsx, tmpdir) temp_wsx_file = os.path.join(tmpdir, wsx_file) temp_wsx_file = mozpath.realpath(temp_wsx_file) pre_values = { 'Vendor': 'Mozilla', 'BrandFullName': 'Mozilla Firefox', 'Version': version, 'AB_CD': locale, 'Architecture': arch, 'ExeSourcePath': setupexe } # update wsx file with inputs from newfile = update_wsx(temp_wsx_file, pre_values) wix_object_file = os.path.join(tmpdir, 'installer.wixobj') env = os.environ.copy() if candle is None: candle = 'candle.exe' cmd = [candle, '-out', wix_object_file, newfile] subprocess.check_call(cmd, env=env) wix_installer = wix_object_file.replace(".wixobj", ".msi") if light is None: light = 'light.exe' light_cmd = [ light, "-cultures:neutral", "-sw1076", "-sw1079", '-out', wix_installer, wix_object_file ] subprocess.check_call(light_cmd, env=env) os.remove(wix_object_file) #mv file to output dir shutil.move(wix_installer, output) finally: os.chdir(old_cwd) shutil.rmtree(tmpdir)