Ejemplo n.º 1
0
    def _pyscript_runner_default(self):
        if self.mode == 'client':
            #            em = self.extraction_line_manager
            ip = InitializationParser()
            elm = ip.get_plugin('Experiment', category='general')
            runner = elm.find('runner')
            host, port, kind = None, None, None

            if runner is not None:
                comms = runner.find('communications')
                host = comms.find('host')
                port = comms.find('port')
                kind = comms.find('kind')

            if host is not None:
                host = host.text  # if host else 'localhost'
            if port is not None:
                port = int(port.text)  # if port else 1061
                kind = kind.text  # if kind else 'udp'

            runner = RemotePyScriptRunner(host, port, kind)
        else:
            runner = PyScriptRunner()

        return runner
Ejemplo n.º 2
0
    def _manager_factory(self):
        """
        """

        ip = InitializationParser()
        plugin = ip.get_plugin(self.klass[1].replace('Manager', ''),
                               category='hardware')
        mode = ip.get_parameter(plugin, 'mode')

        if mode == 'client':
            klass = ip.get_parameter(plugin, 'klass')
            if klass is None:
                klass = 'PychronLaserManager'

            pkg = 'pychron.lasers.laser_managers.pychron_laser_manager'
            try:
                tag = ip.get_parameter(plugin, 'communications', element=True)
                #                tag = plugin.find('communications')
                params = dict()
                for attr in ['host', 'port', 'kind']:
                    try:
                        params[attr] = tag.find(attr).text.strip()
                    except Exception, e:
                        print 'client comms fail', attr, e
            except Exception, e:
                print 'client comms fail', e

            params['name'] = self.name
            factory = __import__(pkg, fromlist=[klass])
            m = getattr(factory, klass)(**params)
Ejemplo n.º 3
0
 def _sources_default(self):
     ip = InitializationParser()
     plugin = ip.get_plugin(self.task_name.replace(' ', ''),
                            category='hardware')
     source = ip.get_parameter(plugin, 'video_source')
     rs = []
     if source:
         rs = [(source, self.task_name)]
     return rs
Ejemplo n.º 4
0
def build_globals(debug):
    from pychron.initialization_parser import InitializationParser

    ip = InitializationParser()

    from pychron.globals import globalv

    globalv.build(ip)
    globalv.debug = debug
Ejemplo n.º 5
0
def get_hardware_plugins():
    ip = InitializationParser()

    ps = []
    if 'hardware' in ip.get_categories():
        from pychron.hardware.tasks.hardware_plugin import HardwarePlugin

        if ip.get_plugins('hardware'):
            ps = [HardwarePlugin(), ]
    return ps
Ejemplo n.º 6
0
    def _factory(self):
        from pychron.initialization_parser import InitializationParser

        ip = InitializationParser()
        try:
            plugin = ip.get_plugin('ExtractionLine', category='hardware')
            mode = ip.get_parameter(plugin, 'mode')
        #            mode = plugin.get('mode')
        except AttributeError:
            # no epxeriment plugin defined
            mode = 'normal'

        elm = ExtractionLineManager(mode=mode)
        elm.bind_preferences()
        return elm
Ejemplo n.º 7
0
    def _manager_factory(self):
        from pychron.experiment.experimentor import Experimentor
        from pychron.initialization_parser import InitializationParser

        ip = InitializationParser()
        plugin = ip.get_plugin('Experiment', category='general')
        mode = ip.get_parameter(plugin, 'mode')

        app = None
        if self.window:
            app = self.window.application

        exp = Experimentor(application=app,
                           mode=mode)

        return exp
Ejemplo n.º 8
0
    def _processors_default(self):
        ps = dict()
        ip = InitializationParser()

        hosts = []
        # load the hosts file
        p = os.path.join(paths.setup_dir, 'hosts')
        if os.path.isfile(p):
            with open(p, 'r') as f:
                hosts = [l.strip() for l in f if l.strip()]

        for pi in ip.get_processors():
            cp = self._command_processor_factory(path=pi)
            cp._hosts = hosts

            ps[cp.name] = cp

        return ps
