コード例 #1
0
ファイル: __main__.py プロジェクト: pvk84/naclports
def CmdPkgUscan(package, options):
    """Use Debian's 'uscan' to check for upstream versions."""
    if not package.URL:
        return 0

    if package.VERSION not in package.URL:
        PrintError('%s: uscan only works if VERSION is embedded in URL' %
                   package.NAME)
        return 0

    temp_fd, temp_file = tempfile.mkstemp('naclports_watchfile')
    try:
        with os.fdopen(temp_fd, 'w') as f:
            uscan_url = package.URL.replace(package.VERSION, '(.+)')
            uscan_url = uscan_url.replace('download.sf.net', 'sf.net')
            util.LogVerbose('uscan pattern: %s' % uscan_url)
            f.write("version = 3\n")
            f.write("%s\n" % uscan_url)

        cmd = [
            'uscan', '--upstream-version', package.VERSION, '--package',
            package.NAME, '--watchfile', temp_file
        ]
        util.LogVerbose(' '.join(cmd))
        rtn = subprocess.call(cmd)
    finally:
        os.remove(temp_file)

    return rtn
コード例 #2
0
 def WriteStamp(self):
     """Write stamp file containing pkg_info."""
     filename = util.GetInstallStamp(self.NAME, self.config)
     util.LogVerbose('stamp: %s' % filename)
     pkg_info = self.GetPkgInfo()
     with open(filename, 'w') as f:
         f.write(pkg_info)
コード例 #3
0
 def Installable(self, package_name, config):
     """Returns True if the index contains the given package and it is
 installable in the currently configured SDK."""
     info = self.packages.get((package_name, config))
     if not info:
         return False
     version = util.GetSDKVersion()
     if info['BUILD_SDK_VERSION'] != version:
         util.LogVerbose(
             'Prebuilt package was built with different SDK version: '
             '%s vs %s' % (info['BUILD_SDK_VERSION'], version))
         return False
     return True
コード例 #4
0
    def _InstallFiles(self, force):
        dest = util.GetInstallRoot(self.config)
        dest_tmp = os.path.join(dest, 'install_tmp')
        if os.path.exists(dest_tmp):
            shutil.rmtree(dest_tmp)

        if self.IsAnyVersionInstalled():
            raise error.Error('package already installed: %s' %
                              self.InfoString())

        self.LogStatus('Installing')
        util.LogVerbose('installing from: %s' % self.filename)
        util.Makedirs(dest_tmp)

        names = []
        try:
            with tarfile.open(self.filename) as tar:
                for info in tar:
                    if info.isdir():
                        continue
                    name = posixpath.normpath(info.name)
                    if name == 'pkg_info':
                        continue
                    if not name.startswith(PAYLOAD_DIR + '/'):
                        raise error.PkgFormatError(
                            'invalid file in package: %s' % name)

                    name = name[len(PAYLOAD_DIR) + 1:]
                    names.append(name)

                if not force:
                    for name in names:
                        full_name = os.path.join(dest, name)
                        if os.path.exists(full_name):
                            raise error.Error('file already exists: %s' %
                                              full_name)

                tar.extractall(dest_tmp)
                payload_tree = os.path.join(dest_tmp, PAYLOAD_DIR)

                names = FilterOutExecutables(names, payload_tree)

                for name in names:
                    InstallFile(name, payload_tree, dest)
        finally:
            shutil.rmtree(dest_tmp)

        for name in names:
            RelocateFile(name, dest)

        self.WriteFileList(names)
コード例 #5
0
def InstallFile(filename, old_root, new_root):
    """Install a single file by moving it into a new location.

  Args:
    filename: Relative name of file to install.
    old_root: The current location of the file.
    new_root: The new desired root for the file.
  """
    oldname = os.path.join(old_root, filename)

    util.LogVerbose('install: %s' % filename)

    newname = os.path.join(new_root, filename)
    dirname = os.path.dirname(newname)
    if not os.path.isdir(dirname):
        util.Makedirs(dirname)
    os.rename(oldname, newname)
コード例 #6
0
ファイル: installed_package.py プロジェクト: pvk84/naclports
  def DoUninstall(self, force):
    with util.InstallLock(self.config):
      if not force:
        for pkg in InstalledPackageIterator(self.config):
          if self.NAME in pkg.DEPENDS:
            raise error.Error("Unable to uninstall '%s' (depended on by '%s')" %
                (self.NAME, pkg.NAME))
      RemoveFile(self.GetInstallStamp())

      root = util.GetInstallRoot(self.config)
      for filename in self.Files():
        fullname = os.path.join(root, filename)
        if not os.path.lexists(fullname):
          util.Warn('File not found while uninstalling: %s' % fullname)
          continue
        util.LogVerbose('uninstall: %s' % filename)
        RemoveFile(fullname)

      if os.path.exists(self.GetListFile()):
        RemoveFile(self.GetListFile())
コード例 #7
0
def InstallFile(filename, old_root, new_root):
    """Install a single file by moving it into a new location.

  Args:
    filename: Relative name of file to install.
    old_root: The current location of the file.
    new_root: The new desired root for the file.
  """
    oldname = os.path.join(old_root, filename)

    util.LogVerbose('install: %s' % filename)

    newname = os.path.join(new_root, filename)
    dirname = os.path.dirname(newname)
    if not os.path.isdir(dirname):
        util.Makedirs(dirname)
    os.rename(oldname, newname)

    # When install binaries ELF files into the toolchain direcoties, remove
    # the X bit so that they do not found when searching the PATH.
    if util.IsElfFile(newname) or util.IsPexeFile(newname):
        mode = os.stat(newname).st_mode
        mode = mode & ~(stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
        os.chmod(newname, mode)