Example #1
0
    def _build_file_structs(self, filepool, files):
        total = 0
        for filename, length in files:
            self.undownloaded[filename] = length
            if length > 0:
                self.ranges.append((total, total + length, filename))

            self.range_by_name[filename] = (total, total + length)

            if os.path.exists(filename):
                if not os.path.isfile(filename):
                    raise BTFailure(_("File %s already exists, but is not a "
                                      "regular file") % filename)
                l = os.path.getsize(filename)
                if l > length:
                    # This is the truncation Bram was talking about that no one
                    # else thinks is a good idea.
                    #h = file(filename, 'rb+')
                    #make_file_sparse(filename, h, length)
                    #h.truncate(length)
                    #h.close()
                    l = length

                a = get_allocated_regions(filename, begin=0, length=l)
                if a is not None:
                    a.offset(total)
                else:
                    a = SparseSet()
                    if l > 0:
                        a.add(total, total + l)
                self.allocated_regions += a
            total += length
        self.total_length = total
        self.initialized = True
        return True
Example #2
0
    def _build_file_structs(self, filepool, files):
        total = 0
        for filename, length in files:
            print "filename %s in stor tpool length %d " % (filename, length)
            # we're shutting down, abort.
            if self.doneflag.isSet():
                return False

            self.undownloaded[filename] = length
            if length > 0:
                self.ranges.append((total, total + length, filename))

            self.range_by_name[filename] = (total, total + length)

            if os.path.exists(filename):
                if not os.path.isfile(filename):
                    raise BTFailure(
                        _("File %s already exists, but is not a "
                          "regular file") % filename)
                l = os.path.getsize(filename)
                print "size on disk %d length = %d" % (l, length)
                if l > length:
                    # This is the truncation Bram was talking about that no one
                    # else thinks is a good idea.
                    #h = file(filename, 'rb+')
                    #make_file_sparse(filename, h, length)
                    #h.truncate(length)
                    #h.close()
                    l = length

                a = get_allocated_regions(filename, begin=0, length=l)
                if a is not None:
                    a.offset(total)
                else:
                    a = SparseSet()
                    if l > 0:
                        a.add(total, total + l)
                self.allocated_regions += a
            total += length
        self.total_length = total
        self.initialized = True
        return True
Example #3
0
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from BitTorrent.platform import is_sparse, get_allocated_regions
import os
import sys
import glob

for p in glob.glob(sys.argv[1]):
    s = '%s is ' % p
    if not is_sparse(p):
        s += 'not sparse'
    else:
        a = get_allocated_regions(p)
        print a
        total = 0
        for x, y in a.iterrange():
            total += y - x
        real = float(total) / float(os.path.getsize(p))
        sparse = 1.0 - real
        sparse *= 100.0
        s += '%.2f%% sparse' % sparse
                                
    print s
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from BitTorrent.platform import is_sparse, get_allocated_regions
import os
import sys
import glob

for p in glob.glob(sys.argv[1]):
    s = '%s is ' % p
    if not is_sparse(p):
        s += 'not sparse'
    else:
        a = get_allocated_regions(p)
        print a
        total = 0
        for x, y in a.iterrange():
            total += y - x
        real = float(total) / float(os.path.getsize(p))
        sparse = 1.0 - real
        sparse *= 100.0
        s += '%.2f%% sparse' % sparse

    print s