Ejemplo n.º 9
0
    def _load_servers(self):
        '''
        '''
        # get server names
        ip = InitializationParser()
        names = ip.get_servers()
        if names:
            for s in names:
                pn = '{}-processor'.format(s)
                cp = self._command_processor_factory(name=pn)
                cp.manager = self
                cp.bootstrap()

                self.processors[pn] = cp
                e = RemoteCommandServer(name=s,
                                        configuration_dir_name='servers',
                                        processor=cp)
                e.bootstrap()
                self.servers.append(e)
Ejemplo n.º 10
0
    def bind_preferences(self, cp):
        try:
            bind_preference(self, 'system_lock',
                            'pychron.hardware.enable_system_lock')

            bind_preference(cp, 'system_lock',
                            'pychron.hardware.enable_system_lock')
            bind_preference(cp, 'system_lock_address',
                            'pychron.hardware.system_lock_address')
            bind_preference(cp, 'system_lock_name',
                            'pychron.hardware.system_lock_name')

            #        ip = InitializationParser(os.path.join(setup_dir, 'initialization.xml'))
            ip = InitializationParser()
            names = []
            hosts = dict()
            for name, host in ip.get_systems():
                names.append(name)
                hosts[name] = host

            pref = self.application.preferences
            pref.set('pychron.hardware.system_lock_names', names)
            pref.set('pychron.hardware.system_lock_addresses', hosts)

            name = pref.get('pychron.hardware.system_lock_name')

            try:
                if name:
                    pref.set('pychron.hardware.system_lock_address',
                             hosts[name.strip("'").lower()])
                else:
                    pref.set('pychron.hardware.system_lock_address',
                             hosts[names[0].lower()])
            except Exception, err:
                pass

    #            import traceback
    #            traceback.print_exc()
    #            print 'system lock exception', err

            pref.save()
Ejemplo n.º 11
0
    def _monitor_factory(self):
        mon = None
        isok = True
        self.debug('Experiment Executor mode={}'.format(self.mode))
        if self.mode == 'client':
            ip = InitializationParser()
            exp = ip.get_plugin('Experiment', category='general')
            monitor = exp.find('monitor')
            if monitor is not None:
                if to_bool(monitor.get('enabled')):
                    host, port, kind = None, None, None
                    comms = monitor.find('communications')
                    host = comms.find('host')
                    port = comms.find('port')
                    kind = comms.find('kind')

                    if host is not None:
                        host = host.text  # if host else 'localhost'
                    if port is not None:
                        port = int(port.text)  # if port else 1061
                    if kind is not None:
                        kind = kind.text
                    mon = RemoteAutomatedRunMonitor(host,
                                                    port,
                                                    kind,
                                                    name=monitor.text.strip())
        else:
            mon = AutomatedRunMonitor()

        self.debug('Automated run monitor {}'.format(mon))
        if mon is not None:
            #        mon.configuration_dir_name = paths.monitors_dir
            isok = mon.load()
            if isok:
                return mon
            else:
                self.warning(
                    'no automated run monitor avaliable. Make sure config file is located at setupfiles/monitors/automated_run_monitor.cfg'
                )
Ejemplo n.º 12
0
def get_user_plugins():
    """
    """
    # append plugins dir to the sys path
    #    sys.path.append(plugins_dir)

    plugins = []
    ps = InitializationParser().get_plugins()

    core_added = False
    for p in ps:
        # if laser plugin add CoreLaserPlugin
        if p in ('FusionsCO2', 'FusionsDiode'):
            plugin = get_plugin('CoreLaserPlugin')
            if plugin and not core_added:
                core_added = True
                plugins.append(plugin)

        plugin = get_plugin(p)
        if plugin:
            plugins.append(plugin)

    return plugins
Ejemplo n.º 13
0
    def __init__(self, *args, **kw):

        super(Initializer, self).__init__(*args, **kw)
        self.clear()
        self.cnt = 0
        self.parser = InitializationParser()