Beispiel #1
0
def getDerivedTarget(target_name_and_version, targets_path, install_missing=True, update_installed=False):
    ''' Get the specified target description, optionally ensuring that it (and
        all dependencies) are installed in targets_path.

        Returns (DerivedTarget, errors), or (None, errors) if the leaf target
        could not be found/installed.
    '''
    logger.debug('satisfy target: %s' % target_name_and_version);
    if ',' in target_name_and_version:
        name, ver = target_name_and_version.split(',')
        dspec = pack.DependencySpec(name, ver)
    else:
        dspec = pack.DependencySpec(target_name_and_version, "*")
    
    leaf_target      = None
    previous_name    = dspec.name
    search_dirs      = [targets_path]
    target_hierarchy = []
    errors           = []
    while True:
        t = None
        try:
            if install_missing:
                t = access.satisfyVersion(
                                 name = dspec.name,
                     version_required = dspec.version_req,
                            available = target_hierarchy,
                         search_paths = search_dirs,
                    working_directory = targets_path,
                     update_installed = ('Update' if update_installed else None),
                                 type = 'target'
                )
            else:
                t = access.satisfyVersionFromSearchPaths(
                                 name = dspec.name,
                     version_required = dspec.version_req,
                         search_paths = search_dirs,
                                 type = 'target'
                )
        except access_common.Unavailable as e:
            errors.append(e)
        if not t:
            if install_missing:
                logger.error(
                    'could not install target %s %s for %s' %
                    (dspec.name, ver, previous_name)
                )
            break
        else:
            target_hierarchy.append(t)
            previous_name = dspec.name
            dspec = t.baseTargetSpec()
            if not leaf_target:
                leaf_target = t
            if dspec is None:
                break
    if leaf_target is None:
        return (None, errors)
    else:
        return (DerivedTarget(leaf_target, target_hierarchy[1:]), errors)
Beispiel #2
0
 def satisfyTarget(self, target_name_and_version, update_installed=False):
     ''' Ensure that the specified target name (and optionally version,
         github ref or URL) is installed in the targets directory of the
         current component
     '''
     logger.debug('satisfy target: %s' % target_name_and_version);
     if ',' in target_name_and_version:
         name, ver = target_name_and_version.split(',')
         dspec = pack.DependencySpec(name, ver)
     else:
         dspec = pack.DependencySpec(target_name_and_version, "*")
     
     leaf_target      = None
     previous_name    = dspec.name
     search_dirs      = [self.targetsPath()]
     target_hierarchy = []
     errors           = []
     while True:
         t = None
         try:
             t = access.satisfyVersion(
                              name = dspec.name,
                  version_required = dspec.version_req,
                         available = target_hierarchy,
                      search_paths = search_dirs,
                 working_directory = self.targetsPath(),
                  update_installed = ('Update' if update_installed else None),
                              type = 'target'
             )
         except access_common.Unavailable as e:
             errors.append(e)
         if not t:
             logger.error(
                 'could not install target %s %s for %s' %
                 (dspec.name, ver, previous_name)
             )
             break
         else:
             target_hierarchy.append(t)
             previous_name = dspec.name
             dspec = t.baseTargetSpec()
             if not leaf_target:
                 leaf_target = t
             if dspec is None:
                 break
     if leaf_target is None:
         return (None, errors)
     else:
         return (target.DerivedTarget(leaf_target, target_hierarchy[1:]), errors)
