Exemplo n.º 1
0
    def get_json_target_data():
        """Load the description of JSON target data"""
        targets = json_file_to_dict(Target.__targets_json_location or
                                    Target.__targets_json_location_default)

        for extra_target in Target.__extra_target_json_files:
            for k, v in json_file_to_dict(extra_target).iteritems():
                if k in targets:
                    print 'WARNING: Custom target "%s" cannot replace existing target.' % k
                else:
                    targets[k] = v

        return targets
Exemplo n.º 2
0
    def get_json_target_data():
        """Load the description of JSON target data"""
        targets = json_file_to_dict(Target.__targets_json_location
                                    or Target.__targets_json_location_default)

        for extra_target in Target.__extra_target_json_files:
            for k, v in json_file_to_dict(extra_target).iteritems():
                if k in targets:
                    print 'WARNING: Custom target "%s" cannot replace existing target.' % k
                else:
                    targets[k] = v

        return targets
Exemplo n.º 3
0
    def add_config_files(self, flist):
        """Add configuration files

        Positional arguments:
        flist - a list of files to add to this configuration
        """
        for config_file in flist:
            if not config_file.endswith(self.__mbed_lib_config_name):
                continue
            full_path = os.path.normpath(os.path.abspath(config_file))
            # Check that we didn't already process this file
            if self.processed_configs.has_key(full_path):
                continue
            self.processed_configs[full_path] = True
            # Read the library configuration and add a "__full_config_path"
            # attribute to it
            try:
                cfg = json_file_to_dict(config_file)
            except ValueError as exc:
                sys.stderr.write(str(exc) + "\n")
                continue

            # Validate the format of the JSON file based on the schema_lib.json
            schema_root = os.path.dirname(os.path.abspath(__file__))
            schema_path = os.path.join(schema_root, "schema_lib.json")
            schema_file = json_file_to_dict(schema_path)

            url = moves.urllib.request.pathname2url(schema_path)
            uri = moves.urllib_parse.urljoin("file://", url)

            resolver = RefResolver(uri, schema_file)
            validator = Draft4Validator(schema_file, resolver=resolver)

            errors = sorted(validator.iter_errors(cfg))

            if errors:
                raise ConfigException(",".join(x.message for x in errors))

            cfg["__config_path"] = full_path

            # If there's already a configuration for a module with the same
            # name, exit with error
            if self.lib_config_data.has_key(cfg["name"]):
                raise ConfigException(
                    "Library name '%s' is not unique (defined in '%s' and '%s')"
                    % (cfg["name"], full_path,
                       self.lib_config_data[cfg["name"]]["__config_path"]))
            self.lib_config_data[cfg["name"]] = cfg
Exemplo n.º 4
0
 def __init__(self, target, top_level_dirs=[]):
     app_config_location = None
     for s in (top_level_dirs or []):
         full_path = os.path.join(s, self.__mbed_app_config_name)
         if os.path.isfile(full_path):
             if app_config_location is not None:
                 raise ConfigException(
                     "Duplicate '%s' file in '%s' and '%s'" %
                     (self.__mbed_app_config_name, app_config_location,
                      full_path))
             else:
                 app_config_location = full_path
     self.app_config_data = json_file_to_dict(
         app_config_location) if app_config_location else {}
     # Check the keys in the application configuration data
     unknown_keys = set(
         self.app_config_data.keys()) - self.__allowed_keys["application"]
     if unknown_keys:
         raise ConfigException(
             "Unknown key(s) '%s' in %s" %
             (",".join(unknown_keys), self.__mbed_app_config_name))
     # Update the list of targets with the ones defined in the application config, if applicable
     Target.add_py_targets(self.app_config_data.get("custom_targets", {}))
     self.lib_config_data = {}
     # Make sure that each config is processed only once
     self.processed_configs = {}
     self.target = target if isinstance(target, str) else target.name
     self.target_labels = Target.get_target(self.target).get_labels()
     self.target_instance = Target.get_target(self.target)
