[121076] users/jmr
jmr at macports.org
jmr at macports.org
Mon Jun 16 19:43:53 PDT 2014
Revision: 121076
https://trac.macports.org/changeset/121076
Author: jmr at macports.org
Date: 2014-06-16 19:43:53 -0700 (Mon, 16 Jun 2014)
Log Message:
-----------
scripts for pruning archives
Added Paths:
-----------
users/jmr/delete_old_archives/
users/jmr/delete_old_archives/current_versions.tcl
users/jmr/delete_old_archives/delete_old_archives.py
Property changes on: users/jmr/delete_old_archives
___________________________________________________________________
Added: svn:ignore
+ current_versions.txt
Added: users/jmr/delete_old_archives/current_versions.tcl
===================================================================
--- users/jmr/delete_old_archives/current_versions.tcl (rev 0)
+++ users/jmr/delete_old_archives/current_versions.tcl 2014-06-17 02:43:53 UTC (rev 121076)
@@ -0,0 +1,17 @@
+#!/usr/bin/env port-tclsh
+
+package require macports
+mportinit
+
+if {[catch {set res [mportlistall]} result]} {
+ puts stderr "$::errorInfo"
+ error "listing all ports failed: $result"
+}
+
+foreach {name dictionary} $res {
+ array unset portinfo
+ array set portinfo $dictionary
+ puts "${name} $portinfo(version)_$portinfo(revision)"
+}
+
+mportshutdown
Property changes on: users/jmr/delete_old_archives/current_versions.tcl
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:keywords
+ Id
Added: svn:eol-style
+ native
Added: users/jmr/delete_old_archives/delete_old_archives.py
===================================================================
--- users/jmr/delete_old_archives/delete_old_archives.py (rev 0)
+++ users/jmr/delete_old_archives/delete_old_archives.py 2014-06-17 02:43:53 UTC (rev 121076)
@@ -0,0 +1,81 @@
+#!/usr/bin/env python
+
+greatestAge = 0
+greatestSize = 0
+totalSize = 0
+
+class archiveFile(object):
+ """An archive file being considered for deletion"""
+ def __init__(self, path, age, size):
+ self.path = path
+ self.age = age
+ self.size = size
+
+def weightedValue(age, size):
+ """Combine an age and a size into a value out of 100"""
+ weightedAge = (float(age) / float(greatestAge)) * 50.0
+ weightedSize = (float(size) / float(greatestSize)) * 50.0
+ return weightedAge + weightedSize
+
+def weightedKey(archive):
+ """Key extraction function for sorting using weightedValue"""
+ return weightedValue(archive.age, archive.size)
+
+import sys
+
+versionFile = 'current_versions.txt'
+rootDir = '.'
+
+if len(sys.argv) > 1:
+ rootDir = sys.argv[1]
+ if len(sys.argv) > 2:
+ versionFile = sys.argv[2]
+
+import re
+# patterns to match against for archives that are the current version
+currentVersions = {}
+fd = open(versionFile, 'r')
+for line in fd:
+ name, version = line.split()
+ currentVersions[name] = re.compile(name+'-'+version+'[.+]')
+fd.close()
+
+import time
+now = time.time()
+fileList = []
+
+import os
+for portdir in os.listdir(rootDir):
+ portDirPath = os.path.join(rootDir, portdir)
+ if os.path.isdir(portDirPath):
+ for archiveFilename in os.listdir(portDirPath):
+ if archiveFilename.endswith('.rmd160') or currentVersions[portdir].match(archiveFilename):
+ continue
+ archivePath = os.path.join(portDirPath, archiveFilename)
+ if os.path.isfile(archivePath):
+ thisAge = now - os.path.getmtime(archivePath)
+ thisSize = os.path.getsize(archivePath)
+ thisArchiveFile = archiveFile(archivePath, thisAge, thisSize)
+ fileList.append(thisArchiveFile)
+ if thisArchiveFile.age > greatestAge:
+ greatestAge = thisArchiveFile.age
+ if thisArchiveFile.size > greatestSize:
+ greatestSize = thisArchiveFile.size
+ totalSize += thisSize
+
+fileList.sort(key=weightedKey, reverse=True)
+
+for f in fileList:
+ sys.stderr.write(f.path+' '+str(f.age)+' '+str(f.size)+': weighted value = '+str(weightedValue(f.age, f.size))+'\n')
+
+# trim files until the total size of non-current archives remaining is this or less
+targetSize = 200 * 10**9
+
+for f in fileList:
+ if totalSize <= targetSize:
+ break
+ print (f.path)
+ sigpath = f.path+'.rmd160'
+ if os.path.isfile(sigpath):
+ print (sigpath)
+ totalSize -= f.size
Property changes on: users/jmr/delete_old_archives/delete_old_archives.py
___________________________________________________________________
Added: svn:executable
+ *
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/macports-changes/attachments/20140616/250cc153/attachment.html>
More information about the macports-changes
mailing list