From owner-svn-src-projects@FreeBSD.ORG Fri Jan 11 07:39:12 2013 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 61F89A29; Fri, 11 Jan 2013 07:39:12 +0000 (UTC) (envelope-from linimon@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 44DE6739; Fri, 11 Jan 2013 07:39:12 +0000 (UTC) Received: from svn.freebsd.org (svn.FreeBSD.org [8.8.178.70]) by svn.freebsd.org (8.14.5/8.14.5) with ESMTP id r0B7dCrp013999; Fri, 11 Jan 2013 07:39:12 GMT (envelope-from linimon@svn.freebsd.org) Received: (from linimon@localhost) by svn.freebsd.org (8.14.5/8.14.5/Submit) id r0B7dC4l013998; Fri, 11 Jan 2013 07:39:12 GMT (envelope-from linimon@svn.freebsd.org) Message-Id: <201301110739.r0B7dC4l013998@svn.freebsd.org> From: Mark Linimon Date: Fri, 11 Jan 2013 07:39:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r245288 - projects/portbuild/scripts X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Jan 2013 07:39:12 -0000 Author: linimon (doc,ports committer) Date: Fri Jan 11 07:39:11 2013 New Revision: 245288 URL: http://svnweb.freebsd.org/changeset/base/245288 Log: Smash hard-coding once and for all. Modified: projects/portbuild/scripts/zexpire Modified: projects/portbuild/scripts/zexpire ============================================================================== --- projects/portbuild/scripts/zexpire Fri Jan 11 06:31:04 2013 (r245287) +++ projects/portbuild/scripts/zexpire Fri Jan 11 07:39:11 2013 (r245288) @@ -2,41 +2,123 @@ # # Expire old snapshots -import sys, commands, datetime, os +import sys, commands, datetime, os, string -sys.path.insert(0, '/var/portbuild/lib/python') +pbc = os.getenv('PORTBUILD_CHECKOUT') \ + if os.getenv('PORTBUILD_CHECKOUT') else "/a/portbuild" +pbd = os.getenv('PORTBUILD_DATA') \ + if os.getenv('PORTBUILD_DATA') else "/a/portbuild" +sys.path.insert(0, '%s/lib/python' % pbc) + +from freebsd import * +from freebsd_config import * import zfs -ENABLED = True +CONFIG_SUBDIR="conf" +CONFIG_FILENAME="server.conf" + +ENABLED = False VERBOSE= True -# List of filesystems to expire -expirelist=(("a", 14), - ("a/portbuild/amd64", 14), - ("a/portbuild/arm", 14), - ("a/portbuild/i386", 14), - ("a/portbuild/ia64", 14), - ("a/portbuild/mips", 14), - ("a/portbuild/powerpc", 14), - ("a/portbuild/sparc64", 14), - ("a/portbuild/sun4v", 14), - ("a/snap", 7), - ("a/snap/ports-head", 2), - ("a/snap/ports-head/ports", 2), - ("a/snap/src-7", 2), - ("a/snap/src-7/src", 2), - ("a/snap/src-8", 2), - ("a/snap/src-8/src", 2), - ("a/snap/src-9", 2), - ("a/snap/src-9/src", 2), - ("a/snap/src-10", 2), - ("a/snap/src-10/src", 2)) +## List of filesystems to expire +## XXX MCL so much hardcoding. +#expirelist=(("a", 14), +# ("a/portbuild/amd64", 14), +# ("a/portbuild/arm", 14), +# ("a/portbuild/i386", 14), +# ("a/portbuild/ia64", 14), +# ("a/portbuild/mips", 14), +# ("a/portbuild/powerpc", 14), +# ("a/portbuild/sparc64", 14), +# ("a/portbuild/sun4v", 14), +# ("a/snap", 7), +# ("a/snap/ports-head", 2), +# ("a/snap/ports-head/ports", 2), +# ("a/snap/src-7", 2), +# ("a/snap/src-7/src", 2), +# ("a/snap/src-8", 2), +# ("a/snap/src-8/src", 2), +# ("a/snap/src-9", 2), +# ("a/snap/src-9/src", 2), +# ("a/snap/src-10", 2), +# ("a/snap/src-10/src", 2)) +expirelist2={} now = datetime.datetime.now() print "zexpire: starting at " + now.ctime() -for (fs, maxage) in expirelist: +config = getConfig( pbc, CONFIG_SUBDIR, CONFIG_FILENAME ) +ZFS_VOLUME = config.get( 'ZFS_VOLUME' ) +if not ZFS_VOLUME: + print "you must define ZFS_VOLUME" + sys.exit( 1 ) +ZFS_MOUNTPOINT = config.get( 'ZFS_MOUNTPOINT' ) +if not ZFS_MOUNTPOINT: + print "you must define ZFS_MOUNTPOINT" + sys.exit( 1 ) +PORTBUILD_DIRECTORY = config.get( 'PORTBUILD_DIRECTORY' ) +if not PORTBUILD_DIRECTORY: + print "you must define PORTBUILD_DIRECTORY" + sys.exit( 1 ) +portbuild_directory = os.path.join( ZFS_VOLUME, PORTBUILD_DIRECTORY ) +SNAP_DIRECTORY = config.get( 'SNAP_DIRECTORY' ) +if not SNAP_DIRECTORY: + print "you must define SNAP_DIRECTORY" + sys.exit( 1 ) +snap_directory = os.path.join( ZFS_VOLUME, SNAP_DIRECTORY ) +snap_mountpoint = os.path.join( ZFS_MOUNTPOINT, SNAP_DIRECTORY ) +SUPPORTED_ARCHS = config.get( 'SUPPORTED_ARCHS' ) +if not SUPPORTED_ARCHS: + print "you must define SUPPORTED_ARCHS" + sys.exit( 1 ) +supported_archs = string.split( SUPPORTED_ARCHS ) +ZFS_DEFAULT_EXPIRATION = config.get( 'ZFS_DEFAULT_EXPIRATION' ) +if not ZFS_DEFAULT_EXPIRATION: + print "you must define ZFS_DEFAULT_EXPIRATION" + sys.exit( 1 ) +ZFS_SNAPSHOT_EXPIRATION = config.get( 'ZFS_SNAPSHOT_EXPIRATION' ) +if not ZFS_SNAPSHOT_EXPIRATION: + print "you must define ZFS_SNAPSHOT_EXPIRATION" + sys.exit( 1 ) + +#print portbuild_directory +#print snap_directory +#print supported_archs +#print ZFS_DEFAULT_EXPIRATION +#print ZFS_SNAPSHOT_EXPIRATION + +expirelist2[ ZFS_VOLUME ] = ZFS_DEFAULT_EXPIRATION +expirelist2[ portbuild_directory ] = ZFS_DEFAULT_EXPIRATION +for arch in supported_archs: + expirelist2[ os.path.join( portbuild_directory, arch ) ] = ZFS_DEFAULT_EXPIRATION +expirelist2[ snap_directory ] = ZFS_SNAPSHOT_EXPIRATION +try: + snapdirs = os.listdir( snap_mountpoint ) + for snapdir in snapdirs: + subdir = os.path.join( snap_mountpoint, snapdir ) + tmp = os.path.join( snap_directory, snapdir ) + expirelist2[ tmp ] = ZFS_SNAPSHOT_EXPIRATION + try: + snapsubdirs = os.listdir( subdir ) + for snapsubdir in snapsubdirs: + expirelist2[ os.path.join( tmp, snapsubdir ) ] = ZFS_SNAPSHOT_EXPIRATION + except: + pass +except: + pass + +keys = expirelist2.keys() +keys.sort() +for key in keys: + fs = key + maxage = 2 + try: + maxage = int( expirelist2[ key ] ) + except: + pass + +#for (fs, maxage) in expirelist: print if VERBOSE: