Esempio n. 1
0
def main():
    parser = OptionParser(
        usage="usage: %prog [options] dir1 ... dirN",
        option_list=[
            make_option("-c",
                        "--capacity",
                        type="int",
                        default=736000000,
                        help="Storage unit capacity (in bytes)"),
            make_option("-r",
                        "--recursive",
                        action="store_true",
                        help="Scan each directory recursively"),
            make_option("-i",
                        "--include",
                        action="append",
                        default=[],
                        help="Filename pattern of files to be included"
                        " (more than one can be specified)"),
            make_option("-x",
                        "--exclude",
                        action="append",
                        default=[],
                        help="Filename pattern of files to be excluded"
                        " (more than one can be specified)"),
            make_option("-p",
                        "--preserveStructure",
                        action="store_true",
                        help="Preserve the directory tree hierarchy "
                        "in the partition"),
        ])

    options, dirs = parser.parse_args()
    if not dirs:
        dirs = ['.']

    fileLists = getFileLists(dirs, options.include, options.exclude,
                             options.recursive, options.preserveStructure)

    getSize = os.path.getsize
    bins = getBins(fileLists, options.capacity, getSize)
    files = flatten(fileLists)
    totalSize = sum(map(getSize, files))
    minBound = int(math.ceil(totalSize / float(options.capacity)))

    print "*** SUMMARY ***"
    print "* %d files (%s)" % (len(files), _sizeAsString(totalSize))
    print "* %s storage unit capacity" % _sizeAsString(options.capacity)
    print "* %d storage units are required at minimum" % minBound
    print "* %d sections were allocated" % len(bins)
    print
    print "* Listing files per unit"
    for i, bin in enumerate(sorted(bins, key=Bin.size, descending=True)):
        print "  - Unit %d (%s / %.2f%%)" % (i, _sizeAsString(
            bin.size()), 100 * bin.size() / float(options.capacity))
        for object in sorted(bin, key=getSize, descending=True):
            print "    %s (%s)" % (object, _sizeAsString(getSize(object)))
Esempio n. 2
0
 def __eq__(self,other):
     try:
         #todo: remove sorted() once MultiDigraph.edges returns Multiset
         #      instead of list
         from common import sorted
         return self.nodes() == other.nodes() \
                and sorted(self.edges()) == sorted(other.edges())
     except AttributeError:
         return False
Esempio n. 3
0
 def __eq__(self, other):
     try:
         #todo: remove sorted() once MultiDigraph.edges returns Multiset
         #      instead of list
         from common import sorted
         return self.nodes() == other.nodes() \
                and sorted(self.edges()) == sorted(other.edges())
     except AttributeError:
         return False
Esempio n. 4
0
def main():
    parser = OptionParser(
        usage = "usage: %prog [options] dir1 ... dirN",
        option_list= [
            make_option("-c", "--capacity",
                        type = "int",
                        default = 736000000,
                        help = "Storage unit capacity (in bytes)"),

            make_option("-r", "--recursive",
                        action = "store_true",
                        help = "Scan each directory recursively"),

            make_option("-i", "--include",
                        action = "append",
                        default = [],
                        help = "Filename pattern of files to be included"
                               " (more than one can be specified)"),

            make_option("-x", "--exclude",
                        action = "append",
                        default = [],
                        help = "Filename pattern of files to be excluded"
                               " (more than one can be specified)"),

            make_option("-p", "--preserveStructure",
                        action = "store_true",
                        help = "Preserve the directory tree hierarchy "
                               "in the partition"),
                     ])

    options,dirs = parser.parse_args()
    if not dirs:
        dirs = ['.']

    fileLists = getFileLists(dirs, options.include, options.exclude,
                             options.recursive, options.preserveStructure)

    getSize = os.path.getsize
    bins = getBins(fileLists, options.capacity, getSize)
    files = flatten(fileLists)
    totalSize = sum(map(getSize,files))
    minBound = int(math.ceil(totalSize / float(options.capacity)))

    print "*** SUMMARY ***"
    print "* %d files (%s)" % (len(files), _sizeAsString(totalSize))
    print "* %s storage unit capacity" % _sizeAsString(options.capacity)
    print "* %d storage units are required at minimum" % minBound
    print "* %d sections were allocated" % len(bins)
    print
    print "* Listing files per unit"
    for i,bin in enumerate(sorted(bins,key=Bin.size,descending=True)):
        print "  - Unit %d (%s / %.2f%%)" % (
                        i, _sizeAsString(bin.size()),
                        100 * bin.size() / float(options.capacity))
        for object in sorted(bin, key=getSize, descending=True):
            print "    %s (%s)" % (object, _sizeAsString(getSize(object)))
Esempio n. 5
0
 def __str__(self):
     output = StringIO()
     attrs = 'label width height minX minY'.split()
     for label, pic in sorted(self._pictures.iteritems()):
         print >> output, ' '.join(
             [str(getattr(pic, attr)) for attr in attrs])
     return output.getvalue().strip()
Esempio n. 6
0
def binPacking_bfd(objects, capacity, getSize=lambda x: x):
    return binPacking_bf(sorted(objects, key=getSize, descending=True),
                         capacity, getSize)
Esempio n. 7
0
 def assertEqualSets(self,c1,c2):
     #self.assertEquals(list(c1), list(c2))
     self.assertEquals(sorted(c1), sorted(c2))
Esempio n. 8
0
 def __str__(self):
     output = StringIO()
     attrs = "label width height minX minY".split()
     for label, pic in sorted(self._pictures.iteritems()):
         print >> output, " ".join([str(getattr(pic, attr)) for attr in attrs])
     return output.getvalue().strip()
Esempio n. 9
0
def binPacking_bfd(objects, capacity, getSize = lambda x:x):
    return binPacking_bf(sorted(objects,key=getSize,descending=True), capacity,
                         getSize)