Exemplo n.º 5
0
    def __init__(self, target, top_level_dirs = []):
        app_config_location = None
        for s in (top_level_dirs or []):
            full_path = os.path.join(s, self.__mbed_app_config_name)
            if os.path.isfile(full_path):
                if app_config_location is not None:
                    raise ConfigException("Duplicate '%s' file in '%s' and '%s'" % (self.__mbed_app_config_name, app_config_location, full_path))
                else:
                    app_config_location = full_path
        self.app_config_data = json_file_to_dict(app_config_location) if app_config_location else {}
        # Check the keys in the application configuration data
        unknown_keys = set(self.app_config_data.keys()) - self.__allowed_keys["application"]
        if unknown_keys:
            raise ConfigException("Unknown key(s) '%s' in %s" % (",".join(unknown_keys), self.__mbed_app_config_name))
        # Update the list of targets with the ones defined in the application config, if applicable
        Target.add_py_targets(self.app_config_data.get("custom_targets", {}))
        self.lib_config_data = {}
        # Make sure that each config is processed only once
        self.processed_configs = {}
        self.target = target if isinstance(target, basestring) else target.name
        self.target_labels = Target.get_target(self.target).get_labels()

        self.cumulative_overrides = { key: ConfigCumulativeOverride(key) 
                                      for key in Target._Target__cumulative_attributes }

        self._process_config_and_overrides(self.app_config_data, {}, "app", "application")
        self.target_labels = Target.get_target(self.target).get_labels()
Exemplo n.º 6
0
    def add_config_files(self, flist):
        """Add configuration files

        Positional arguments:
        flist - a list of files to add to this configuration
        """
        for config_file in flist:
            if not config_file.endswith(self.__mbed_lib_config_name):
                continue
            full_path = os.path.normpath(os.path.abspath(config_file))
            # Check that we didn't already process this file
            if self.processed_configs.has_key(full_path):
                continue
            self.processed_configs[full_path] = True
            # Read the library configuration and add a "__full_config_path"
            # attribute to it
            try:
                cfg = json_file_to_dict(config_file)
            except ValueError as exc:
                sys.stderr.write(str(exc) + "\n")
                continue

            cfg["__config_path"] = full_path

            if "name" not in cfg:
                raise ConfigException(
                    "Library configured at %s has no name field." % full_path)
            # If there's already a configuration for a module with the same
            # name, exit with error
            if self.lib_config_data.has_key(cfg["name"]):
                raise ConfigException(
                    "Library name '%s' is not unique (defined in '%s' and '%s')"
                    % (cfg["name"], full_path,
                       self.lib_config_data[cfg["name"]]["__config_path"]))
            self.lib_config_data[cfg["name"]] = cfg
    def add_config_files(self, flist):
        """Add configuration files

        Positional arguments:
        flist - a list of files to add to this configuration
        """
        for config_file in flist:
            if not config_file.endswith(self.__mbed_lib_config_name):
                continue
            full_path = os.path.normpath(os.path.abspath(config_file))
            # Check that we didn't already process this file
            if self.processed_configs.has_key(full_path):
                continue
            self.processed_configs[full_path] = True
            # Read the library configuration and add a "__full_config_path"
            # attribute to it
            try:
                cfg = json_file_to_dict(config_file)
            except ValueError as exc:
                sys.stderr.write(str(exc) + "\n")
                continue

            cfg["__config_path"] = full_path

            if "name" not in cfg:
                raise ConfigException(
                    "Library configured at %s has no name field." % full_path)
            # If there's already a configuration for a module with the same
            # name, exit with error
            if self.lib_config_data.has_key(cfg["name"]):
                raise ConfigException(
                    "Library name '%s' is not unique (defined in '%s' and '%s')"
                    % (cfg["name"], full_path,
                       self.lib_config_data[cfg["name"]]["__config_path"]))
            self.lib_config_data[cfg["name"]] = cfg
