示例#1
0
 def on_apply_changes(self):
     
     directory = os.path.join(self.download_directory, "packages")
     
     # Build the list of package urls to download
     downloads = [(key, value["Repository"]["url"].split("dists")[0] + value["Filename"]) \
                  for key, value in self.status.items() \
                  if value["Status"] in ["to be downloaded", "dependency to be downloaded"]]
     
     #downloads = []
     #for key, value in self.status.items():
     #    if value["Status"] == "to be downloaded":
     #        downloads.append(value["Repository"]["url"].split("dists")[0] + value["Filename"])
             
     logging.info("%i packages to be installed" % len(downloads))
     
     # Create the download directory if it doesn't exist
     if not os.path.exists(directory):
         os.mkdir(directory)
     
     # Download the files
     for key, url in downloads:
         download_url(url, 
                      "%s/%s" % (directory, url.rsplit("/", 1)[1]), 
                      proxy=self.proxy["proxy"], 
                      username=self.proxy["user"], 
                      password=self.proxy["pass"])
         # Once it's downloaded, mark this package status to "to be installed"
         # or "dependency to be installed", depending on what it is now.
         if self.status[key]["Status"] == "to be downloaded":
             self.status[key]["Status"] = "to be installed"
         elif self.status[key]["Status"] == "dependency to be downloaded":
             self.status[key]["Status"] = "dependency to be installed"
示例#2
0
    def _download_lists(self, reporthook=None):
        """
            on_update helper function
        """
        
        if not reporthook:
            reporthook = textprogress
        
        directory = os.path.join(self.download_directory, "lists")

        # If the download directory does not exist, create it
        if not os.path.exists(directory):
            os.makedirs(directory)

        for repo in self.__iter_repositories():

            # Build the strings
            url = to_url(repo, self.architecture, "Packages")
            filename = to_filename(directory, url)
            display_name = "Repository => %s / %s" % (repo["dist"], repo["section"])

            # Download
            #TODO: catch exceptions
            #TODO: Support bz2 and unarchived Packages files
            filename = "%s.gz" % filename
            download_url("%s.gz" % url, 
                         filename, 
                         display_name, 
                         progress=reporthook,
                         proxy=self.proxy["proxy"], 
                         username=self.proxy["user"], 
                         password=self.proxy["pass"])