[26980] in Source-Commits

home help back first fref pref prev next nref lref last post

/svn/athena r25869 - in trunk: athena/bin debathena/debathena debathena/debathena/getcluster debathena/debathena/getcluster/debian

daemon@ATHENA.MIT.EDU (Jonathan D Reed)
Thu Mar 28 13:33:42 2013

Date: Thu, 28 Mar 2013 13:33:36 -0400
From: Jonathan D Reed <jdreed@MIT.EDU>
Message-Id: <201303281733.r2SHXalv007079@drugstore.mit.edu>
To: source-commits@MIT.EDU
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Author: jdreed
Date: 2013-03-28 13:33:36 -0400 (Thu, 28 Mar 2013)
New Revision: 25869

Added:
   trunk/debathena/debathena/getcluster/
   trunk/debathena/debathena/getcluster/Makefile
   trunk/debathena/debathena/getcluster/debian/changelog
   trunk/debathena/debathena/getcluster/debian/control
   trunk/debathena/debathena/getcluster/getcluster.py
Removed:
   trunk/athena/bin/getcluster/
   trunk/debathena/debathena/getcluster/Makefile.in
   trunk/debathena/debathena/getcluster/configure.in
   trunk/debathena/debathena/getcluster/debian/changelog
   trunk/debathena/debathena/getcluster/debian/control.in
   trunk/debathena/debathena/getcluster/getcluster.c
Modified:
   trunk/debathena/debathena/getcluster/debian/compat
   trunk/debathena/debathena/getcluster/debian/rules
Log:


Added: trunk/debathena/debathena/getcluster/Makefile
===================================================================
--- trunk/debathena/debathena/getcluster/Makefile	                        (rev 0)
+++ trunk/debathena/debathena/getcluster/Makefile	2013-03-28 17:33:36 UTC (rev 25869)
@@ -0,0 +1,19 @@
+all:
+
+getcluster: getcluster.py
+	cp getcluster.py getcluster
+	chmod 755 getcluster
+
+check:	getcluster
+	sh tests.sh
+
+install:
+	mkdir -p ${DESTDIR}/bin
+	mkdir -p ${DESTDIR}/usr/share/man/man1
+	install -m 755 getcluster ${DESTDIR}/bin
+	install -m444 getcluster.1 ${DESTDIR}/usr/share/man/man1
+
+clean:
+	rm -f getcluster
+
+distclean: clean
\ No newline at end of file

