]> git.donarmstrong.com Git - dsa-puppet.git/commitdiff
Ship a schroot-list-sessions
authorPeter Palfrader <peter@palfrader.org>
Mon, 22 Apr 2013 21:02:44 +0000 (23:02 +0200)
committerPeter Palfrader <peter@palfrader.org>
Mon, 22 Apr 2013 21:03:27 +0000 (23:03 +0200)
modules/porterbox/files/schroot-list-sessions [new file with mode: 0755]
modules/porterbox/manifests/init.pp

diff --git a/modules/porterbox/files/schroot-list-sessions b/modules/porterbox/files/schroot-list-sessions
new file mode 100755 (executable)
index 0000000..6a999f6
--- /dev/null
@@ -0,0 +1,78 @@
+#!/usr/bin/python
+
+##
+## THIS FILE IS UNDER PUPPET CONTROL. DON'T EDIT IT HERE.
+## USE: git clone git+ssh://$USER@puppet.debian.org/srv/puppet.debian.org/git/dsa-puppet.git
+##
+
+# Copyright (c) 2013 Peter Palfrader <peter@palfrader.org>
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+# List the schroot sessions that a user has access to.
+
+import ConfigParser
+import fnmatch
+import getpass
+import optparse
+import os
+import sys
+
+def die(s):
+    print >> sys.stderr, s
+    sys.exit(1)
+
+SESSION_PATH = '/var/lib/schroot/session'
+def get_session_owner(session):
+    path = os.path.join(SESSION_PATH, session)
+    config = ConfigParser.RawConfigParser()
+    config.read(path)
+    owner = []
+    try:
+        owner.append(config.get(session, 'users'))
+        owner.append(config.get(session, 'root-users'))
+    except ConfigParser.NoSectionError:
+        die("Did not find session definition in session file.")
+    except ConfigParser.NoOptionError:
+        die("Did not find user information in session file.")
+    return filter(lambda a: a!="", owner)
+
+def ownermatch(owners, users):
+    for gl in users:
+        for o in owners:
+            if fnmatch.fnmatch(o, gl): return True
+    return False
+
+def list_schroots(users):
+    for session in os.listdir(SESSION_PATH):
+        owners = get_session_owner(session)
+        if ownermatch(owners, users):
+            print "%s:%s"%(session, ','.join(owners))
+
+parser = optparse.OptionParser()
+parser.set_usage("""%prog [user]""")
+(options, args) = parser.parse_args()
+
+if len(args) < 1:
+    users = [getpass.getuser()]
+else:
+    users = args
+
+list_schroots(users)
index 7b08b8b4b9a301a82534c46b7dbdb945ced0d1ec..4d4d3a90d32a28a07e7471f81d91048533a0b1c6 100644 (file)
@@ -25,6 +25,10 @@ class porterbox {
                mode    => 555,
                source  => 'puppet:///modules/porterbox/dd-schroot-cmd',
        }
+       file { '/usr/local/bin/schroot-list-sessions':
+               mode    => 555,
+               source  => 'puppet:///modules/porterbox/schroot-list-sessions',
+       }
        file { '/usr/local/sbin/setup-dchroot':
                mode    => 555,
                source  => 'puppet:///modules/porterbox/setup-dchroot',