def clearCache(all=False): import glob def getPackageLists(pkgList): latest = {} for f in pkgList: try: name, full_version = util.parse_package_name(f) version, release, build = pisi.util.split_version(full_version) release = int(release) if name in latest: lversion, lrelease = latest[name] if lrelease > release: continue latest[name] = full_version, release except: pass latestVersions = [] for pkg in latest: latestVersions.append("%s-%s" % (pkg, latest[pkg][0])) oldVersions = list(set(pkgList) - set(latestVersions)) return oldVersions, latestVersions def getRemoveOrder(cacheDir, pkgList): sizes = {} for pkg in pkgList: sizes[pkg] = os.stat(os.path.join(cacheDir, pkg) + ctx.const.package_suffix).st_size # sort dictionary by value from PEP-265 from operator import itemgetter return sorted(sizes.iteritems(), key=itemgetter(1), reverse=False) def removeOrderByLimit(cacheDir, order, limit): totalSize = 0 for pkg, size in order: totalSize += size if totalSize >= limit: try: os.remove(os.path.join(cacheDir, pkg) + ctx.const.package_suffix) except exceptions.OSError: pass def removeAll(cacheDir): cached = glob.glob("%s/*.eopkg" % cacheDir) + glob.glob("%s/*.part" % cacheDir) for pkg in cached: try: os.remove(pkg) except exceptions.OSError: pass cacheDir = ctx.config.cached_packages_dir() pkgList = map(lambda x: os.path.basename(x).split(ctx.const.package_suffix)[0], glob.glob("%s/*.eopkg" % cacheDir)) if not all: # Cache limits from pisi.conf config = pisi.configfile.ConfigurationFile("/etc/eopkg/eopkg.conf") cacheLimit = int(config.get("general", "package_cache_limit")) * 1024 * 1024 # is this safe? if not cacheLimit: return old, latest = getPackageLists(pkgList) order = getRemoveOrder(cacheDir, latest) + getRemoveOrder(cacheDir, old) removeOrderByLimit(cacheDir, order, cacheLimit) else: removeAll(cacheDir)
def clearCache(all=False): import glob def getPackageLists(pkgList): latest = {} for f in pkgList: try: name, full_version = util.parse_package_name(f) version, release, build = pisi.util.split_version(full_version) release = int(release) if name in latest: lversion, lrelease = latest[name] if lrelease > release: continue latest[name] = full_version, release except: pass latestVersions = [] for pkg in latest: latestVersions.append("%s-%s" % (pkg, latest[pkg][0])) oldVersions = list(set(pkgList) - set(latestVersions)) return oldVersions, latestVersions def getRemoveOrder(cacheDir, pkgList): sizes = {} for pkg in pkgList: sizes[pkg] = os.stat( os.path.join(cacheDir, pkg) + ctx.const.package_suffix).st_size # sort dictionary by value from PEP-265 from operator import itemgetter return sorted(iter(list(sizes.items())), key=itemgetter(1), reverse=False) def removeOrderByLimit(cacheDir, order, limit): totalSize = 0 for pkg, size in order: totalSize += size if totalSize >= limit: try: os.remove( os.path.join(cacheDir, pkg) + ctx.const.package_suffix) except OSError: pass def removeAll(cacheDir): cached = glob.glob("%s/*.pisi" % cacheDir) + glob.glob( "%s/*.part" % cacheDir) for pkg in cached: try: os.remove(pkg) except OSError: pass cacheDir = ctx.config.cached_packages_dir() pkgList = [ os.path.basename(x).split(ctx.const.package_suffix)[0] for x in glob.glob("%s/*.pisi" % cacheDir) ] if not all: # Cache limits from pisi.conf config = pisi.configfile.ConfigurationFile("/etc/pisi/pisi.conf") cacheLimit = int(config.get( "general", "package_cache_limit")) * 1024 * 1024 # is this safe? if not cacheLimit: return old, latest = getPackageLists(pkgList) order = getRemoveOrder(cacheDir, latest) + getRemoveOrder( cacheDir, old) removeOrderByLimit(cacheDir, order, cacheLimit) else: removeAll(cacheDir)
def clearCache(all=False): import glob from sets import Set as set def getPackageLists(pkgList): latest = {} for f in pkgList: try: name, version = util.parse_package_name(f) if latest.has_key(name): if Version(latest[name]) < Version(version): latest[name] = version else: if version: latest[name] = version except: pass latestVersions = [] for pkg in latest: latestVersions.append("%s-%s" % (pkg, latest[pkg])) oldVersions = list(set(pkgList) - set(latestVersions)) return oldVersions, latestVersions def getRemoveOrder(cacheDir, pkgList): sizes = {} for pkg in pkgList: sizes[pkg] = os.stat(os.path.join(cacheDir, pkg) + ".pisi").st_size # sort dictionary by value from PEP-265 from operator import itemgetter return sorted(sizes.iteritems(), key=itemgetter(1), reverse=False) def removeOrderByLimit(cacheDir, order, limit): totalSize = 0 for pkg, size in order: totalSize += size if totalSize >= limit: try: os.remove(os.path.join(cacheDir, pkg) + ".pisi") except exceptions.OSError: pass def removeAll(cacheDir): cached = glob.glob("%s/*.pisi" % cacheDir) + glob.glob("%s/*.part" % cacheDir) for pkg in cached: try: os.remove(pkg) except exceptions.OSError: pass cacheDir = ctx.config.cached_packages_dir() pkgList = map(lambda x: os.path.basename(x).split(".pisi")[0], glob.glob("%s/*.pisi" % cacheDir)) if not all: # Cache limits from pisi.conf config = pisi.configfile.ConfigurationFile("/etc/pisi/pisi.conf") cacheLimit = int(config.get("general", "package_cache_limit")) * 1024 * 1024 # is this safe? if not cacheLimit: return old, latest = getPackageLists(pkgList) order = getRemoveOrder(cacheDir, latest) + getRemoveOrder(cacheDir, old) removeOrderByLimit(cacheDir, order, cacheLimit) else: removeAll(cacheDir)