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

Source Code for Module omero.plugins.basics

  1  #!/usr/bin/env python 
  2  """ 
  3     load, quit, version, help plugins 
  4   
  5     Plugin read by omero.cli.Cli during initialization. The method(s) 
  6     defined here will be added to the Cli class for later use. 
  7   
  8     The load plugin is used to read in files with omero cli commands 
  9     (omitting the omero). For example, 
 10   
 11     ./omero load some/file.osh 
 12   
 13     The help, quit, and version plugins are self-explanatory. 
 14   
 15     Copyright 2008 Glencoe Software, Inc. All rights reserved. 
 16     Use is subject to license terms supplied in LICENSE.txt 
 17   
 18  """ 
 19   
 20  import subprocess, optparse, os, sys 
 21  from omero.cli import Arguments, BaseControl, VERSION 
 22   
23 -class DebugControl(BaseControl):
24 - def help(self, args = None):
25 self.ctx.out("Run command with debug")
26 - def __call__(self, *args):
27 args = Arguments(*args) 28 self.ctx.setdebug() 29 self.ctx.pub(args)
30
31 -class TraceControl(BaseControl):
32 - def help(self, args = None):
33 self.ctx.out("Run command with tracing turned on")
34 - def __call__(self, *args):
35 args = Arguments(*args) 36 import trace 37 tracer = trace.Trace() 38 tracer.runfunc(self.ctx.pub, args)
39
40 -class ProfileControl(BaseControl):
41 - def help(self, args = None):
42 self.ctx.out("Run command with profiling")
43
44 - def __call__(self, *args):
45 args = Arguments(*args) 46 import hotshot 47 from hotshot import stats 48 prof = hotshot.Profile("hotshot_edi_stats") 49 rv = prof.runcall( lambda: self.ctx.pub(args) ) 50 prof.close() 51 s = stats.load("hotshot_edi_stats") 52 s.sort_stats("time").print_stats()
53
54 -class QuitControl(BaseControl):
55
56 - def help(self, args = None):
57 self.ctx.out("Quit application")
58
59 - def __call__(self, *args):
60 self.ctx.exit("")
61
62 -class VersionControl(BaseControl):
63
64 - def help(self, args = None):
65 self.ctx.out("Version number")
66
67 - def __call__(self, *args):
68 self.ctx.out(VERSION)
69
70 -class LoadControl(BaseControl):
71
72 - def help(self = None):
73 status = "enabled" 74 try: 75 import readline 76 except: 77 status = "disabled" 78 79 self.ctx.out( 80 """ 81 Syntax: %%(program_name)s file1 file2 file3 82 83 Load file as if it were sent on standard in. File tab-completion %s" 84 """ % status )
85
86 - def __call__(self, *args):
87 args = Arguments(*args) 88 for arg in args: 89 file = open(arg,'r') 90 self.ctx.dbg("Loading file %s" % arg) 91 for line in file: 92 self.pub.ctx(line)
93
94 -class ShellControl(BaseControl):
95
96 - def help(self, args = None):
97 self.ctx.out("Starts an IPython interpreter session")
98
99 - def __call__(self, *args):
100 """ 101 Copied from IPython embed-short example 102 """ 103 args = Arguments(*args) 104 from IPython.Shell import IPShellEmbed 105 ipshell = IPShellEmbed(args.args) 106 ipshell()
107 108 try: 109 register("load", LoadControl) 110 register("quit", QuitControl) 111 register("shell", ShellControl) 112 register("version", VersionControl) 113 register("debug", DebugControl) 114 register("profile", ProfileControl) 115 register("trace", TraceControl) 116 except NameError: 117 VersionControl()._main() 118