Exemplo n.º 8
0
    def __init__(self, target, top_level_dirs=None):
        """Construct a mbed configuration

        Positional arguments:
        target - the name of the mbed target used for this configuration
                 instance

        Keyword argumets:
        top_level_dirs - a list of top level source directories (where
                         mbed_abb_config.json could be found)

        NOTE: Construction of a Config object will look for the application
        configuration file in top_level_dirs. If found once, it'll parse it and
        check if it has a custom_targets function. If it does, it'll update the
        list of targets as needed. If more than one config file is found, an
        exception is raised. top_level_dirs may be None (in this case,
        the constructor will not search for a configuration file)
        """
        app_config_location = None
        for directory in top_level_dirs or []:
            full_path = os.path.join(directory, self.__mbed_app_config_name)
            if os.path.isfile(full_path):
                if app_config_location is not None:
                    raise ConfigException(
                        "Duplicate '%s' file in '%s' and '%s'" %
                        (self.__mbed_app_config_name, app_config_location,
                         full_path))
                else:
                    app_config_location = full_path
        self.app_config_data = json_file_to_dict(app_config_location) \
                               if app_config_location else {}
        # Check the keys in the application configuration data
        unknown_keys = set(self.app_config_data.keys()) - \
                       self.__allowed_keys["application"]
        if unknown_keys:
            raise ConfigException(
                "Unknown key(s) '%s' in %s" %
                (",".join(unknown_keys), self.__mbed_app_config_name))
        # Update the list of targets with the ones defined in the application
        # config, if applicable
        Target.add_py_targets(self.app_config_data.get("custom_targets", {}))
        self.lib_config_data = {}
        # Make sure that each config is processed only once
        self.processed_configs = {}
        self.target = target if isinstance(target, basestring) else target.name
        self.target_labels = Target.get_target(self.target).get_labels()

        self.cumulative_overrides = {
            key: ConfigCumulativeOverride(key)
            for key in Target.cumulative_attributes
        }

        self._process_config_and_overrides(self.app_config_data, {}, "app",
                                           "application")
        self.target_labels = Target.get_target(self.target).get_labels()
        self.config_errors = None
Exemplo n.º 9
0
    def get_json_target_data():
        """Load the description of JSON target data"""
        from_file = (Target.__targets_json_location or
                     Target.__targets_json_location_default)

        targets = json_file_to_dict(from_file)
        for tgt in targets.values():
            tgt["_from_file"] = from_file

        for extra_target in Target.__extra_target_json_files:
            for k, v in json_file_to_dict(extra_target).items():
                if k in targets:
                    print('WARNING: Custom target "%s" cannot replace existing '
                          'target.' % k)
                else:
                    targets[k] = v
                    targets[k]["_from_file"] = extra_target

        return targets
Exemplo n.º 10
0
    def __init__(self, target, top_level_dirs=None):
        """Construct a mbed configuration

        Positional arguments:
        target - the name of the mbed target used for this configuration
                 instance

        Keyword argumets:
        top_level_dirs - a list of top level source directories (where
                         mbed_abb_config.json could be found)

        NOTE: Construction of a Config object will look for the application
        configuration file in top_level_dirs. If found once, it'll parse it and
        check if it has a custom_targets function. If it does, it'll update the
        list of targets as needed. If more than one config file is found, an
        exception is raised. top_level_dirs may be None (in this case,
        the constructor will not search for a configuration file)
        """
        app_config_location = None
        for directory in top_level_dirs or []:
            full_path = os.path.join(directory, self.__mbed_app_config_name)
            if os.path.isfile(full_path):
                if app_config_location is not None:
                    raise ConfigException("Duplicate '%s' file in '%s' and '%s'"
                                          % (self.__mbed_app_config_name,
                                             app_config_location, full_path))
                else:
                    app_config_location = full_path
        self.app_config_data = json_file_to_dict(app_config_location) \
                               if app_config_location else {}
        # Check the keys in the application configuration data
        unknown_keys = set(self.app_config_data.keys()) - \
                       self.__allowed_keys["application"]
        if unknown_keys:
            raise ConfigException("Unknown key(s) '%s' in %s" %
                                  (",".join(unknown_keys),
                                   self.__mbed_app_config_name))
        # Update the list of targets with the ones defined in the application
        # config, if applicable
        Target.add_py_targets(self.app_config_data.get("custom_targets", {}))
        self.lib_config_data = {}
        # Make sure that each config is processed only once
        self.processed_configs = {}
        self.target = target if isinstance(target, basestring) else target.name
        self.target_labels = Target.get_target(self.target).get_labels()

        self.cumulative_overrides = {key: ConfigCumulativeOverride(key)
                                     for key in
                                     Target.cumulative_attributes}

        self._process_config_and_overrides(self.app_config_data, {}, "app",
                                           "application")
        self.target_labels = Target.get_target(self.target).get_labels()
        self.config_errors = None
