Example #1
0
    def _load_general_settings(self):
        if self.parser.has_option(PEERS, 'mx'):
            self.config.mx = self.parser.get(PEERS, 'mx')

        if self.parser.has_option(PEERS, 'scenario_dir'):
            self.config.scenario_dir = self.parser.get(PEERS, 'scenario_dir')
            self.config.scenario_dir = expand_path(self.config.scenario_dir, base_dir=self.scenario_dir)
Example #2
0
    def _load_general_settings(self):
        items = self.load[PEERS]

        if 'scenario_dir' in items:
            self.config.scenario_dir = items['scenario_dir']
            self.config.scenario_dir = expand_path(self.config.scenario_dir,
                                                   base_dir=self.scenario_dir)
Example #3
0
    def _get_experiment_details(self):
        if not self.exp_req:
            return
        exp_msg = self.comm_exp(self.mtool.fill_msg("get_experiment_info"))
        if not exp_msg:
            return

        self.origin_machine = exp_msg.origin_machine

        for peer, short_info in exp_msg.peers.iteritems():
            # self.exp_config.set_peer_machine(peer, short_info['machine'])

            msg = self.comm_exp(self.mtool.fill_msg("get_peer_info",
                                                    peer_id=peer))
            if not msg:
                return

            ext_defs = {}
            for name, defi in msg.external_params.iteritems():
                ext_defs[name] = defi[0] + '.' + defi[1]
            strict_update = os.path.exists(launcher_tools.expand_path(self.launch_file))
            self.exp_config.update_peer_config(peer, dict(config_sources=msg.config_sources,
                                                          launch_dependencies=msg.launch_dependencies,
                                                          local_params=msg.local_params,
                                                          external_params=ext_defs))

        for peer, status in exp_msg.experiment_status['peers_status'].iteritems():
            self.status.peer_status(peer).set_status(
                status['status_name'],
                                            details=status['details'])
    def _get_experiment_details(self):
        if not self.exp_req:
            return
        exp_msg = self.comm_exp(self.mtool.fill_msg("get_experiment_info"))
        if not exp_msg:
            return

        self.origin_machine = exp_msg.origin_machine

        for peer, short_info in exp_msg.peers.iteritems():
            # self.exp_config.set_peer_machine(peer, short_info['machine'])

            msg = self.comm_exp(self.mtool.fill_msg("get_peer_info",
                                        peer_id=peer))
            if not msg:
                return

            ext_defs = {}
            for name, defi in msg.external_params.iteritems():
                ext_defs[name] = defi[0] + '.' + defi[1]
            strict_update = os.path.exists(launcher_tools.expand_path(self.launch_file))
            self.exp_config.update_peer_config(peer, dict(config_sources=msg.config_sources,
                                                launch_dependencies=msg.launch_dependencies,
                                                local_params=msg.local_params,
                                                external_params=ext_defs))

        for peer, status in exp_msg.experiment_status['peers_status'].iteritems():
            self.status.peer_status(peer).set_status(
                                            status['status_name'],
                                            details=status['details'])
Example #5
0
    def _load_peer(self, peer_id, peer_items):
        # FIXME rewrite cleaner

        machine_set = False
        peer_config_file = ''
        config_section_contents = ''
        peer_path = ''

        for (param, value) in peer_items:
            # print '- - -', param, value, peer_id
            if param == "path":
                self.config.set_peer_path(peer_id, value)
                peer_path = self.config.peers[peer_id].path
                full = expand_path(peer_path)
                if not os.path.exists(full):
                    raise OBCISystemConfigError(
                        "Path to peer executable not found! Path defined: " +
                        value + "   full path:  " + expand_path(peer_path))
            elif param == "config":
                if self.config.scenario_dir:
                    warnings.warn("Choosing {0} for {1} config\
 instead of a file in scenario dir {2}!!!".format(value, peer_id,
                                                  self.config.scenario_dir))
                config_section_contents = value

            elif param == "machine":
                machine_set = True
                self._set_peer_machine(peer_id, value)
            else:
                pass
                # raise OBCISystemConfigError("Unrecognized launch file option {0}".format(param))
        if not machine_set:
            self._set_peer_machine(peer_id, '')
        if not config_section_contents:
            if self.config.scenario_dir:
                config_section_contents = os.path.join(
                    self.config.scenario_dir, peer_id + '.ini')
            else:
                # well, then we'll try to load default .ini for this peer or,
                # if default config does not exist, leave config empty
                pass
        if not peer_path:
            raise OBCISystemConfigError(
                "No program path defined for peer_id {0}".format(peer_id))
        self._parse_peer_config_section(peer_id, config_section_contents,
                                        peer_path)
