def startup(self): if self.options.daemon: # detach log.info("FIXME: Daemon...") # system config self.config = SystemConfig.fromFile(self.options.config_file, self.options.use_global) # manager if not self.options.dry: log.info("Starting system.") log.info("Chimera version: %s" % find_dev_version() or _chimera_version_) log.info("Chimera prefix: %s" % ChimeraPath.root()) try: self.manager = Manager(**self.config.chimera) except ChimeraException, e: log.error( "Chimera is already running on this machine. Use chimera-admin to manage it." ) sys.exit(1) log.info("Chimera: running on " + self.manager.getHostname() + ":" + str(self.manager.getPort())) if self.options.use_global: log.info("Chimera: reading configuration from %s" % SYSTEM_CONFIG_DEFAULT_GLOBAL) log.info("Chimera: reading configuration from %s" % os.path.realpath(self.options.config_file))
def getImageServer(manager): try: toReturn = manager.getProxy('/ImageServer/0') except ObjectNotFoundException: try: toReturn = manager.addLocation('/ImageServer/imageserver', [ChimeraPath.controllers()]) except Exception, e: print ''.join(Pyro.util.getPyroTraceback(e)) raise ClassLoaderException('Unable to create imageserver')
def getImageServer(manager): try: toReturn = manager.getProxy('/ImageServer/0') except ObjectNotFoundException: try: toReturn = manager.addLocation('/ImageServer/imageserver', ChimeraPath().controllers) except Exception, e: print ''.join(Pyro.util.getPyroTraceback(e)) raise ClassLoaderException('Unable to create imageserver')
def __init__(self, args = [], wait=True): self.wait = wait self.options, self.args = self.parseArgs(args) if self.options.verbose == 1: chimera.core.log.setConsoleLevel(logging.INFO) if self.options.verbose > 1: chimera.core.log.setConsoleLevel(logging.DEBUG) self.manager = None self.paths = {"instruments": [], "controllers": []} # add system path self.paths["instruments"].append(ChimeraPath.instruments()) self.paths["controllers"].append(ChimeraPath.controllers())
def __init__(self, args=[], wait=True): self.wait = wait self.options, self.args = self.parseArgs(args) if self.options.verbose == 1: chimera.core.log.setConsoleLevel(logging.INFO) if self.options.verbose > 1: chimera.core.log.setConsoleLevel(logging.DEBUG) self.manager = None self.paths = {"instruments": [], "controllers": [], "drivers": []} # add system path self.paths["instruments"].append(ChimeraPath.instruments()) self.paths["controllers"].append(ChimeraPath.controllers()) self.paths["drivers"].append(ChimeraPath.drivers())
def addController (self, **params): params["type"] = ParameterType.CONTROLLER self.addParameters(params) if self._needControllersPath: if not "PATHS" in self._helpGroups: self.addHelpGroup("PATHS", "Object Paths") self.addParameters(dict(name="ctrl_dir", short="C", long="controllers-dir", helpGroup="PATHS", type=ParameterType.INCLUDE_PATH, default=[ChimeraPath.controllers()], help="Append PATH to controllers load path. " "This option could be setted multiple " "times to add multiple directories.", metavar="PATH")) self._needControllersPath = False
def addInstrument (self, **params): params["type"] = ParameterType.INSTRUMENT self.addParameters(params) if self._needInstrumentsPath: if not "PATHS" in self._helpGroups: self.addHelpGroup("PATHS", "Object Paths") self.addParameters(dict(name="inst_dir", short="I", long="instruments-dir", helpGroup="PATHS", type=ParameterType.INCLUDE_PATH, default=[ChimeraPath.instruments()], help="Append PATH to %s load path. " "This option could be setted multiple " "times to add multiple directories." % params["name"].capitalize(), metavar="PATH")) self._needInstrumentsPath = False
def addController(self, **params): params["type"] = ParameterType.CONTROLLER self.addParameters(params) if self._needControllersPath: if not "PATHS" in self._helpGroups: self.addHelpGroup("PATHS", "Object Paths") self.addParameters( dict(name="ctrl_dir", short="C", long="controllers-dir", helpGroup="PATHS", type=ParameterType.INCLUDE_PATH, default=ChimeraPath().controllers, help="Append PATH to controllers load path. " "This option could be setted multiple " "times to add multiple directories.", metavar="PATH")) self._needControllersPath = False
def addInstrument(self, **params): params["type"] = ParameterType.INSTRUMENT self.addParameters(params) if self._needInstrumentsPath: if not "PATHS" in self._helpGroups: self.addHelpGroup("PATHS", "Object Paths") self.addParameters( dict(name="inst_dir", short="I", long="instruments-dir", helpGroup="PATHS", type=ParameterType.INCLUDE_PATH, default=ChimeraPath().instruments, help="Append PATH to %s load path. " "This option could be setted multiple " "times to add multiple directories." % params["name"].capitalize(), metavar="PATH")) self._needInstrumentsPath = False
def getPath(): return ChimeraPath()
def startup(self): if self.options.daemon: # detach log.info("FIXME: Daemon...") # system config try: self.config = SystemConfig.fromFile(self.options.config_file) except (InvalidLocationException, IOError) as e: log.exception(e) log.error( "There was a problem reading your configuration file. (%s)" % e) sys.exit(1) # manager if not self.options.dry: log.info("Starting system.") log.info("Chimera: %s" % _chimera_version_) log.info("Chimera prefix: %s" % ChimeraPath().root()) log.info("Python: %s" % platform.python_version()) log.info("System: %s" % ' '.join(platform.uname())) try: self.manager = Manager(**self.config.chimera) except ChimeraException as e: log.error( "Chimera is already running on this machine. Use chimera-admin to manage it." ) sys.exit(1) log.info("Chimera: running on " + self.manager.getHostname() + ":" + str(self.manager.getPort())) log.info("Chimera: reading configuration from %s" % os.path.realpath(self.options.config_file)) # add site object if not self.options.dry: for site in self.config.sites: self.manager.addClass(Site, site.name, site.config, True) # search paths log.info( "Setting objects include path from command line parameters...") for _dir in self.options.inst_dir: self.paths["instruments"].append(_dir) for _dir in self.options.ctrl_dir: self.paths["controllers"].append(_dir) # init from config log.info("Trying to start instruments...") for inst in self.config.instruments + self.options.instruments: if self.options.dry: print(inst) else: self._add(inst, path=self.paths["instruments"], start=True) log.info("Trying to start controllers...") for ctrl in self.config.controllers + self.options.controllers: if self.options.dry: print(ctrl) else: self._add(ctrl, path=self.paths["controllers"], start=True) log.info("System up and running.") # ok, let's wait manager work if self.wait and not self.options.dry: self.manager.wait()
class SiteController(object): def __init__(self, args=[], wait=True): self.wait = wait self.options, self.args = self.parseArgs(args) if self.options.verbose == 1: chimera.core.log.setConsoleLevel(logging.INFO) #log.setConsoleLevel(logging.INFO) if self.options.verbose > 1: chimera.core.log.setConsoleLevel(logging.DEBUG) #log.setConsoleLevel(logging.DEBUG) self.manager = None self.paths = {"instruments": [], "controllers": []} # add system and plugins paths Path = ChimeraPath() self.paths["instruments"].extend(Path.instruments) self.paths["controllers"].extend(Path.controllers) def parseArgs(self, args): def check_location(option, opt_str, value, parser): try: l = Location(value) except InvalidLocationException: raise optparse.OptionValueError("%s isnt't a valid location." % value) eval('parser.values.%s.append ("%s")' % (option.dest, value)) def check_includepath(option, opt_str, value, parser): if not value or not os.path.isdir(os.path.abspath(value)): raise optparse.OptionValueError( "Couldn't found %s include path." % value) eval('parser.values.%s.append ("%s")' % (option.dest, value)) parser = optparse.OptionParser( prog="chimera", version=_chimera_version_, description=_chimera_description_, usage="chimera --help for more information") manag_group = optparse.OptionGroup(parser, "Basic options") manag_group.add_option( "-H", "--host", action="store", dest="pyro_host", type="string", help="Host name/IP address to run as; [default=%default]", metavar="HOST") manag_group.add_option( "-P", "--port", action="store", dest="pyro_port", type="string", help="Port on which to listen for requests; [default=%default]", metavar="PORT") config_group = optparse.OptionGroup(parser, "Configuration") config_group.add_option( "--config", dest="config_file", help="Start Chimera using configuration from FILE.", metavar="FILE") config_group.add_option( "--daemon", action="store_true", dest='daemon', help= "Run Chimera in Daemon mode (will detach from current terminal).") misc_group = optparse.OptionGroup(parser, "General") misc_group.add_option( "--dry-run", action="store_true", dest="dry", help= "Only list all configured objects (from command line and configuration files) without starting the system." ) misc_group.add_option( "-v", "--verbose", action="count", dest='verbose', help="Increase log level (multiple v's to increase even more).") inst_group = optparse.OptionGroup( parser, "Instruments and Controllers Management") inst_group.add_option( "-i", "--instrument", action="callback", callback=check_location, dest="instruments", type="string", help="Load the instrument defined by LOCATION." "This option could be set many times to load multiple instruments.", metavar="LOCATION") inst_group.add_option( "-c", "--controller", action="callback", callback=check_location, dest="controllers", type="string", help="Load the controller defined by LOCATION." "This option could be set many times to load multiple controllers.", metavar="LOCATION") inst_group.add_option("-I", "--instruments-dir", action="callback", callback=check_includepath, dest="inst_dir", type="string", help="Append PATH to instruments load path.", metavar="PATH") inst_group.add_option("-C", "--controllers-dir", action="callback", callback=check_includepath, dest="ctrl_dir", type="string", help="Append PATH to controllers load path.", metavar="PATH") parser.add_option_group(manag_group) parser.add_option_group(config_group) parser.add_option_group(misc_group) parser.add_option_group(inst_group) parser.set_defaults(instruments=[], controllers=[], config_file=SYSTEM_CONFIG_DEFAULT_FILENAME, inst_dir=[], ctrl_dir=[], drv_dir=[], dry=False, verbose=0, daemon=False, pyro_host=MANAGER_DEFAULT_HOST, pyro_port=MANAGER_DEFAULT_PORT) return parser.parse_args(args) def startup(self): if self.options.daemon: # detach log.info("FIXME: Daemon...") # system config try: self.config = SystemConfig.fromFile(self.options.config_file) except (InvalidLocationException, IOError), e: log.exception(e) log.error( "There was a problem reading your configuration file. (%s)" % e) sys.exit(1) # manager if not self.options.dry: log.info("Starting system.") log.info("Chimera: %s" % _chimera_version_) log.info("Chimera prefix: %s" % ChimeraPath().root()) log.info("Python: %s" % platform.python_version()) log.info("System: %s" % ' '.join(platform.uname())) try: self.manager = Manager(**self.config.chimera) except ChimeraException, e: log.error( "Chimera is already running on this machine. Use chimera-admin to manage it." ) sys.exit(1) log.info("Chimera: running on " + self.manager.getHostname() + ":" + str(self.manager.getPort())) log.info("Chimera: reading configuration from %s" % os.path.realpath(self.options.config_file))