Exemplo n.º 11
0
 def add_config_files(self, flist):
     for f in flist:
         if not f.endswith(self.__mbed_lib_config_name):
             continue
         full_path = os.path.normpath(os.path.abspath(f))
         # Check that we didn't already process this file
         if self.processed_configs.has_key(full_path):
             continue
         self.processed_configs[full_path] = True
         # Read the library configuration and add a "__full_config_path" attribute to it
         cfg = json_file_to_dict(f)
         cfg["__config_path"] = full_path
         # If there's already a configuration for a module with the same name, exit with error
         if self.lib_config_data.has_key(cfg["name"]):
             raise ConfigException("Library name '%s' is not unique (defined in '%s' and '%s')" % (cfg["name"], full_path, self.lib_config_data[cfg["name"]]["__config_path"]))
         self.lib_config_data[cfg["name"]] = cfg
Exemplo n.º 12
0
from os.path import dirname, abspath, join, exists

from tools.utils import json_file_to_dict
from tools.targets import TARGET_MAP
from tools.config import Config

CONFIG_DIR = dirname(abspath(__file__))
CONFIG_MAP = json_file_to_dict(join(CONFIG_DIR, "config_paths.json"))
TARGET_CONFIGS = json_file_to_dict(join(CONFIG_DIR, "target_configs.json"))

def get_valid_configs(target_name):
    if target_name in TARGET_CONFIGS:
        target_config = TARGET_CONFIGS[target_name]
    elif (target_name in TARGET_MAP and 'EMAC' in TARGET_MAP[target_name].device_has):
        target_config = { "default_test_configuration": "ETHERNET", "test_configurations": ["ETHERNET"] }
    else:
        return {}

    config_dict = {}
    for attr in CONFIG_MAP:
        if attr in target_config['test_configurations']:
            config_dict[attr] = CONFIG_MAP[attr]
    return config_dict

def get_config_path(conf_name, target_name):
    configs = get_valid_configs(target_name)
    if configs and conf_name.upper() in configs:
        return join(CONFIG_DIR, configs[conf_name.upper()])
    else:
        return None
Exemplo n.º 13
0
 def get_json_target_data():
     return json_file_to_dict(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'hal', 'targets.json'))
    def __init__(self, tgt, top_level_dirs=None, app_config=None):
        """Construct a mbed configuration

        Positional arguments:
        target - the name of the mbed target used for this configuration
                 instance

        Keyword argumets:
        top_level_dirs - a list of top level source directories (where
                         mbed_app_config.json could be found)
        app_config - location of a chosen mbed_app.json file

        NOTE: Construction of a Config object will look for the application
        configuration file in top_level_dirs. If found once, it'll parse it.
        top_level_dirs may be None (in this case, the constructor will not
        search for a configuration file).
        """
        config_errors = []
        self.app_config_location = app_config
        if self.app_config_location is None:
            for directory in top_level_dirs or []:
                full_path = os.path.join(directory, self.__mbed_app_config_name)
                if os.path.isfile(full_path):
                    if self.app_config_location is not None:
                        raise ConfigException("Duplicate '%s' file in '%s' and '%s'"
                                              % (self.__mbed_app_config_name,
                                                 self.app_config_location, full_path))
                    else:
                        self.app_config_location = full_path
        try:
            self.app_config_data = json_file_to_dict(self.app_config_location) \
                                   if self.app_config_location else {}
        except ValueError as exc:
            self.app_config_data = {}
            config_errors.append(
                ConfigException("Could not parse mbed app configuration from %s"
                                % self.app_config_location))

        # Check the keys in the application configuration data
        unknown_keys = set(self.app_config_data.keys()) - \
                       set(self.__allowed_keys["application"].keys())
        if unknown_keys:
            raise ConfigException("Unknown key(s) '%s' in %s" %
                                  (",".join(unknown_keys),
                                   self.__mbed_app_config_name))
        check_dict_types(self.app_config_data, self.__allowed_keys["application"],
                         "app-config")
        # Update the list of targets with the ones defined in the application
        # config, if applicable
        self.lib_config_data = {}
        # Make sure that each config is processed only once
        self.processed_configs = {}
        if isinstance(tgt, basestring):
            if tgt in TARGET_MAP:
                self.target = TARGET_MAP[tgt]
            else:
                self.target = generate_py_target(
                    self.app_config_data.get("custom_targets", {}), tgt)

        else:
            self.target = tgt
        self.target = deepcopy(self.target)
        self.target_labels = self.target.labels

        self.cumulative_overrides = {key: ConfigCumulativeOverride(key)
                                     for key in CUMULATIVE_ATTRIBUTES}

        self._process_config_and_overrides(self.app_config_data, {}, "app",
                                           "application")
        self.config_errors = config_errors
