def testParser(self): parser = OptionParser() options, rest = parser.parse_args(['--verbose']) self.failUnless(options.verbose) self.failIf(rest) options, rest = parser.parse_args(['--debug', '*:5']) self.assertEqual(options.debug, "*:5") self.failIf(rest) options, rest = parser.parse_args(['rest']) self.assertEqual(rest, ["rest"])
def testParser(self): parser = OptionParser() options, rest = parser.parse_args(['--verbose']) self.failUnless(options.verbose) self.failIf(rest) options, rest = parser.parse_args(['--debug', '*:5']) self.assertEqual(options.debug, "*:5") self.failIf(rest) options, rest = parser.parse_args(['rest']) self.assertEqual(rest, ["rest"])
def testGroup(self): parser = OptionParser() group = OptionGroup(parser, "group") group.add_option('-t', '--test', action="store_true", dest="test") parser.add_option_group(group) options, rest = parser.parse_args([]) self.failIf(options.test) self.failIf(rest) options, rest = parser.parse_args(['--test']) self.failUnless(options.test) self.failIf(rest) options, rest = parser.parse_args(['--test', '--verbose', 'rest']) self.failUnless(options.test) self.failUnless(options.verbose) self.assertEqual(rest, ["rest"])
def testGroup(self): parser = OptionParser() group = OptionGroup(parser, "group") group.add_option('-t', '--test', action="store_true", dest="test") parser.add_option_group(group) options, rest = parser.parse_args([]) self.failIf(options.test) self.failIf(rest) options, rest = parser.parse_args(['--test']) self.failUnless(options.test) self.failIf(rest) options, rest = parser.parse_args(['--test', '--verbose', 'rest']) self.failUnless(options.test) self.failUnless(options.verbose) self.assertEqual(rest, ["rest"])
def main(args): global _retval parser = OptionParser(domain="flumotion-admin") parser.add_option('-m', '--manager', action="store", type="string", dest="manager", help="the manager to connect to, e.g. localhost:7531") parser.add_option('', '--no-ssl', action="store_false", dest="ssl", default=True, help="disable encryption when connecting to the manager") options, args = parser.parse_args(args) i18n.installGettext() if len(args) > 1: log.error('flumotion-admin', 'too many arguments: %r' % (args[1:], )) return 1 from flumotion.ui.icons import register_icons register_icons() from flumotion.admin.gtk.dialogs import exceptionHandler sys.excepthook = exceptionHandler from flumotion.admin.gtk.adminwindow import AdminWindow win = AdminWindow() if options.verbose or (options.debug and options.debug > 3): win.setDebugEnabled(True) if options.manager: d = _connectToManager(win, options.manager, options.ssl) else: d = showGreeter(win) # Printout unhandled exception to stderr d.addErrback(twistedlog.err) # Fixes a bug on widnows version of twisted that makes # the application to crash because _simtag is not defined. if not hasattr(reactor, '_simtag'): reactor._simtag = None reactor.run() return _retval
def main(args): parser = OptionParser(domain=configure.PACKAGE) parser.add_option('-l', '--logfile', action="store", dest="logfile", help="flumotion service log file") parser.add_option('-C', '--configdir', action="store", dest="configdir", help="flumotion configuration directory (default: %s)" % configure.configdir) parser.add_option('-L', '--logdir', action="store", dest="logdir", help="flumotion log directory (default: %s)" % configure.logdir) parser.add_option('-R', '--rundir', action="store", dest="rundir", help="flumotion run directory (default: %s)" % configure.rundir) options, args = parser.parse_args(args) # Force options down configure's throat for d in ['configdir', 'logdir', 'rundir']: o = getattr(options, d, None) if o: log.debug('service', 'Setting configure.%s to %s' % (d, o)) setattr(configure, d, o) # if log file is specified, redirect stdout and stderr if options.logfile: try: out = open(options.logfile, 'a+') err = open(options.logfile, 'a+', 0) except IOError, e: sys.stderr.write("Could not open file '%s' for writing:\n%s\n" % (options.logfile, e.strerror)) sys.exit(1) os.dup2(out.fileno(), sys.stdout.fileno()) os.dup2(err.fileno(), sys.stderr.fileno())
def main(args): global _retval parser = OptionParser(domain="flumotion-admin") parser.add_option('-m', '--manager', action="store", type="string", dest="manager", help="the manager to connect to, e.g. localhost:7531") parser.add_option('', '--no-ssl', action="store_false", dest="ssl", default=True, help="disable encryption when connecting to the manager") options, args = parser.parse_args(args) i18n.installGettext() if len(args) > 1: log.error('flumotion-admin', 'too many arguments: %r' % (args[1:], )) return 1 from flumotion.ui.icons import register_icons register_icons() from flumotion.admin.gtk.dialogs import exceptionHandler sys.excepthook = exceptionHandler from flumotion.admin.gtk.adminwindow import AdminWindow win = AdminWindow() if options.verbose or (options.debug and options.debug > 3): win.setDebugEnabled(True) if options.manager: d = _connectToManager(win, options.manager, options.ssl) else: d = showGreeter(win) # Printout unhandled exception to stderr d.addErrback(twistedlog.err) # Fixes a bug on widnows version of twisted that makes # the application to crash because _simtag is not defined. if not hasattr(reactor, '_simtag'): reactor._simtag = None reactor.run() return _retval
def main(args): parser = OptionParser(domain="flumotion-job") log.debug('job', 'Parsing arguments (%r)' % ', '.join(args)) options, args = parser.parse_args(args) # check if a config file was specified; if so, parse config and copy over if len(args) != 3: parser.error("must pass an avatarId and a path to the socket: %r" % args) avatarId = args[1] socket = args[2] # log our standardized starting marker log.info('job', "Starting job '%s'" % avatarId) # register all package paths (FIXME: this should go away when # components and all deps come from manager) # this is still necessary so that code from other projects can be imported from flumotion.common import setup setup.setupPackagePath() log.info('job', 'Connecting to worker on socket %s' % (socket)) job_factory = job.JobClientFactory(avatarId) reactor.connectWith(fdserver.FDConnector, socket, job_factory, 10, checkPID=False) # should probably move this to boot if 'FLU_PROFILE' in os.environ: try: import statprof statprof.start() print 'Profiling started.' def stop_profiling(): statprof.stop() statprof.display() reactor.addSystemEventTrigger('before', 'shutdown', stop_profiling) except ImportError, e: print ('Profiling requested, but statprof is not available (%s)' % e)
def main(args): parser = OptionParser(domain="flumotion-job") log.debug('job', 'Parsing arguments (%r)' % ', '.join(args)) options, args = parser.parse_args(args) # check if a config file was specified; if so, parse config and copy over if len(args) != 3: parser.error("must pass an avatarId and a path to the socket: %r" % args) avatarId = args[1] socket = args[2] # log our standardized starting marker log.info('job', "Starting job '%s'" % avatarId) # register all package paths (FIXME: this should go away when # components and all deps come from manager) # this is still necessary so that code from other projects can be imported from flumotion.common import setup setup.setupPackagePath() log.info('job', 'Connecting to worker on socket %s' % (socket)) job_factory = job.JobClientFactory(avatarId) reactor.connectWith(fdserver.FDConnector, socket, job_factory, 10, checkPID=False) reactor.addSystemEventTrigger('before', 'shutdown', job_factory.medium.shutdownHandler) # log our standardized started marker log.info('job', "Started job '%s'" % avatarId) reactor.run() # log our standardized stopping marker log.info('job', "Stopping job '%s'" % avatarId) # log our standardized stopped marker log.info('job', "Stopped job '%s'" % avatarId) return 0
def main(args): parser = OptionParser(domain="flumotion-admin-text") parser.add_option( "-u", "--username", action="store", type="string", dest="username", help="set username to connect to manager" ) parser.add_option( "-P", "--password", action="store", type="string", dest="password", help="set password to connect to manager" ) parser.add_option( "-H", "--hostname", action="store", type="string", dest="hostname", help="set hostname of manager to connect to" ) parser.add_option( "-p", "--port", action="store", type="string", dest="port", help="set port of manager to connect to" ) parser.add_option("", "--insecure", action="store_true", dest="insecure", help="make insecure connection") options, args = parser.parse_args(args) _runInterface(options) reactor.run()
def main(args): parser = OptionParser(domain=configure.PACKAGE) parser.add_option('-l', '--logfile', action="store", dest="logfile", help="flumotion service log file") parser.add_option('-C', '--configdir', action="store", dest="configdir", help="flumotion configuration directory (default: %s)" % configure.configdir) parser.add_option('-L', '--logdir', action="store", dest="logdir", help="flumotion log directory (default: %s)" % configure.logdir) parser.add_option('-R', '--rundir', action="store", dest="rundir", help="flumotion run directory (default: %s)" % configure.rundir) options, args = parser.parse_args(args) # Force options down configure's throat for d in ['configdir', 'logdir', 'rundir']: o = getattr(options, d, None) if o: log.debug('service', 'Setting configure.%s to %s' % (d, o)) setattr(configure, d, o) # if log file is specified, redirect stdout and stderr if options.logfile: try: out = open(options.logfile, 'a+') err = open(options.logfile, 'a+', 0) except IOError, e: sys.stderr.write("Could not open file '%s' for writing:\n%s\n" % ( options.logfile, e.strerror)) sys.exit(1) os.dup2(out.fileno(), sys.stdout.fileno()) os.dup2(err.fileno(), sys.stderr.fileno())
def main(args): parser = OptionParser(domain="flumotion-admin-text") parser.add_option('-u', '--username', action="store", type="string", dest="username", help="set username to connect to manager") parser.add_option('-P', '--password', action="store", type="string", dest="password", help="set password to connect to manager") parser.add_option('-H', '--hostname', action="store", type="string", dest="hostname", help="set hostname of manager to connect to") parser.add_option('-p', '--port', action="store", type="string", dest="port", help="set port of manager to connect to") parser.add_option('', '--insecure', action="store_true", dest="insecure", help="make insecure connection") options, args = parser.parse_args(args) _runInterface(options) reactor.run()
def main(args): from flumotion.common import setup setup.setupPackagePath() usage_str = ('Usage: %prog [options] [COMPONENT-OR-PLUG' ' [FULL-PROPERTY-NAME]]') fpname_str = ("FULL-PROPERTY-NAME: represents a fully qualified" " property name, including the names of the containing" " properties: " "...[property-name:]property-name") parser = OptionParser(usage=usage_str, description=fpname_str, domain="flumotion-inspect") log.debug('inspect', 'Parsing arguments (%r)' % ', '.join(args)) options, args = parser.parse_args(args) r = registry.getRegistry() if len(args) == 1: # print all components components = [(c.getType(), c) for c in r.getComponents()] components.sort() print '\nAvailable components:\n' for name, c in components: print ' %s' % name plugs = [(p.getType(), p) for p in r.getPlugs()] plugs.sort() print '\nAvailable plugs:\n' for name, p in plugs: print ' %s' % name print elif len(args) == 2: cname = args[1] handled = False if r.hasComponent(cname): handled = True c = r.getComponent(cname) print '\nComponent:' print ' %s' % cname desc = c.getDescription() if desc: print ' %s' % desc print '\nSource:' print ' %s' % c.getSource() print ' in %s' % c.getBase() print '\nEaters:' if c.getEaters(): for e in c.getEaters(): print (' %s (%s%s)' % (e.getName(), e.getRequired() and 'required' or 'optional', (e.getMultiple() and ', multiple ok' or ''))) else: print ' (None)' print '\nFeeders:' if c.getFeeders(): for e in c.getFeeders(): print ' %s' % e else: print ' (None)' print '\nFeatures:' features = [(p.getType(), p) for p in c.getEntries()] features.sort() if features: for k, v in features: print ' %s: %s:%s' % (k, v.getLocation(), v.getFunction()) else: print ' (None)' print '\nProperties:' printProperties(c.getProperties(), 0) sockets = c.getSockets() print '\nClocking:' print ' Needs synchronisation: %r' % c.getNeedsSynchronization() if (c.getClockPriority() is not None and c.getNeedsSynchronization()): print ' Clock priority: %d' % c.getClockPriority() print '\nSockets:' for socket in sockets: print ' %s' % socket print if r.hasPlug(cname): handled = True p = r.getPlug(cname) print '\nPlug type:' print ' %s' % cname desc = p.getDescription() if desc: print ' %s' % desc print '\nEntry:' e = p.getEntry() print ' %s() in %s' % (e.getFunction(), e.getModuleName()) print '\nProperties:' printProperties(p.getProperties(), 0) print if not handled: parser.exit(status=1, msg=('Unknown component or plug `%s\'\n' % cname)) elif len(args) == 3: cname = args[1] pname = args[2] ppath = pname.split(':') handled = False if r.hasComponent(cname): handled = True c = r.getComponent(cname) try: prop = getNestedProperty(c, ppath) except _NestedPropertyError, npe: parser.exit(status=1, msg='%s\n' % npe.message) print '\nComponent:' print ' %s' % cname desc = c.getDescription() if desc: print ' %s' % desc print '\nProperty:' printProperty(prop, len(prop.getName())) print if r.hasPlug(cname): handled = True p = r.getPlug(cname) try: prop = getNestedProperty(p, ppath) except _NestedPropertyError, npe: parser.exit(status=1, msg='%s\n' % npe.message) print '\nPlug:' print ' %s' % cname print '\nType:' print ' %s' % p.getType() print '\nProperty:' printProperty(prop, len(prop.getName())) print
def main(args): from flumotion.common import setup setup.setupPackagePath() from flumotion.configure import configure log.debug('launch', 'Running Flumotion version %s' % configure.version) import twisted.copyright log.debug('launch', 'Running against Twisted version %s' % twisted.copyright.version) from flumotion.project import project for p in project.list(): log.debug('launch', 'Registered project %s version %s' % ( p, project.get(p, 'version'))) parser = OptionParser(domain="flumotion-launch") log.debug('launch', 'Parsing arguments (%r)' % ', '.join(args)) options, args = parser.parse_args(args) i18n.installGettext() # verbose overrides --debug if options.verbose: log.setFluDebug("*:3") # handle all options if options.version: print common.version("flumotion-launch") return 0 if options.debug: log.setFluDebug(options.debug) # note parser versus parse configs = parse.parse_args(args[1:]) # load the modules, make the component wrappers = [ComponentWrapper(config) for config in configs] # make socket pairs fds = make_pipes(wrappers) reactor.running = False reactor.failure = False reactor.callLater(0, lambda: setattr(reactor, 'running', True)) d = start_components(wrappers, fds) def errback(failure): log.debug('launch', log.getFailureMessage(failure)) print "Error occurred: %s" % failure.getErrorMessage() failure.printDetailedTraceback() reactor.failure = True if reactor.running: print "Stopping reactor." reactor.stop() d.addErrback(errback) if not reactor.failure: print 'Running the reactor. Press Ctrl-C to exit.' log.debug('launch', 'Starting reactor') reactor.run() log.debug('launch', 'Reactor stopped') if reactor.failure: return 1 else: return 0
def main(args): from flumotion.common import setup setup.setupPackagePath() usage_str = ('Usage: %prog [options] [COMPONENT-OR-PLUG' ' [FULL-PROPERTY-NAME]]') fpname_str = ("FULL-PROPERTY-NAME: represents a fully qualified" " property name, including the names of the containing" " properties: " "...[property-name:]property-name") parser = OptionParser(usage=usage_str, description=fpname_str, domain="flumotion-inspect") log.debug('inspect', 'Parsing arguments (%r)' % ', '.join(args)) options, args = parser.parse_args(args) r = registry.getRegistry() if len(args) == 1: # print all components components = [(c.getType(), c) for c in r.getComponents()] components.sort() print '\nAvailable components:\n' for name, c in components: print ' %s' % name plugs = [(p.getType(), p) for p in r.getPlugs()] plugs.sort() print '\nAvailable plugs:\n' for name, p in plugs: print ' %s' % name print elif len(args) == 2: cname = args[1] handled = False if r.hasComponent(cname): handled = True c = r.getComponent(cname) print '\nComponent:' print ' %s' % cname desc = c.getDescription() if desc: print ' %s' % desc print '\nSource:' print ' %s' % c.getSource() print ' in %s' % c.getBase() print '\nEaters:' if c.getEaters(): for e in c.getEaters(): print(' %s (%s%s)' % (e.getName(), e.getRequired() and 'required' or 'optional', (e.getMultiple() and ', multiple ok' or ''))) else: print ' (None)' print '\nFeeders:' if c.getFeeders(): for e in c.getFeeders(): print ' %s' % e else: print ' (None)' print '\nFeatures:' features = [(p.getType(), p) for p in c.getEntries()] features.sort() if features: for k, v in features: print ' %s: %s:%s' % (k, v.getLocation(), v.getFunction()) else: print ' (None)' print '\nProperties:' printProperties(c.getProperties(), 0) sockets = c.getSockets() print '\nClocking:' print ' Needs synchronisation: %r' % c.getNeedsSynchronization() if (c.getClockPriority() is not None and c.getNeedsSynchronization()): print ' Clock priority: %d' % c.getClockPriority() print '\nSockets:' for socket in sockets: print ' %s' % socket print if r.hasPlug(cname): handled = True p = r.getPlug(cname) print '\nPlug type:' print ' %s' % cname desc = p.getDescription() if desc: print ' %s' % desc print '\nEntry:' e = p.getEntry() print ' %s() in %s' % (e.getFunction(), e.getModuleName()) print '\nProperties:' printProperties(p.getProperties(), 0) print if not handled: parser.exit(status=1, msg=('Unknown component or plug `%s\'\n' % cname)) elif len(args) == 3: cname = args[1] pname = args[2] ppath = pname.split(':') handled = False if r.hasComponent(cname): handled = True c = r.getComponent(cname) try: prop = getNestedProperty(c, ppath) except _NestedPropertyError, npe: parser.exit(status=1, msg='%s\n' % npe.message) print '\nComponent:' print ' %s' % cname desc = c.getDescription() if desc: print ' %s' % desc print '\nProperty:' printProperty(prop, len(prop.getName())) print if r.hasPlug(cname): handled = True p = r.getPlug(cname) try: prop = getNestedProperty(p, ppath) except _NestedPropertyError, npe: parser.exit(status=1, msg='%s\n' % npe.message) print '\nPlug:' print ' %s' % cname print '\nType:' print ' %s' % p.getType() print '\nProperty:' printProperty(prop, len(prop.getName())) print