コード例 #1
0
ファイル: component.py プロジェクト: geky/yotta
        def provider(
            dspec,
            available_components,
            search_dirs,
            working_directory,
            update_installed,
            dep_of=None
        ):
            r = access.satisfyFromAvailable(dspec.name, available_components)
            if r:
                if r.isTestDependency() and not dspec.is_test_dependency:
                    logger.debug('test dependency subsequently occurred as real dependency: %s', r.getName())
                    r.setTestDependency(False)
                return r
            update_if_installed = False
            if update_installed is True:
                update_if_installed = True
            elif update_installed:
                update_if_installed = dspec.name in update_installed
            r = access.satisfyVersionFromSearchPaths(
                dspec.name,
                dspec.versionReq(),
                search_dirs,
                update_if_installed,
                inherit_shrinkwrap = dep_of.getShrinkwrap()
            )
            if r:
                r.setTestDependency(dspec.is_test_dependency)
                return r
            # before resorting to install this module, check if we have an
            # existing linked module (which wasn't picked up because it didn't
            # match the version specification) - if we do, then we shouldn't
            # try to install, but should return that anyway:
            default_path = os.path.join(self.modulesPath(), dspec.name)
            if fsutils.isLink(default_path):
                r = Component(
                                       default_path,
                     test_dependency = dspec.is_test_dependency,
                    installed_linked = fsutils.isLink(default_path),
                  inherit_shrinkwrap = dep_of.getShrinkwrap()
                )
                if r:
                    assert(r.installedLinked())
                    return r
                else:
                    logger.error('linked module %s is invalid: %s', dspec.name, r.getError())
                    return r

            r = access.satisfyVersionByInstalling(
                dspec.name,
                dspec.versionReq(),
                self.modulesPath(),
                inherit_shrinkwrap = dep_of.getShrinkwrap()
            )
            if not r:
                logger.error('could not install %s' % dspec.name)
            if r is not None:
                r.setTestDependency(dspec.is_test_dependency)
            return r
コード例 #2
0
ファイル: component.py プロジェクト: stevenewey/yotta
 def provideInstalled(self,
                     dspec,
      available_components,
               search_dirs,
         working_directory,
       update_if_installed,
               dep_of_name
     ):
     r = access.satisfyFromAvailable(dspec.name, available_components)
     if r:
         if r.isTestDependency() and not dspec.is_test_dependency:
             logger.debug('test dependency subsequently occurred as real dependency: %s', r.getName())
             r.setTestDependency(False)
         return r
     r = access.satisfyVersionFromSearchPaths(dspec.name, dspec.version_req, search_dirs, update_if_installed)
     if r:
         r.setTestDependency(dspec.is_test_dependency)
         return r
     # return a module initialised to the path where we would have
     # installed this module, so that it's possible to use
     # getDependenciesRecursive to find a list of failed dependencies,
     # as well as just available ones
     # note that this Component object may still be valid (usable to
     # attempt a build), if a different version was previously installed
     # on disk at this location (which means we need to check if the
     # existing version is linked)
     default_path = os.path.join(self.modulesPath(), dspec.name)
     r = Component(
                            default_path,
          test_dependency = dspec.is_test_dependency,
         installed_linked = fsutils.isLink(default_path)
     )
     return r
コード例 #3
0
 def provideInstalled(self, dspec, available_components, search_dirs,
                      working_directory, update_if_installed, dep_of_name):
     r = access.satisfyFromAvailable(dspec.name, available_components)
     if r:
         if r.isTestDependency() and not dspec.is_test_dependency:
             logger.debug(
                 'test dependency subsequently occurred as real dependency: %s',
                 r.getName())
             r.setTestDependency(False)
         return r
     r = access.satisfyVersionFromSearchPaths(dspec.name, dspec.version_req,
                                              search_dirs,
                                              update_if_installed)
     if r:
         r.setTestDependency(dspec.is_test_dependency)
         return r
     # return a module initialised to the path where we would have
     # installed this module, so that it's possible to use
     # getDependenciesRecursive to find a list of failed dependencies,
     # as well as just available ones
     # note that this Component object may still be valid (usable to
     # attempt a build), if a different version was previously installed
     # on disk at this location (which means we need to check if the
     # existing version is linked)
     default_path = os.path.join(self.modulesPath(), dspec.name)
     r = Component(default_path,
                   test_dependency=dspec.is_test_dependency,
                   installed_linked=fsutils.isLink(default_path))
     return r