Exemplo n.º 15
0
 def get_json_target_data():
     """Load the description of JSON target data"""
     return json_file_to_dict(Target.__targets_json_location
                              or Target.__targets_json_location_default)
Exemplo n.º 16
0
from os.path import dirname, abspath, join

from tools.utils import json_file_to_dict
from tools.targets import TARGET_MAP

CONFIG_DIR = dirname(abspath(__file__))
CONFIG_MAP = json_file_to_dict(join(CONFIG_DIR, "config_paths.json"))
TARGET_CONFIGS = json_file_to_dict(join(CONFIG_DIR, "target_configs.json"))


def get_valid_configs(target_name):
    if target_name in TARGET_CONFIGS:
        target_config = TARGET_CONFIGS[target_name]
    elif (target_name in TARGET_MAP
          and 'LWIP' in TARGET_MAP[target_name].features):
        target_config = {
            "default_test_configuration": "ETHERNET",
            "test_configurations": ["ETHERNET"]
        }
    else:
        return {}

    config_dict = {}
    for attr in CONFIG_MAP:
        if attr in target_config['test_configurations']:
            config_dict[attr] = CONFIG_MAP[attr]
    return config_dict


def get_config_path(conf_name, target_name):
    configs = get_valid_configs(target_name)
Exemplo n.º 17
0
 def get_json_target_data():
     return json_file_to_dict(
         os.path.join(os.path.dirname(os.path.abspath(__file__)), '..',
                      'hal', 'targets.json'))
Exemplo n.º 18
0
    def __init__(self, tgt, top_level_dirs=None, app_config=None):
        """Construct a mbed configuration

        Positional arguments:
        target - the name of the mbed target used for this configuration
                 instance

        Keyword argumets:
        top_level_dirs - a list of top level source directories (where
                         mbed_app_config.json could be found)
        app_config - location of a chosen mbed_app.json file

        NOTE: Construction of a Config object will look for the application
        configuration file in top_level_dirs. If found once, it'll parse it.
        top_level_dirs may be None (in this case, the constructor will not
        search for a configuration file).
        """
        app_config_location = app_config
        if app_config_location is None:
            for directory in top_level_dirs or []:
                full_path = os.path.join(directory, self.__mbed_app_config_name)
                if os.path.isfile(full_path):
                    if app_config_location is not None:
                        raise ConfigException("Duplicate '%s' file in '%s' and '%s'"
                                              % (self.__mbed_app_config_name,
                                                 app_config_location, full_path))
                    else:
                        app_config_location = full_path
        try:
            self.app_config_data = json_file_to_dict(app_config_location) \
                                   if app_config_location else {}
        except ValueError as exc:
            sys.stderr.write(str(exc) + "\n")
            self.app_config_data = {}

        # Check the keys in the application configuration data
        unknown_keys = set(self.app_config_data.keys()) - \
                       self.__allowed_keys["application"]
        if unknown_keys:
            raise ConfigException("Unknown key(s) '%s' in %s" %
                                  (",".join(unknown_keys),
                                   self.__mbed_app_config_name))
        # Update the list of targets with the ones defined in the application
        # config, if applicable
        self.lib_config_data = {}
        # Make sure that each config is processed only once
        self.processed_configs = {}
        if isinstance(tgt, basestring):
            if tgt in TARGET_MAP:
                self.target = TARGET_MAP[tgt]
            else:
                self.target = generate_py_target(
                    self.app_config_data.get("custom_targets", {}), tgt)

        else:
            self.target = tgt
        self.target = deepcopy(self.target)
        self.target_labels = self.target.labels

        self.cumulative_overrides = {key: ConfigCumulativeOverride(key)
                                     for key in CUMULATIVE_ATTRIBUTES}

        self._process_config_and_overrides(self.app_config_data, {}, "app",
                                           "application")
        self.config_errors = None
