Package omero :: Package plugins :: Module sessions
[hide private]
[frames] | no frames]

Source Code for Module omero.plugins.sessions

 1  #!/usr/bin/env python 
 2  """ 
 3     Plugin for viewing and controlling active sessions via the 
 4     jgroups-based ome.services.blitz.fire.Ring class 
 5   
 6     Plugin read by omero.cli.Cli during initialization. The method(s) 
 7     defined here will be added to the Cli class for later use. 
 8   
 9     Copyright 2008 Glencoe Software, Inc. All rights reserved. 
10     Use is subject to license terms supplied in LICENSE.txt 
11   
12  """ 
13   
14  import subprocess, optparse, os, sys 
15  import getpass, pickle 
16  import omero.java 
17  from omero.cli import Arguments, BaseControl, VERSION 
18  from path import path 
19   
20 -class SessionsControl(BaseControl):
21
22 - def help(self, args = None):
23 self.ctx.out("table -- print table of session data")
24
25 - def table(self, args):
26 args = Arguments(args) 27 first, other = args.firstOther() 28 files = os.listdir("blitz") 29 classpath = os.path.pathsep.join(files) 30 omero.java.run(["-cp",classpath,SessionsControl.RING, first], debug=False, xargs=[], use_exec = True)
31
32 - def isactive(self, *args):
33 args = Arguments(*args)
34
35 - def login(self, *args):
36 args = Arguments(*args) 37 name, other = args.firstOther() 38 if not name: 39 name = self._username() 40 pasw = self._password() 41 sess = self._session(name, pasw, other) 42 self._savesession(sess)
43
44 - def logout(self, *args):
45 old_sess = self._savesession(None) 46 client = omero.client() 47 client.joinSession(old_session) 48 print "Do until 0" 49 client.closeSession()
50
51 - def closeall(self, *args):
52 print "closeall"
53 54 # 55 # Private methods 56 #
57 - def _username(self):
58 defuser = getpass.getuser() 59 return raw_input("Username: [%s]" % defuser)
60
61 - def _password(self):
62 return getpass.getpass()
63
64 - def _session(self, username, password, other):
65 client = self.ctx.conn({"omero.user":username,"omero.pass":password}) 66 session_id = client.sf.ice_getIdentity().name 67 return session_id
68
69 - def _savesession(self, sess):
70 sess_file = self.ctx.userdir() / "sessionid" 71 if sess: 72 f = open(str(sess_file), "w") 73 try: 74 f.write(str(sess)) 75 print "Created session: %s" % sess 76 finally: 77 f.close() 78 return True 79 else: 80 if sess_file.exists(): 81 f = open(str(sess_file), "r") 82 try: 83 old_sess = f.readline() 84 finally: 85 f.close() 86 sess_file.remove() 87 self.ctx.out("Cleared session: %s" % old_sess) 88 return old_sess 89 else: 90 self.ctx.out("No active session") 91 return None
92 93 try: 94 register("sessions", SessionsControl) 95 except NameError: 96 SessionsControl()._main() 97