Beispiel #3
0
def getDerivedTarget(
        target_name_and_version,
                   targets_path,
                application_dir = None,
                install_missing = True,
               update_installed = False
    ):
    ''' Get the specified target description, optionally ensuring that it (and
        all dependencies) are installed in targets_path.

        Returns (DerivedTarget, errors), or (None, errors) if the leaf target
        could not be found/installed.
    '''
    logger.debug('satisfy target: %s' % target_name_and_version);
    if ',' in target_name_and_version:
        name, ver = target_name_and_version.split(',')
        dspec = pack.DependencySpec(name, ver)
    else:
        dspec = pack.DependencySpec(target_name_and_version, "*")

    leaf_target      = None
    previous_name    = dspec.name
    search_dirs      = [targets_path]
    target_hierarchy = []
    errors           = []
    while True:
        t = None
        try:
            if install_missing:
                t = access.satisfyVersion(
                                 name = dspec.name,
                     version_required = dspec.version_req,
                            available = target_hierarchy,
                         search_paths = search_dirs,
                    working_directory = targets_path,
                     update_installed = ('Update' if update_installed else None),
                                 type = 'target'
                )
            else:
                t = access.satisfyVersionFromSearchPaths(
                                 name = dspec.name,
                     version_required = dspec.version_req,
                         search_paths = search_dirs,
                                 type = 'target'
                )
        except access_common.Unavailable as e:
            errors.append(e)
        if not t:
            if install_missing:
                logger.error(
                    'could not install target %s for %s' %
                    (dspec, previous_name)
                )
            break
        else:
            target_hierarchy.append(t)
            previous_name = dspec.name
            assert(isinstance(t, Target))
            dspec = t.baseTargetSpec() #pylint: disable=no-member
            if not leaf_target:
                leaf_target = t
            if dspec is None:
                break
    if leaf_target is None:
        return (None, errors)
    # if we have a valid target, try to load the app-specific config data (if
    # any):
    app_config = {}
    if application_dir is not None:
        app_config_fname = os.path.join(application_dir, App_Config_File)
        if os.path.exists(app_config_fname):
            try:
                app_config = ordered_json.load(app_config_fname)
            except Exception as e:
                errors.append(Exception("Invalid application config.json: %s" % (e)))
    return (DerivedTarget(leaf_target, target_hierarchy[1:], app_config), errors)
Beispiel #4
0
def getDerivedTarget(target_name_and_version,
                     targets_path,
                     application_dir=None,
                     install_missing=True,
                     update_installed=False):
    ''' Get the specified target description, optionally ensuring that it (and
        all dependencies) are installed in targets_path.

        Returns (DerivedTarget, errors), or (None, errors) if the leaf target
        could not be found/installed.
    '''
    logger.debug('satisfy target: %s' % target_name_and_version)
    if ',' in target_name_and_version:
        name, ver = target_name_and_version.split(',')
        dspec = pack.DependencySpec(name, ver)
    else:
        dspec = pack.DependencySpec(target_name_and_version, "*")

    leaf_target = None
    previous_name = dspec.name
    search_dirs = [targets_path]
    target_hierarchy = []
    errors = []
    while True:
        t = None
        try:
            if install_missing:
                t = access.satisfyVersion(
                    name=dspec.name,
                    version_required=dspec.version_req,
                    available=target_hierarchy,
                    search_paths=search_dirs,
                    working_directory=targets_path,
                    update_installed=('Update' if update_installed else None),
                    type='target')
            else:
                t = access.satisfyVersionFromSearchPaths(
                    name=dspec.name,
                    version_required=dspec.version_req,
                    search_paths=search_dirs,
                    type='target')
        except access_common.Unavailable as e:
            errors.append(e)
        if not t:
            if install_missing:
                logger.error('could not install target %s for %s' %
                             (dspec, previous_name))
            break
        else:
            target_hierarchy.append(t)
            previous_name = dspec.name
            assert (isinstance(t, Target))
            dspec = t.baseTargetSpec()  #pylint: disable=no-member
            if not leaf_target:
                leaf_target = t
            if dspec is None:
                break
    if leaf_target is None:
        return (None, errors)
    # if we have a valid target, try to load the app-specific config data (if
    # any):
    app_config = {}
    if application_dir is not None:
        app_config_fname = os.path.join(application_dir, App_Config_File)
        if os.path.exists(app_config_fname):
            try:
                app_config = ordered_json.load(app_config_fname)
            except Exception as e:
                errors.append(
                    Exception("Invalid application config.json: %s" % (e)))
    return (DerivedTarget(leaf_target, target_hierarchy[1:],
                          app_config), errors)