Exemplo n.º 19
0
 def get_json_target_data():
     """Load the description of JSON target data"""
     return json_file_to_dict(Target.__targets_json_location or
                              Target.__targets_json_location_default)
Exemplo n.º 20
0
 def get_json_target_data():
     return json_file_to_dict(Target.__targets_json_location)
Exemplo n.º 21
0
    def __init__(self, tgt, top_level_dirs=None, app_config=None):
        """Construct a mbed configuration

        Positional arguments:
        target - the name of the mbed target used for this configuration
                 instance

        Keyword argumets:
        top_level_dirs - a list of top level source directories (where
                         mbed_app_config.json could be found)
        app_config - location of a chosen mbed_app.json file

        NOTE: Construction of a Config object will look for the application
        configuration file in top_level_dirs. If found once, it'll parse it.
        top_level_dirs may be None (in this case, the constructor will not
        search for a configuration file).
        """
        config_errors = []
        self.app_config_location = app_config
        if self.app_config_location is None and top_level_dirs:
            self.app_config_location = self.find_app_config(top_level_dirs)
        try:
            self.app_config_data = json_file_to_dict(self.app_config_location) \
                                   if self.app_config_location else {}
        except ValueError as exc:
            self.app_config_data = {}
            config_errors.append(
                ConfigException(
                    "Could not parse mbed app configuration from %s" %
                    self.app_config_location))

        if self.app_config_location is not None:
            # Validate the format of the JSON file based on schema_app.json
            schema_root = os.path.dirname(os.path.abspath(__file__))
            schema_path = os.path.join(schema_root, "schema_app.json")
            schema = json_file_to_dict(schema_path)

            url = moves.urllib.request.pathname2url(schema_path)
            uri = moves.urllib_parse.urljoin("file://", url)

            resolver = RefResolver(uri, schema)
            validator = Draft4Validator(schema, resolver=resolver)

            errors = sorted(validator.iter_errors(self.app_config_data))

            if errors:
                raise ConfigException(",".join(x.message for x in errors))

        # Update the list of targets with the ones defined in the application
        # config, if applicable
        self.lib_config_data = {}
        # Make sure that each config is processed only once
        self.processed_configs = {}
        if isinstance(tgt, basestring):
            if tgt in TARGET_MAP:
                self.target = TARGET_MAP[tgt]
            else:
                self.target = generate_py_target(
                    self.app_config_data.get("custom_targets", {}), tgt)

        else:
            self.target = tgt
        self.target = deepcopy(self.target)
        self.target_labels = self.target.labels
        for override in BOOTLOADER_OVERRIDES:
            _, attr = override.split(".")
            setattr(self.target, attr, None)

        self.cumulative_overrides = {
            key: ConfigCumulativeOverride(key)
            for key in CUMULATIVE_ATTRIBUTES
        }

        self._process_config_and_overrides(self.app_config_data, {}, "app",
                                           "application")
        self.config_errors = config_errors