Example #1
0
 def __init__(self,
              dest_dir,
              log,
              pkg_dirs=None,
              no_download=False,
              copy_files=False):
     from bootstrap import Downloader
     self.dest_dir = dest_dir
     self.log = log
     self.pkg_dirs = pkg_dirs
     self.no_download = no_download
     self.copy_files = copy_files
     self.downloader = Downloader()
Example #2
0
 def __init__ (self, dest_dir, log, pkg_dirs=None, no_download=False,
     copy_files=False) :
   from bootstrap import Downloader
   self.dest_dir = dest_dir
   self.log = log
   self.pkg_dirs = pkg_dirs
   self.no_download = no_download
   self.copy_files = copy_files
   self.downloader = Downloader()
Example #3
0
class fetch_packages (object) :
  """
  Download manager for the packages defined by this module - this is used by
  install_base_packages.py but also for setting up installer bundles.
  """
  def __init__ (self, dest_dir, log, pkg_dirs=None, no_download=False,
      copy_files=False) :
    from bootstrap import Downloader
    self.dest_dir = dest_dir
    self.log = log
    self.pkg_dirs = pkg_dirs
    self.no_download = no_download
    self.copy_files = copy_files
    self.downloader = Downloader()

  def __call__ (self,
                pkg_name,
                pkg_url=None,
                output_file=None,
                return_file_and_status=False,
                ) :
    if (pkg_url is None) :
      pkg_url = BASE_CCI_PKG_URL
    if (output_file is None) :
      output_file = pkg_name
    os.chdir(self.dest_dir)
    print >> self.log, "  getting package %s..." % pkg_name
    if (self.pkg_dirs is not None) and (len(self.pkg_dirs) > 0) :
      for pkg_dir in self.pkg_dirs :
        static_file = op.join(pkg_dir, pkg_name)
        if (op.exists(static_file)) :
          print >> self.log, "    using %s" % static_file
          if self.copy_files :
            copy_file(static_file, op.join(self.dest_dir, output_file))
            if return_file_and_status:
              return op.join(self.dest_dir, output_file), 0
            return op.join(self.dest_dir, output_file)
          else :
            if return_file_and_status:
              return static_file, 0
            return static_file
    if (self.no_download) :
      if (op.exists(pkg_name)) :
        print >> self.log, "    using ./%s" % pkg_name
        if return_file_and_status:
          return op.join(self.dest_dir, output_file), 0
        return op.join(self.dest_dir, pkg_name)
      else :
        raise RuntimeError(("Package '%s' not found on local filesystems.  ") %
          pkg_name)
    full_url = "%s/%s" % (pkg_url, pkg_name)
    self.log.write("    downloading from %s : " % pkg_url)

    size = self.downloader.download_to_file(full_url, output_file, log=self.log)
    if (size == -2):
      print >> self.log, "    using ./%s (cached)" % pkg_name
      if return_file_and_status:
        return op.join(self.dest_dir, output_file), size
      return op.join(self.dest_dir, output_file)
    assert (size > 0), pkg_name
    if return_file_and_status:
      return op.join(self.dest_dir, output_file), size
    return op.join(self.dest_dir, output_file)
Example #4
0
class fetch_packages(object):
    """
  Download manager for the packages defined by this module - this is used by
  install_base_packages.py but also for setting up installer bundles.
  """
    def __init__(self,
                 dest_dir,
                 log,
                 pkg_dirs=None,
                 no_download=False,
                 copy_files=False):
        from bootstrap import Downloader
        self.dest_dir = dest_dir
        self.log = log
        self.pkg_dirs = pkg_dirs
        self.no_download = no_download
        self.copy_files = copy_files
        self.downloader = Downloader()

    def __call__(self, pkg_name, pkg_url=None, output_file=None):
        if (pkg_url is None):
            pkg_url = BASE_CCI_PKG_URL
        if (output_file is None):
            output_file = pkg_name
        os.chdir(self.dest_dir)
        print >> self.log, "  getting package %s..." % pkg_name
        if (self.pkg_dirs is not None) and (len(self.pkg_dirs) > 0):
            for pkg_dir in self.pkg_dirs:
                static_file = op.join(pkg_dir, pkg_name)
                if (op.exists(static_file)):
                    print >> self.log, "    using %s" % static_file
                    if self.copy_files:
                        copy_file(static_file,
                                  op.join(self.dest_dir, output_file))
                        return op.join(self.dest_dir, output_file)
                    else:
                        return static_file
        if (self.no_download):
            if (op.exists(pkg_name)):
                print >> self.log, "    using ./%s" % pkg_name
                return op.join(self.dest_dir, pkg_name)
            else:
                raise RuntimeError(
                    ("Package '%s' not found on local filesystems.  ") %
                    pkg_name)
        full_url = "%s/%s" % (pkg_url, pkg_name)
        self.log.write("    downloading from %s : " % pkg_url)
        try:
            size = self.downloader.download_to_file(full_url,
                                                    output_file,
                                                    log=self.log)
        except urllib2.HTTPError, err:
            print >> self.log, err
            if (op.exists(pkg_name)):
                print >> self.log, "    using ./%s" % pkg_name
                return op.join(self.dest_dir, pkg_name)
            else:
                raise

        if (size == -2):
            print >> self.log, "    using ./%s (cached)" % pkg_name
            return op.join(self.dest_dir, output_file)
        assert (size > 0), pkg_name
        return op.join(self.dest_dir, output_file)