Beispiel #1
0
    def add_download(self, pkg_name, action_type, simulate=False):
        installed = self.get_pkg_installed(pkg_name)
        if installed == 1:
            self.update_signal([("pkg-installed", (pkg_name, action_type))])
            return
        elif installed == -1:
            self.update_signal([("pkg-not-in-cache", (pkg_name, action_type))])
            return
        pkg_infos = get_pkg_download_info(self.pkg_cache, pkg_name)
        status = pkg_infos["status"]
        self.update_signal([("ready-download-finish", (pkg_name, action_type))])
        if status == DOWNLOAD_STATUS_NOTNEED:
            self.download_finish(pkg_name, action_type, [pkg_name,])
        elif status == DOWNLOAD_STATUS_ERROR:
            self.update_signal([("parse-download-error", (pkg_name, action_type))])
        else:
            names = []
            download_urls = []
            download_hash_infos = []
            pkg_sizes = []
            for info in pkg_infos["info"]:
                names.append(info["name"])
                download_urls.append(info["url"])
                download_hash_infos.append(info["hash"])
                pkg_sizes.append(info["size"])

            self.download_manager.add_download(
                                        pkg_name,
                                        action_type,
                                        download_urls,
                                        download_sizes=pkg_sizes,
                                        download_md5s=download_hash_infos,
                                        all_task_names=[pkg_name],
                                        file_save_dir=self.download_dir
                                        )
 def get_download_size(self, pkg_name):
     total_size = 0
     pkg_infos = get_pkg_download_info(self.pkg_cache, pkg_name)
     if pkg_infos[0] == DOWNLOAD_STATUS_NOTNEED:
         total_size = get_pkg_own_size(self.pkg_cache, pkg_name)
         size_flag = PKG_SIZE_OWN
     elif pkg_infos[0] == DOWNLOAD_STATUS_ERROR:
         total_size = -1
         size_flag = PKG_SIZE_ERROR
     else:
         (names, download_urls, download_hash_infos, pkg_sizes) = pkg_infos
         for size in pkg_sizes:
             total_size += size
         size_flag = PKG_SIZE_DOWNLOAD
     return [size_flag, total_size]
Beispiel #3
0
 def get_download_size(self, pkg_name):
     total_size = 0
     pkg_infos = get_pkg_download_info(self.pkg_cache, pkg_name)
     status = pkg_infos["status"]
     if status == DOWNLOAD_STATUS_NOTNEED:
         total_size = get_pkg_own_size(self.pkg_cache, pkg_name)
         size_flag = PKG_SIZE_OWN
     elif status == DOWNLOAD_STATUS_ERROR:
         total_size = -1
         size_flag = PKG_SIZE_ERROR
     else:
         for info in pkg_infos["info"]:
             total_size += info["size"]
         size_flag = PKG_SIZE_DOWNLOAD
     return [size_flag, total_size]
Beispiel #4
0
 def get_download_size(self, pkg_name):
     total_size = 0
     pkg_infos = get_pkg_download_info(self.pkg_cache, pkg_name)
     status = pkg_infos["status"]
     if status == DOWNLOAD_STATUS_NOTNEED:
         total_size = get_pkg_own_size(self.pkg_cache, pkg_name)
         size_flag = PKG_SIZE_OWN
     elif status == DOWNLOAD_STATUS_ERROR:
         total_size = -1
         size_flag = PKG_SIZE_ERROR
     else:
         for info in pkg_infos["info"]:
             total_size += info["size"]
         size_flag = PKG_SIZE_DOWNLOAD
     return [size_flag, total_size]
 def add_download(self, pkg_name, action_type, simulate=False):
     pkg_infos = get_pkg_download_info(self.pkg_cache, pkg_name)
     self.update_signal([("ready-download-finish", (pkg_name, action_type))])
     if pkg_infos[0] == DOWNLOAD_STATUS_NOTNEED:
         self.download_finish(pkg_name, action_type, [pkg_name,])
         print "Don't need download"
     elif pkg_infos[0] == DOWNLOAD_STATUS_ERROR:
         self.update_signal([("parse-download-error", (pkg_name, action_type))])
         print "Download error"
     else:
         (names, download_urls, download_hash_infos, pkg_sizes) = pkg_infos
         
         self.download_manager.add_download(
                                     pkg_name, 
                                     action_type, 
                                     download_urls, 
                                     all_pkg_names=[pkg_name,],
                                     file_save_dir=self.download_dir)
Beispiel #6
0
    def add_download(self, pkg_name, action_type, simulate=False):
        installed = self.get_pkg_installed(pkg_name)
        if installed == 1:
            self.update_signal([("pkg-installed", (pkg_name, action_type))])
            return
        elif installed == -1:
            self.update_signal([("pkg-not-in-cache", (pkg_name, action_type))])
            return
        pkg_infos = get_pkg_download_info(self.pkg_cache, pkg_name)
        status = pkg_infos["status"]
        self.update_signal([("ready-download-finish", (pkg_name, action_type))
                            ])
        if status == DOWNLOAD_STATUS_NOTNEED:
            self.download_finish(pkg_name, action_type, [
                pkg_name,
            ])
        elif status == DOWNLOAD_STATUS_ERROR:
            self.update_signal([("parse-download-error", (pkg_name,
                                                          action_type))])
        else:
            names = []
            download_urls = []
            download_hash_infos = []
            pkg_sizes = []
            for info in pkg_infos["info"]:
                names.append(info["name"])
                download_urls.append(info["url"])
                download_hash_infos.append(info["hash"])
                pkg_sizes.append(info["size"])

            self.download_manager.add_download(
                pkg_name,
                action_type,
                download_urls,
                download_sizes=pkg_sizes,
                download_md5s=download_hash_infos,
                all_task_names=[pkg_name],
                file_save_dir=self.download_dir)
        
        return parent_dir

    sys.path.append(os.path.join(get_parent_dir(__file__, 3), "pkg_manager", "apt"))
    
    from parse_pkg import get_pkg_download_info
    from apt_cache import AptCache
    import gtk
    import apt_pkg
    
    gtk.gdk.threads_init()
    
    apt_pkg.init()
    cache = AptCache()
    pkg_name = "amarok"
    pkg_infos = get_pkg_download_info(cache, pkg_name)
    download_manager = DownloadManager(verbose=True)
    if pkg_infos != None:
        (names, download_urls, download_hash_infos, pkg_sizes) = pkg_infos
    
        download_manager.add_download(pkg_name, 1, False, download_urls, download_hash_infos, pkg_sizes)
        # download_manager.add_download(
        #     pkg_name, 
        #     ["http://test.packages.linuxdeepin.com/ubuntu/pool/main/k/kdepim/libkdepim4_4.8.5-0ubuntu0.1_amd64.deb"],
        #     None,
        #     None
        #     )
    
    gtk.main()