コード例 #1
0
ファイル: binpack.py プロジェクト: gpapadop79/gsakkis-utils
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)))
コード例 #2
0
ファイル: binpack.py プロジェクト: gpapadop79/gsakkis-utils
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)))
コード例 #3
0
ファイル: binpack.py プロジェクト: gpapadop79/gsakkis-utils
def _getFiles(dir, includeFilters, excludeFilters, recursive, preserveStructure):
    files = []
    kept, thrown = [sum([glob.glob(os.path.join(dir,p)) for p in filters], [])
                    for filters in includeFilters, excludeFilters]
    for fullname in [f for f in kept if f not in thrown]:
        if os.path.isdir(fullname):
            if recursive:
                accumulate = preserveStructure and files.append or files.extend
                accumulate(_getFiles(fullname,includeFilters,excludeFilters,
                                    recursive,preserveStructure))
        else:
            files.append(fullname)
    return files
コード例 #4
0
ファイル: binpack.py プロジェクト: gpapadop79/gsakkis-utils
def _getFiles(dir, includeFilters, excludeFilters, recursive,
              preserveStructure):
    files = []
    kept, thrown = [
        sum([glob.glob(os.path.join(dir, p)) for p in filters], [])
        for filters in includeFilters, excludeFilters
    ]
    for fullname in [f for f in kept if f not in thrown]:
        if os.path.isdir(fullname):
            if recursive:
                accumulate = preserveStructure and files.append or files.extend
                accumulate(
                    _getFiles(fullname, includeFilters, excludeFilters,
                              recursive, preserveStructure))
        else:
            files.append(fullname)
    return files
コード例 #5
0
from common import sum, get_divisors

upper_limit = 10000
amicable = []

for x in xrange(1, upper_limit):
	d = sum(get_divisors(x))
	if d != 0 and sum(get_divisors(d)) == x:
		if x != d:
			if x not in amicable:
				amicable.append(x)
			if d not in amicable:
				amicable.append(d)
print amicable
print sum(amicable) 

コード例 #6
0
ファイル: glossy.py プロジェクト: gpapadop79/gsakkis-utils
 def objectiveFunction(self):
     return page.area - sum([picture.area for picture in self.pictures])
コード例 #7
0
 def objectiveFunction(self):
     return page.area - sum([picture.area for picture in self.pictures])