コード例 #4
0
ファイル: access.py プロジェクト: parisk/yotta
def satisfyTarget(name, version_required, working_directory, update_installed=None):
    ''' returns a Target for the specified version (either to an already
        installed copy (from disk), or to a newly downloaded one), or None if
        the version could not be satisfied.

        update_installed = {None, 'Check', 'Update'}
            None:   prevent any attempt to look for new versions if the
                    target already exists
            Check:  check for new versions, and pass new version information to
                    the target object
            Update: replace any existing version with the newest available, if
                    the newest available has a higher version
    '''
    
    spec = None
    v = None
    
    target_path = os.path.join(working_directory, name)
    local_target = target.Target(
                    target_path,
               installed_linked = fsutils.isLink(target_path),
        latest_suitable_version = v
    )
    
    if local_target and (local_target.installedLinked() or update_installed != 'Update' or not local_target.outdated()):
        # if a target exists (has a valid description file), and either is
        # not outdated, or we are not updating
        return local_target

    # if we need to check for latest versions, get the latest available version
    # before checking for a local target so that we can create the local
    # target with a handle to its latest available version
    if update_installed is None:
        logger.debug('attempt to check latest version of %s @%s...' % (name, version_required))
        v = latestSuitableVersion(name, version_required, registry='targets')
    elif local_target and local_target.outdated():
        logger.info('%soutdated: %s@%s -> %s' % (
            ('update ' if update_installed == 'Update' else ''),
            name,
            local_target.getVersion(),
            v
        ))
        # must rm the old target before continuing
        fsutils.rmRf(target_path)

    if not v and update_installed is not None:
        v = latestSuitableVersion(name, version_required, registry='targets')

    if not v:
        raise access_common.TargetUnavailable(
            'Target "%s":"%s" is not a supported form.' % (name, version_required)
        )
    directory = os.path.join(working_directory, name)
    v.unpackInto(directory)
    r = target.Target(directory)
    if not r:
        raise Exception(
            'Dependency "%s":"%s" is not a valid target.' % (name, version_required)
        )
    return r
コード例 #5
0
        def provider(
            dspec,
            available_components,
            search_dirs,
            working_directory,
            update_installed,
            dep_of_name=None
        ):
            r = access.satisfyFromAvailable(dspec.name, available_components)
            if r:
                if r.isTestDependency() and not dspec.is_test_dependency:
                    logger.debug('test dependency subsequently occurred as real dependency: %s', r.getName())
                    r.setTestDependency(False)
                return r
            update_if_installed = False
            if update_installed is True:
                update_if_installed = True
            elif update_installed:
                update_if_installed = dspec.name in update_installed
            r = access.satisfyVersionFromSearchPaths(dspec.name, dspec.version_req, search_dirs, update_if_installed)
            if r:
                r.setTestDependency(dspec.is_test_dependency)
                return r
            # before resorting to install this module, check if we have an
            # existing linked module (which wasn't picked up because it didn't
            # match the version specification) - if we do, then we shouldn't
            # try to install, but should return that anyway:
            default_path = os.path.join(self.modulesPath(), dspec.name)
            if fsutils.isLink(default_path):
                r = Component(
                                       default_path,
                     test_dependency = dspec.is_test_dependency,
                    installed_linked = fsutils.isLink(default_path)
                )
                if r:
                    assert(r.installedLinked())
                    return r
                else:
                    logger.error('linked module %s is invalid: %s', dspec.name, r.getError())
                    return r

            r = access.satisfyVersionByInstalling(dspec.name, dspec.version_req, self.modulesPath())
            if not r:
                logger.error('could not install %s' % dspec.name)
            if r is not None:
                r.setTestDependency(dspec.is_test_dependency)
            return r