Example #6
0
    def _load_general_settings(self):
        items = self.parser.items(PEERS)
        if self.parser.has_option(PEERS, 'mx'):
            self.config.mx = self.parser.get(PEERS, 'mx')

        if self.parser.has_option(PEERS, 'scenario_dir'):
            self.config.scenario_dir = self.parser.get(PEERS, 'scenario_dir')
            self.config.scenario_dir = expand_path(self.config.scenario_dir,
                                                   base_dir=self.scenario_dir)
Example #7
0
    def _load_peer(self, peer_id, peer_items):
        #FIXME rewrite cleaner

        machine_set= False
        peer_config_file = ''
        config_section_contents = ''
        peer_path = ''

        for (param, value) in peer_items:
            # print '- - -', param, value, peer_id
            if param == "path":
                self.config.set_peer_path(peer_id, value)
                peer_path = self.config.peers[peer_id].path
                full = expand_path(peer_path)
                if not os.path.exists(full):
                    raise OBCISystemConfigError("Path to peer executable not found! Path defined: " +\
                            value + "   full path:  " + expand_path(peer_path))
            elif param == "config":
                if self.config.scenario_dir:
                    warnings.warn("Choosing {0} for {1} config\
 instead of a file in scenario dir {2}!!!".format(value, peer_id, self.config.scenario_dir))
                config_section_contents = value

            elif param == "machine":
                machine_set = True
                self._set_peer_machine(peer_id, value)
            else:
                pass
                #raise OBCISystemConfigError("Unrecognized launch file option {0}".format(param))
        if not machine_set:
            self._set_peer_machine(peer_id, '')
        if not config_section_contents:
            if self.config.scenario_dir:
                config_section_contents = os.path.join(self.config.scenario_dir, peer_id + '.ini')
            else:
                # well, then we'll try to load default .ini for this peer or,
                # if default config does not exist, leave config empty
                pass
        if not peer_path:
            raise OBCISystemConfigError("No program path defined for peer_id {0}".format(peer_id))
        self._parse_peer_config_section(peer_id, config_section_contents, peer_path)
Example #8
0
    def update_from_file(self, p_config_file=None):
        if not p_config_file:
            p_config_file = self._config_file
        tpath = expand_path(p_config_file)
        if os.path.exists(tpath):
            base = os.path.basename(tpath).rsplit('.')[0]
            dirname = os.path.dirname(tpath)
            fo, path, des = imp.find_module(base, [dirname])
            mod = imp.load_module(base, fo, path, des)
            l_logic_config = mod.Config()
        else:
            dot = p_config_file.rfind('.')
            if dot < 0:
                mod = ''
                cls = p_config_file
            else:
                mod = p_config_file[:dot]
                cls = p_config_file[dot + 1:]
            print("DUPA: " + str(p_config_file))
            tmp = __import__(mod, globals(), locals(), [cls], -1)
            reload(tmp)
            l_logic_config = tmp.__dict__[cls]()
        self._states = []
        for i_state_ind in range(l_logic_config.number_of_states):
            l_state = dict()
            for i_state_variable in l_logic_config.states_configs:
                l_state[i_state_variable] = l_logic_config.__dict__[
                    i_state_variable][i_state_ind]  #TODO - shold i copy?
            self._states.append(l_state)

        self._current_state_id = 0

        # Get also config not assigned to any particular state.
        self._other_configs = dict()

        for i_config_var in l_logic_config.other_configs:
            self._other_configs[i_config_var] = (
                l_logic_config.__dict__[i_config_var]
            )  #TODO - #TODO - should i copy?
Example #9
0
    def make_experiment_config(self):
        launch_parser = launch_file_parser.LaunchFileParser(
            launcher_tools.obci_root(), settings.DEFAULT_SCENARIO_DIR)
        if not self.launch_file:
            return False, "Empty scenario."

        try:
            with open(launcher_tools.expand_path(self.launch_file)) as f:
                launch_parser.parse(f, self.exp_config, apply_globals=True)
        except Exception as e:
            self.status.set_status(launcher_tools.NOT_READY, details=str(e))
            print "config errror   ", str(e)
            return False, str(e)

        rd, details = self.exp_config.config_ready()
        if rd:
            self.status.set_status(launcher_tools.READY_TO_LAUNCH)
        else:
            self.status.set_status(launcher_tools.NOT_READY, details=details)
            print rd, details

        return True, None
    def make_experiment_config(self):
        launch_parser = launch_file_parser.LaunchFileParser(
                            launcher_tools.obci_root(), settings.DEFAULT_SCENARIO_DIR)
        if not self.launch_file:
            return False, "Empty scenario."

        try:
            with open(launcher_tools.expand_path(self.launch_file)) as f:
                launch_parser.parse(f, self.exp_config, apply_globals=True)
        except Exception as e:
            self.status.set_status(launcher_tools.NOT_READY, details=str(e))
            print "config errror   ", str(e)
            return False, str(e)

        rd, details = self.exp_config.config_ready()
        if rd:
            self.status.set_status(launcher_tools.READY_TO_LAUNCH)
        else:
            self.status.set_status(launcher_tools.NOT_READY, details=details)
            print rd, details

        return True, None
