def _manager_default(self):
        from pychron.envisage.initialization.initialization_parser import \
            InitializationParser

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

        proto = 'pychron.database.isotope_database_manager.IsotopeDatabaseManager'
        iso_db_man = self.application.get_service(proto)
        # experimentor.iso_db_man = iso_db_man

        proto = 'pychron.dvc.dvc.DVC'
        dvc = self.application.get_service(proto)
        # experimentor.dvc = dvc

        experimentor = Experimentor(application=self.application,
                                    mode=mode,
                                    dvc=dvc,
                                    iso_db_man=iso_db_man)

        experimentor.executor.set_managers()
        experimentor.executor.bind_preferences()

        return experimentor
Exemplo n.º 2
0
def get_initialization_model():
    ip = InitializationParser()
    rtree = load_plugin_tree()
    gtree = load_global_tree()
    for gi in ip.get_plugin_groups():
        tree = get_tree(gi, rtree)
        if tree:
            ps = ip.get_plugins(gi, element=True)
            if ps:
                for pp in ps:
                    plugin = get_plugin(pp.text.strip(), tree)
                    if plugin:
                        plugin.enabled = to_bool(pp.get('enabled'))

    for gi in ip.get_globals():
        gv = gtree.get_value(gi.tag)
        if gv:
            gv.enabled = to_bool(gi.text.strip())

    model = InitializationModel(trees=[gtree, rtree],
                                path_name=os.path.basename(ip.path),
                                parser=ip)
    model.init_hash()

    return model
Exemplo n.º 3
0
    def run(self, application=None):
        self._parser = InitializationParser()
        self.info('Initialization Path: {}'.format(self._parser.path))

        self.application = application

        ok = True
        self.info('Running Initializer')
        nsteps = sum([self._get_nsteps(idict['plugin_name']) for idict in self._init_list]) + 1

        pd = self._setup_progress(nsteps)
        try:
            for idict in self._init_list:
                ok = self._run(**idict)
                if not ok:
                    break

            msg = ('Complete' if ok else 'Failed')
            self.info('Initialization {}'.format(msg))

            pd.close()
        except BaseException as e:
            import traceback
            traceback.print_exc()
            self.debug('Initializer Exception: {}'.format(e))
            raise e

        return ok
    def _runner_factory(self):

        ip = InitializationParser()
        elm = ip.get_plugin('ClientExtractionLine', category='hardware')
        runner = elm.find('runner')
        if runner is None:
            self.warning_dialog(
                'Script Runner is not configured in the Initialization file. See documentation'
            )
            return

        host, port, kind, frame = None, None, None, None

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

        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  # if kind else 'udp'
        if frame is not None:
            frame = frame.text

        runner = RemotePyScriptRunner(host, port, kind, frame)
        return runner
Exemplo n.º 5
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
Exemplo n.º 6
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
Exemplo n.º 7
0
    def _manager_factory(self):
        """
        """

        ip = InitializationParser()
        plugin = ip.get_plugin(self.klass[1].replace('Manager', ''),
                               category='hardware')
        mode = ip.get_parameter(plugin, 'mode')
        self.mode = mode
        klass = ip.get_parameter(plugin, 'klass')
        if klass is None and mode == 'client':
            klass = 'PychronLaserManager'
            pkg = 'pychron.lasers.laser_managers.pychron_laser_manager'
            factory = __import__(pkg, fromlist=[klass])
            klassfactory = getattr(factory, klass)
        else:
            factory = __import__(self.klass[0], fromlist=[self.klass[1]])
            klassfactory = getattr(factory, self.klass[1])

        params = dict(name=self.name)
        if mode == 'client':
            try:
                tag = ip.get_parameter(plugin, 'communications', element=True)
                for attr in [
                        'host', 'port', 'kind', 'message_frame',
                    ('use_end', to_bool)
                ]:
                    func = None
                    if isinstance(attr, tuple):
                        attr, func = attr

                    try:
                        elem = tag.find(attr)
                        if elem is not None:
                            v = elem.text.strip()
                            if func:
                                v = func(v)

                            params[attr] = v
                        else:
                            self.debug(
                                'No communications attribute {}'.format(attr))
                    except Exception as e:
                        print('client comms fail a', attr, e)
            except Exception as e:
                print('client comms fail b', e)

        m = klassfactory(**params)
        m.mode = mode
        m.bootstrap()
        m.plugin_id = self.id
        m.bind_preferences(self.id)
        return m
Exemplo n.º 8
0
def build_globals(user, debug):
    try:
        from pychron.envisage.initialization.initialization_parser import InitializationParser
    except ImportError as e:
        from pyface.message_dialog import warning

        warning(None, str(e))

    ip = InitializationParser()

    from pychron.globals import globalv

    globalv.build(ip)
    globalv.debug = debug
    globalv.username = user
    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
    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)
    def _bind_processor_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()
Exemplo n.º 12
0
    def _manager_default(self):
        from pychron.envisage.initialization.initialization_parser import \
            InitializationParser

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

        man = Experimentor(application=self.application, mode=mode)

        iso = 'pychron.database.isotope_database_manager.IsotopeDatabaseManager'
        manager = self.application.get_service(iso)

        dvc = self.application.get_service('pychron.dvc.dvc.DVC')
        if dvc:
            man.dvc = dvc

        man.iso_db_manager = manager
        man.executor.set_managers()
        man.executor.bind_preferences()

        return man
Exemplo n.º 13
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
Exemplo n.º 14
0
def add_eggs(root):
    egg_path = os.path.join(root, 'pychron.pth')
    if os.path.isfile(egg_path):
        # use a pychron.pth to get additional egg paths
        with open(egg_path, 'r') as rfile:
            eggs = [ei.strip() for ei in rfile.read().split('\n')]
            eggs = [ei for ei in eggs if ei]

            for egg_name in eggs:
                # sys.path.insert(0, os.path.join(root, egg_name))
                sys.path.append(os.path.join(root, egg_name))
                print os.path.join(root, egg_name)


def build_globals(debug):
    try:
        from pychron.envisage.initialization.initialization_parser import InitializationParser
    except ImportError, e:
        from pyface.message_dialog import warning

        warning(None, str(e))

    ip = InitializationParser()

    from pychron.globals import globalv

    globalv.build(ip)
    globalv.debug = debug

# ============= EOF =============================================