4 ## THIS FILE IS UNDER PUPPET CONTROL. DON'T EDIT IT HERE.
5 ## USE: git clone git+ssh://$USER@puppet.debian.org/srv/puppet.debian.org/git/dsa-puppet.git
8 # Copyright (c) 2013 Peter Palfrader <peter@palfrader.org>
10 # Permission is hereby granted, free of charge, to any person obtaining
11 # a copy of this software and associated documentation files (the
12 # "Software"), to deal in the Software without restriction, including
13 # without limitation the rights to use, copy, modify, merge, publish,
14 # distribute, sublicense, and/or sell copies of the Software, and to
15 # permit persons to whom the Software is furnished to do so, subject to
16 # the following conditions:
18 # The above copyright notice and this permission notice shall be
19 # included in all copies or substantial portions of the Software.
21 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 # List the schroot sessions that a user has access to.
40 print >> sys.stderr, s
43 SESSION_PATH = '/var/lib/schroot/session'
46 def __init__(self, name):
48 self.path = os.path.join(SESSION_PATH, self.name)
50 self.mtime = os.path.getmtime(self.path)
51 self.__read_session_config()
52 self.__set_session_owner()
54 def __read_session_config(self):
55 self.config = ConfigParser.RawConfigParser()
56 self.config.read(self.path)
58 def __set_session_owner(self):
61 owner.append(self.config.get(self.name, 'users'))
62 owner.append(self.config.get(self.name, 'root-users'))
63 except ConfigParser.NoSectionError:
64 die("Did not find session definition in session file.")
65 except ConfigParser.NoOptionError:
66 die("Did not find user information in session file.")
67 self.owners = filter(lambda a: a!="", owner)
69 def __str__(self, pretty=False):
71 ts = datetime.datetime.fromtimestamp(self.mtime).isoformat().replace(':', '')
73 ts = '%d'%(self.mtime,)
75 return ':'.join([self.name, ','.join(self.owners), ts])
78 return self.__str__(pretty = True)
80 def ownermatch(self, users):
83 if fnmatch.fnmatch(o, gl): return True
87 parser = optparse.OptionParser()
88 parser.set_usage("""%prog [user]""")
89 parser.add_option("", "--mr", dest="mr", action="store_true", default=False,
90 help="print some data in a format better for post-processing (e.g. timestamps).",)
91 (options, args) = parser.parse_args()
94 users = [getpass.getuser()]
98 for name in os.listdir(SESSION_PATH):
100 if s.ownermatch(users):