コード例 #6
0
def searchPathsForComponent(name, version_required, search_paths):
    for path in search_paths:
        component_path = os.path.join(path, name)
        logger.debug("check path %s for %s" % (component_path, name))
        local_component = component.Component(
            component_path,
            installed_previously=True,
            installed_linked=fsutils.isLink(component_path),
            latest_suitable_version=None)
        if local_component:
            return local_component
    return None
コード例 #7
0
ファイル: access.py プロジェクト: danros/yotta
def searchPathsFor(name, version_required, search_paths, type='module'):
    for path in search_paths:
        check_path = os.path.join(path, name)
        logger.debug("check path %s for %s" % (check_path, name))
        instance = _clsForType(type)(
                     check_path,
                   installed_linked = fsutils.isLink(check_path),
            latest_suitable_version = None
        )
        if instance:
            return instance
    return None
コード例 #8
0
ファイル: access.py プロジェクト: parisk/yotta
def searchPathsForComponent(name, version_required, search_paths):
    for path in search_paths:
        component_path = os.path.join(path, name)
        logger.debug("check path %s for %s" % (component_path, name))
        local_component = component.Component(
                     component_path,
               installed_previously = True,
                   installed_linked = fsutils.isLink(component_path),
            latest_suitable_version = None
        )
        if local_component:
            return local_component
    return None
コード例 #9
0
ファイル: access.py プロジェクト: BlackstoneEngineering/yotta
def searchPathsFor(name, spec, search_paths, type='module'):
    for path in search_paths:
        check_path = os.path.join(path, name)
        logger.debug("check path %s for %s" % (check_path, name))
        instance = _clsForType(type)(
                     check_path,
                   installed_linked = fsutils.isLink(check_path),
            latest_suitable_version = None
        )
        if instance:
            logger.debug("got %s v=%s spec %s matches? %s", instance, instance.getVersion(), spec, spec.match(instance.getVersion()))
            if spec.match(instance.getVersion()):
                return instance
        else:
            logger.debug("got %s", instance)
    return None
コード例 #10
0
def searchPathsFor(name, spec, search_paths, type='module'):
    for path in search_paths:
        check_path = os.path.join(path, name)
        logger.debug("check path %s for %s" % (check_path, name))
        instance = _clsForType(type)(
            check_path,
            installed_linked=fsutils.isLink(check_path),
            latest_suitable_version=None)
        if instance:
            logger.debug("got %s v=%s spec %s matches? %s", instance,
                         instance.getVersion(), spec,
                         spec.match(instance.getVersion()))
            if spec.match(instance.getVersion()):
                return instance
        else:
            logger.debug("got %s", instance)
    return None
コード例 #11
0
ファイル: component.py プロジェクト: danros/yotta
 def getDependencies(self,
     available_components = None,
              search_dirs = None,
                   target = None,
           available_only = False,
                     test = False,
                 warnings = True
     ):
     ''' Returns {component_name:component}
     '''
     available_components = self.ensureOrderedDict(available_components)        
     if search_dirs is None:
         search_dirs = []
     r = OrderedDict()
     modules_path = self.modulesPath()
     for dspec in self.getDependencySpecs(target=target):
         if dspec.is_test_dependency and not test:
             continue
         name = dspec.name
         ver_req = dspec.version_req
         if name in available_components:
             logger.debug('found dependency %s of %s in available components' % (name, self.getName()))
             r[name] = available_components[name]
         elif not available_only:
             for d in search_dirs + [modules_path]:
                 logger.debug('looking for dependency %s of %s in %s' % (name, self.getName(), d))
                 component_path = path.join(d, name)
                 c = Component(
                     component_path,
                     installed_linked=fsutils.isLink(component_path)
                 )
                 if c:
                     logger.debug('found dependency %s of %s in %s' % (name, self.getName(), d))
                     break
             # if we didn't find a valid component in the search path, we
             # use the component initialised with the last place checked
             # (the modules path)
             if warnings and not c:
                 logger.warning('failed to find dependency %s of %s' % (name, self.getName()))
             r[name] = c
     return r