Copied: trunk/debathena/debathena/getcluster/debian/changelog (from rev 25865, trunk/athena/bin/getcluster/debian/changelog)
===================================================================
--- trunk/debathena/debathena/getcluster/debian/changelog	                        (rev 0)
+++ trunk/debathena/debathena/getcluster/debian/changelog	2013-03-28 17:33:36 UTC (rev 25869)
@@ -0,0 +1,77 @@
+debathena-getcluster (10.2) unstable; urgency=low
+
+  * Rewrite in Python and remove autogoo (Trac: #1037)
+  * Actually quote shell output (Trac: #1037)
+  * Add decision debugging with DEBUG_GETCLUSTER=yes
+  * Convert to Debian native package
+  * Bump compat level and Standards-Version
+  * Depend on python-hesiod
+  * Build-Depend on python-hesiod (for 'make check')
+  * Convert to arch-indep package
+
+ -- Jonathan Reed <jdreed@mit.edu>  Thu, 28 Mar 2013 13:29:29 -0400
+
+debathena-getcluster (10.1.0-0debathena2) unstable; urgency=low
+
+  * Quote shell output (Trac: #1037), now that the dotfiles are actually
+    fixed.
+
+ -- Jonathan Reed <jdreed@mit.edu>  Thu, 21 Mar 2013 16:45:44 -0400
+
+debathena-getcluster (10.1.0-0debathena1) unstable; urgency=low
+
+  * Bump debian/compat to 6
+  * Add a "-p" flag to print out space-separated key/value pairs for
+    things to parse by hand
+  * Update man page for new option
+
+ -- Jonathan Reed <jdreed@mit.edu>  Fri, 20 Jul 2012 17:12:24 -0400
+
+debathena-getcluster (10.0.3-0debathena1) unstable; urgency=low
+
+  * Revert changes to getcluster.c in r25378.  Continue with broken
+    behavior and hope that nobody sets a clusterinfo value with a space in
+    it.
+
+ -- Jonathan Reed <jdreed@mit.edu>  Mon, 28 Nov 2011 10:37:05 -0500
+
+debathena-getcluster (10.0.2-0debathena1) unstable; urgency=low
+
+  * Update date for getcluster.1 to reflect reality
+
+ -- Benjamin Kaduk <kaduk@mit.edu>  Mon, 07 Nov 2011 19:01:32 -0500
+
+debathena-getcluster (10.0.1-0debathena1) unstable; urgency=low
+
+  * Quote shell output (Trac: #1037)
+  * Update the man page for the 21st century (Trac: #964)
+
+ -- Jonathan Reed <jdreed@mit.edu>  Thu, 11 Aug 2011 16:26:14 -0400
+
+debathena-getcluster (10.0.0-0debathena2) unstable; urgency=low
+
+  * Change DEB_AUTO_UPDATE_AUTOCONF to 2.50, not 1.
+  * Remove DEB_AUTO_UPDATE_DEBIAN_CONTROL.
+  * Change "Debian-Athena Project" to "Debathena Project".
+  * Remove debian/control from version control.
+  * Clean up debian/copyright.
+
+ -- Tim Abbott <tabbott@mit.edu>  Sat, 24 Jan 2009 15:17:42 -0500
+
+debathena-getcluster (10.0.0-0debathena1) unstable; urgency=low
+
+  * Man page section fixed in upstream source, remove patch.
+
+ -- Greg Hudson <ghudson@equal-rites.mit.edu>  Wed, 06 Feb 2008 13:21:38 -0500
+
+debathena-getcluster (9.4.0-0debathena2) unstable; urgency=low
+
+  * Section: debathena/net.
+
+ -- Anders Kaseorg <andersk@mit.edu>  Tue, 17 Jul 2007 06:33:43 -0400
+
+debathena-getcluster (9.4.0-0debathena1) unstable; urgency=low
+
+  * Initial release.
+
+ -- Anders Kaseorg <andersk@mit.edu>  Tue, 30 Jan 2007 01:13:49 -0500

Modified: trunk/debathena/debathena/getcluster/debian/compat
===================================================================
--- trunk/athena/bin/getcluster/debian/compat	2012-12-09 08:02:39 UTC (rev 25803)
+++ trunk/debathena/debathena/getcluster/debian/compat	2013-03-28 17:33:36 UTC (rev 25869)
@@ -1 +1 @@
-6
+7

Copied: trunk/debathena/debathena/getcluster/debian/control (from rev 25803, trunk/athena/bin/getcluster/debian/control.in)
===================================================================
--- trunk/debathena/debathena/getcluster/debian/control	                        (rev 0)
+++ trunk/debathena/debathena/getcluster/debian/control	2013-03-28 17:33:36 UTC (rev 25869)
@@ -0,0 +1,16 @@
+Source: debathena-getcluster
+Section: debathena/net
+Priority: extra
+Maintainer: Debathena Project <debathena@mit.edu>
+Build-Depends: debhelper (>= 7.0~)
+Standards-Version: 3.9.3
+
+Package: debathena-getcluster
+Architecture: all
+Provides: getcluster
+Depends: ${misc:Depends}, ${python:Depends}, python-hesiod
+Description: Retrieve service cluster info from Hesiod for Athena workstations
+ The getcluster program is used on all Athena workstations to find the 
+ service cluster information for the workstation and writes a list of 
+ environment variable assignments which can be used to initialize a 
+ shell accordingly.

Modified: trunk/debathena/debathena/getcluster/debian/rules
===================================================================
--- trunk/athena/bin/getcluster/debian/rules	2012-12-09 08:02:39 UTC (rev 25803)
+++ trunk/debathena/debathena/getcluster/debian/rules	2013-03-28 17:33:36 UTC (rev 25869)
@@ -1,10 +1,4 @@
 #!/usr/bin/make -f
 
-DEB_AUTO_UPDATE_AUTOCONF = 2.50
-include /usr/share/cdbs/1/rules/debhelper.mk
-include /usr/share/cdbs/1/class/autotools.mk
-
-DEB_CONFIGURE_EXTRA_FLAGS += lbindir=/bin --with-hesiod
-
-clean::
-	rm -f configure
+%:
+	dh $@

Added: trunk/debathena/debathena/getcluster/getcluster.py
===================================================================
--- trunk/debathena/debathena/getcluster/getcluster.py	                        (rev 0)
+++ trunk/debathena/debathena/getcluster/getcluster.py	2013-03-28 17:33:36 UTC (rev 25869)
@@ -0,0 +1,218 @@
+#!/usr/bin/python
+#
+# A rewrite of getcluster(1) in Python
+#
+
+FALLBACKFILE = "/etc/cluster.fallback"
+LOCALFILE = "/etc/cluster.local"
+CLUSTERFILE = "/etc/cluster"
+HESTYPE = "cluster"
+GENERIC = "public-linux"
+UPDATE_INTERVAL = (3600 * 4)
+
+import hesiod
+import re
+import sys
+import errno
+import socket
+import os
+import time
+import random
+import struct
+from optparse import OptionParser
+
+cluster_re = re.compile('^\S+ \S+( \S+){0,2}$')
+debugMode = os.getenv('DEBUG_GETCLUSTER', 'no') == 'yes'
+
+def debug(msg, *args):
+    if debugMode:
+        print >>sys.stderr, "D:", msg % (args)
+
+def perror(msg, *args):
+    print >>sys.stderr, ("%s: " + msg) % ((sys.argv[0],) + args)
+
+def merge(list1, list2):
+    rv = [] + list1
+    for i in list2:
+        if i.split(' ', 1)[0] not in [j.split(' ', 1)[0] for j in list1]:
+            rv.append(i)
+    return rv
+
+def cleanup(l):
+    return filter(lambda x: cluster_re.match(x), map(lambda x: x.rstrip(), l))
+
+def vercmp(v1, v2):
+    v1l = map(int, map(lambda x: 0 if x is None else x, re.search('^(\d+)(?:\.(\d+)){0,1}',v1).groups()))
+    v2l = map(int, map(lambda x: 0 if x is None else x, re.search('^(\d+)(?:\.(\d+)){0,1}',v2).groups()))
+    return cmp(v1l, v2l)
+
+
+def output_var(var, val, bourne=False, plaintext=False):
+    val = val.replace("'", "'\\''")
+    var = var.upper()
+    if bourne:
+        print "%s='%s' ; export %s" % (var, val, var)
+    elif plaintext:
+        print "%s %s" % (var, val)
+    else:
+        print "setenv %s '%s' ;" % (var, val)
+
+def main():
+    parser = OptionParser(usage='%prog [options] version', add_help_option=False)
+    parser.add_option("-b", action="store_true", dest="bourne", default=False)
+    parser.add_option("-p", action="store_true", dest="plain", default=False)
+    parser.add_option("-d", action="store_true", dest="debug", default=False)
+    parser.add_option("-f", action="store_true", dest="deprecated", default=False)
+    parser.add_option("-l", action="store_true", dest="deprecated", default=False)
+    parser.add_option("-h", action="store", type="string", dest="hostname")
+
+    (options, args) = parser.parse_args()
+    if len(args) == 2:
+        perror("Ignoring deprecated hostname syntax.")
+        args.pop(0)
+    if len(args) != 1:
+        parser.print_usage()
+        return 1
+    
+    if options.deprecated:
+        perror("-f and -l are deprecated and will be ignored.")
+    if options.bourne and options.plain:
+        parser.error("-p and -b are mutually exclusive.")
+
+    ws_version=args[0]
+    fallback=[]
+    local=[]
+    data=[]
+    if (options.hostname == None):
+        # Get the hostname/cluster name from /etc/cluster if present
+        try:
+            with open(CLUSTERFILE, 'r') as f:
+                options.hostname = f.readline().strip()
+        except IOError as e:
+            # Fallback to nodename
+            options.hostname = os.uname()[1]
+
+        if not options.hostname:
+            perror("Cannot determine hostname or %s was empty", CLUSTERFILE)
+            return 1
+
+        try:
+            with open(FALLBACKFILE, 'r') as f:
+                fallback = cleanup(f.readlines())
+        except IOError as e:
+            pass
+
+        try:
+            with open(LOCALFILE, 'r') as f:
+                local = cleanup(f.readlines())
+        except IOError as e:
+            pass
+
+    if options.debug:
+        data = cleanup(sys.stdin.readlines())
+    else:
+        hes = None
+        try:
+            hes = hesiod.Lookup(options.hostname, HESTYPE)
+        except IOError as e:
+            if e.errno != errno.ENOENT:
+                perror("hesiod_resolve: %s", str(e))
+                return 1
+        if hes == None:
+            try:
+                hes = hesiod.Lookup(GENERIC, HESTYPE)
+            except IOError as e:
+                if e.errno != errno.ENOENT:
+                    perror("hesiod_resolve: %s", str(e))
+                    return 1
+        if hes == None:
+            perror("Could not find any Hesiod cluster data.")
+            return 1
+        data = cleanup(hes.results)
+
+    if len(data) == 0 and len(fallback) == 0 and len(local) == 0:
+        if (options.debug):
+            perror("No valid cluster data specified on stdin.")
+        else:
+            perror("No cluster information available for %s", options.hostname)
+    # Sort everything into a hash, with varnames as keys and lists of lists as values
+    cdata = {}
+    for i in map(lambda x: x.split(' '), merge(merge(local, data), fallback)):
+        var = i.pop(0)
+        if var not in cdata:
+            cdata[var] = []
+        cdata[var].append(i)
+
+    now = int(time.time())
+    update_time = -1
+    try:
+        update_time = int(os.getenv('UPDATE_TIME', ''))
+    except ValueError:
+        pass
+    autoupdate = os.getenv('AUTOUPDATE', 'false') == 'true'
+    # This is secretly a 32-bit integer regardless of platform
+    ip = -1 & 0xffffffff
+    try:
+        ip = socket.inet_aton(os.getenv('ADDR', ''))
+    except socket.error:
+        pass
+
+    new_prod = '0.0'
+    new_testing = '0.0'
+    output_time = False
+    vars = {}
+    for var in cdata:
+        maxverforval = '0.0'
+        for opt in cdata[var]:
+            val = opt.pop(0)
+            vers = opt.pop(0) if len(opt) else None
+            flags = opt.pop(0) if len(opt) else ''
+            debug("Examining: %s %s %s %s", var, val, vers, flags)
+            if vers == None:
+                # No version data.  Save it as the default
+                # if we don't already have one
+                if var not in vars:
+                    debug("-> Saving %s as default", val)
+                    vars[var] = val
+            elif vercmp(vers, ws_version) < 0:
+                # Too old.  Discard
+                debug("-> Discarding %s (%s < %s)", val, vers, ws_version)
+            elif ((autoupdate and 't' not in flags) or (vercmp(vers, ws_version) == 0)):
+                if vercmp(vers, ws_version) > 0:
+                    debug("-> Found newer value (%s > %s)", vers, ws_version)
+                    output_time = True
+                    if (update_time == -1) or (now < update_time):
+                        debug("-> Defering new value.")
+                        continue
+                if vercmp(vers, maxverforval) >= 0:
+                    # We found a better option
+                    debug("-> Storing %s (%s > previous max %s)", val, vers, maxverforval)
+                    maxverforval = vers
+                    vars[var] = val
+            else:
+                debug("-> Discarding, but checking new versions")
+                if 't' in flags and vercmp(vers, new_testing) > 0:
+                    debug("-> Storing new testing version %s", vers)
+                    new_testing = vers
+                if 't' not in flags and vercmp(vers, new_prod) > 0:
+                    debug("-> Storing new production version %s", vers)
+                    new_prod = vers
+
+    for v in vars:
+        output_var(v, vars[v], options.bourne, options.plain)
+
+    if vercmp(new_testing, ws_version) > 0:
+        output_var('NEW_TESTING_RELEASE', new_testing, options.bourne, options.plain)
+
+    if vercmp(new_prod, ws_version) > 0:
+        output_var('NEW_PRODUCTION_RELEASE', new_prod, options.bourne, options.plain)
+
+    if output_time:
+        if update_time == -1:
+            random.seed(socket.ntohl(ip))
+            # Python doesn't have RAND_MAX?
+            update_time = now + random.randint(0,65535) % UPDATE_INTERVAL
+        output_var('UPDATE_TIME', "%lu" % (update_time), options.bourne, options.plain)
+    
+if __name__ == '__main__':
+    sys.exit(main())


Property changes on: trunk/debathena/debathena/getcluster/getcluster.py
___________________________________________________________________
Added: svn:executable
   + *


home help back first fref pref prev next nref lref last post