def Install(self, build_deps, force=None, from_source=False): self.CheckInstallable() if force is None and self.IsInstalled(): self.LogStatus('Already installed') return if build_deps: self.InstallDeps(force, from_source) if force: from_source = True package_file = self.PackageFile() if not self.IsBuilt() and not from_source: index = package_index.GetCurrentIndex() if index.Installable(self.NAME, self.config): package_file = index.Download(self.NAME, self.config) else: from_source = True if from_source: self.Build(build_deps, force) if self.IsAnyVersionInstalled(): installed_pkg = self.GetInstalledPackage() installed_pkg.LogStatus('Uninstalling existing') installed_pkg.DoUninstall() binary_package.BinaryPackage(package_file).Install()
def IsBuilt(self): package_file = self.PackageFile() if not os.path.exists(package_file): return False try: pkg = binary_package.BinaryPackage(package_file) except PkgFormatError: # If the package is malformed in some way or in some old format # then treat it as not built. return False return pkg.IsInstallable()
def testWriteStamp(self, mock_get_info): fake_binary_pkg_info = textwrap.dedent('''\ NAME=foo VERSION=1.0 BUILD_CONFIG=release BUILD_ARCH=arm BUILD_TOOLCHAIN=glibc BUILD_SDK_VERSION=38 BUILD_NACLPORTS_REVISION=1414 ''') mock_get_info.return_value = fake_binary_pkg_info pkg = binary_package.BinaryPackage('foo') mock_stamp_file = common.MockFileObject() with patch('__builtin__.open', Mock(return_value=mock_stamp_file), create=True): pkg.WriteStamp() mock_stamp_file.write.assert_called_once_with(fake_binary_pkg_info)
def ExtractPkgInfo(filename): """Return the pkg_info contents from a binary package.""" pkg = binary_package.BinaryPackage(filename) return pkg.GetPkgInfo()