コード例 #12
0
 def getDependencies(self,
                     available_components=None,
                     search_dirs=None,
                     target=None,
                     available_only=False):
     ''' Returns {component_name:component}
     '''
     available_components = self.ensureOrderedDict(available_components)
     if search_dirs is None:
         search_dirs = []
     r = OrderedDict()
     modules_path = self.modulesPath()
     for name, ver_req in self.getDependencySpecs(target=target):
         if name in available_components:
             logger.debug(
                 'found dependency %s of %s in available components' %
                 (name, self.getName()))
             r[name] = available_components[name]
         elif not available_only:
             for d in search_dirs + [modules_path]:
                 logger.debug('looking for dependency %s of %s in %s' %
                              (name, self.getName(), d))
                 component_path = path.join(d, name)
                 c = Component(
                     component_path,
                     installed_previously=True,
                     installed_linked=fsutils.isLink(component_path))
                 if c:
                     logger.debug('found dependency %s of %s in %s' %
                                  (name, self.getName(), d))
                     break
             # if we didn't find a valid component in the search path, we
             # use the component initialised with the last place checked
             # (the modules path)
             if not c:
                 logger.warning('failed to find dependency %s of %s' %
                                (name, self.getName()))
             r[name] = c
     return r
コード例 #13
0
def satisfyTarget(name,
                  version_required,
                  working_directory,
                  update_installed=None):
    ''' returns a Target for the specified version (either to an already
        installed copy (from disk), or to a newly downloaded one), or None if
        the version could not be satisfied.

        update_installed = {None, 'Check', 'Update'}
            None:   prevent any attempt to look for new versions if the
                    target already exists
            Check:  check for new versions, and pass new version information to
                    the target object
            Update: replace any existing version with the newest available, if
                    the newest available has a higher version
    '''

    spec = None
    v = None

    target_path = os.path.join(working_directory, name)
    local_target = target.Target(target_path,
                                 installed_linked=fsutils.isLink(target_path),
                                 latest_suitable_version=v)

    if local_target and (local_target.installedLinked()
                         or update_installed != 'Update'
                         or not local_target.outdated()):
        # if a target exists (has a valid description file), and either is
        # not outdated, or we are not updating
        return local_target

    # if we need to check for latest versions, get the latest available version
    # before checking for a local target so that we can create the local
    # target with a handle to its latest available version
    if update_installed is None:
        logger.debug('attempt to check latest version of %s @%s...' %
                     (name, version_required))
        v = latestSuitableVersion(name, version_required, registry='targets')
    elif local_target and local_target.outdated():
        logger.info('%soutdated: %s@%s -> %s' %
                    (('update ' if update_installed == 'Update' else ''), name,
                     local_target.getVersion(), v))
        # must rm the old target before continuing
        fsutils.rmRf(target_path)

    if not v and update_installed is not None:
        v = latestSuitableVersion(name, version_required, registry='targets')

    if not v:
        raise access_common.TargetUnavailable(
            '"%s" is not a supported specification for a target (the target is %s)'
            % (version_required, name))
    directory = os.path.join(working_directory, name)
    v.unpackInto(directory)
    r = target.Target(directory)
    if not r:
        raise Exception(
            '"%s":"%s" is not a valid target (its description file is invalid)'
            % (name, version_required))
    return r