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)))
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
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
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)))
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()
def binPacking_bfd(objects, capacity, getSize=lambda x: x): return binPacking_bf(sorted(objects, key=getSize, descending=True), capacity, getSize)
def assertEqualSets(self,c1,c2): #self.assertEquals(list(c1), list(c2)) self.assertEquals(sorted(c1), sorted(c2))
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()
def binPacking_bfd(objects, capacity, getSize = lambda x:x): return binPacking_bf(sorted(objects,key=getSize,descending=True), capacity, getSize)