Exemplo n.º 1
0
def completedir(dir, url, flag = Event(), vc = dummy, fc = dummy, piece_len_pow2 = None):
    files = listdir(dir)
    files.sort()
    ext = '.torrent'

    togen = []
    for f in files:
        if f[-len(ext):] != ext and (f + ext) not in files:
            togen.append(join(dir, f))
        
    total = 0
    for i in togen:
        total += calcsize(i)

    subtotal = [0]
    def callback(x, subtotal = subtotal, total = total, vc = vc):
        subtotal[0] += x
        vc(float(subtotal[0]) / total)
    for i in togen:
        fc(i)
        try:
            t = split(i)[-1] 
            if t not in ignore and t[0] != '.':
                make_meta_file(i, url, flag = flag, progress = callback, progress_percent=0, piece_len_exp = piece_len_pow2)
        except ValueError:
            print_exc()
def completedir(files, url, flag = Event(), vc = dummy, fc = dummy, piece_len_pow2 = None):
    files.sort()
    ext = '.torrent'

    togen = []
    for f in files:
        if f[-len(ext):] != ext:
            togen.append(f)
        
    total = 0
    for i in togen:
        total += calcsize(i)

    subtotal = [0]
    def callback(x, subtotal = subtotal, total = total, vc = vc):
        subtotal[0] += x
        vc(float(subtotal[0]) / total)
    for i in togen:
        t = split(i)
        if t[1] == '':
            i = t[0]
        fc(i)
        try:
            make_meta_file(i, url, flag = flag, progress = callback, progress_percent=0, piece_len_exp = piece_len_pow2)
        except ValueError:
            print_exc()
Exemplo n.º 3
0
    def _getFileListing(self, basepath):        
        self.filechecklist.DeleteAllItems()
        
        self.files = []
        self.filemap = {}
        self.isdir = isdir(basepath)
        
        totalsize = 0L
                
        if self.isdir:
            root = self.filechecklist.AddRoot(basepath, ct_type = 1)
            self.filechecklist.SetPyData(root, None)
            
            self.filechecklist.SetItemImage(root, self.images['folder'], which = wx.TreeItemIcon_Normal)
            self.filechecklist.SetItemImage(root, self.images['folder_open'], which = wx.TreeItemIcon_Expanded)
            
            subs = subfiles(basepath)
            subs.sort()
            
            alreadypresent = {}
            
            for patharray, fullpath in subs:
                size = calcsize(fullpath)
                
                relativepath = u""
                firstpart = True
                addto = self.filechecklist.GetRootItem()
                # Add directories first
                if len(patharray) > 1:
                    for index in range(len(patharray) - 1):
                        part = patharray[index]
    
                        relativepath += "\\" + part
                        
                        if not relativepath in alreadypresent:
                            newitem = self.filechecklist.AppendItem(addto, part, ct_type = 1)
                            self.filechecklist.SetPyData(newitem, None)
                            
                            self.filechecklist.SetItemImage(newitem, self.images['folder'], which = wx.TreeItemIcon_Normal)
                            self.filechecklist.SetItemImage(newitem, self.images['folder_open'], which = wx.TreeItemIcon_Expanded)
                            alreadypresent[relativepath] = newitem
                        
                        addto = alreadypresent[relativepath]

                self.files.append((patharray, fullpath, patharray[-1], size, addto))
                
            # Add files after adding directories
            for index in range(len(self.files)):
                patharray, fullpath, filename, size, addto = self.files[index]
                # Only show size for individual items
                
                newitem = self.filechecklist.AppendItem(addto, filename, ct_type = 1)
                self.filemap[index] = newitem
                
                self.filechecklist.SetPyData(newitem, None)
                
                self.filechecklist.SetItemImage(newitem, self.images['file'], which = wx.TreeItemIcon_Normal)
                
            sizelabel = _('Archive Size') + " :"
            
            self.filechecklist.CheckItem(root, True)
        else:
            # Single file
            root = self.filechecklist.AddRoot(basepath)
            self.filechecklist.SetPyData(root, None)
            
            self.filechecklist.SetItemImage(root, self.images['file'], which = wx.TreeItemIcon_Normal)
            
            size = calcsize(basepath)
            self.files = [([], basepath, basepath, size, None)]
            self.filemap[0] = root

            sizelabel = _('File size') + " :"
        
        self.filechecklist.Expand(root)
        
        self.sizelabel.SetLabel(sizelabel)
        
        self._uncheckIgnoredFiles()
        
        self._calcTotalSize()