Example #11
0
    def update_from_file(self, p_config_file=None):
        if not  p_config_file:
            p_config_file = self._config_file
        tpath = expand_path(p_config_file)
        if os.path.exists(tpath):
            base = os.path.basename(tpath).rsplit('.')[0]
            dirname = os.path.dirname(tpath)
            fo, path, des = imp.find_module(base, [dirname])
            mod = imp.load_module(base, fo, path, des)
            l_logic_config = mod.Config()
        else:
            dot = p_config_file.rfind('.')
            if dot < 0:
                mod = ''
                cls = p_config_file
            else:
                mod = p_config_file[:dot]
                cls = p_config_file[dot+1:]
            print("DUPA: "+str(p_config_file))
            tmp = __import__(mod, globals(), locals(), [cls], -1)
            reload(tmp)
            l_logic_config = tmp.__dict__[cls]()
        self._states = []
        for i_state_ind in range(l_logic_config.number_of_states):
            l_state = dict()
            for i_state_variable in l_logic_config.states_configs:
                l_state[i_state_variable] = l_logic_config.__dict__[i_state_variable][i_state_ind] #TODO - shold i copy?
            self._states.append(l_state)

        self._current_state_id = 0

        # Get also config not assigned to any particular state.
        self._other_configs = dict()

        for i_config_var in l_logic_config.other_configs:
            self._other_configs[i_config_var] = (l_logic_config.__dict__[i_config_var]) #TODO - #TODO - should i copy?
Example #12
0
 def _parse_peer_config_section(self, peer_id, peer_config_section, peer_path):
     peer_config_file = expand_path(peer_config_section)
     self._parse_peer_config(peer_id, peer_config_file, peer_path)
Example #13
0
def serialize_scenario_json(p_system_config):
    buf = io.BytesIO()
    ser = LaunchFileSerializerJSON()
    ser.serialize(p_system_config, None, buf)
    return unicode(buf.getvalue())

if __name__ == '__main__':
    import launch_file_parser
    import system_config

    launch_parser = launch_file_parser.LaunchFileParser(
                            launcher_tools.obci_root(), settings.DEFAULT_SCENARIO_DIR)
    config = system_config.OBCIExperimentConfig()
    status = launcher_tools.ExperimentStatus()
    with open(launcher_tools.expand_path('scenarios/cebit/switch/hci_switch_mult_dummy.ini')) as f:
        launch_parser.parse(f, config)
    rd, details = config.config_ready()
    print rd, details
    print "INFO A"
    print config.all_param_values('amplifier')
    print "\n *********************************\n"
    json_ser = serialize_scenario_json(config)
    print json_ser

    jsonpar = launch_file_parser.LaunchJSONParser(
                        launcher_tools.obci_root(), settings.DEFAULT_SCENARIO_DIR)
    inbuf = io.BytesIO(json_ser.encode(encoding='utf-8'))
    new_conf = system_config.OBCIExperimentConfig()

    jsonpar.parse(inbuf, new_conf)
Example #14
0
def path_to_file(string):
    pth = expand_path(string)
    if not os.path.exists(pth):
        msg = "{} -- path not found!".format(pth)
        raise argparse.ArgumentTypeError(msg)
    return pth
Example #15
0
 def _parse_peer_config_section(self, peer_id, peer_config_section,
                                peer_path):
     peer_config_file = expand_path(peer_config_section)
     self._parse_peer_config(peer_id, peer_config_file, peer_path)
Example #16
0
def path_to_file(string):
    pth = expand_path(string)
    if not os.path.exists(pth):
        msg = "{} -- path not found!".format(pth)
        raise argparse.ArgumentTypeError(msg)
    return pth
Example #17
0
    def _load_general_settings(self):
        items = self.load[PEERS]

        if 'scenario_dir' in items:
            self.config.scenario_dir = items['scenario_dir']
            self.config.scenario_dir = expand_path(self.config.scenario_dir, base_dir=self.scenario_dir)