示例#1
0
    def testLink(self):
        linked_in_module = util.writeTestFiles(util.Test_Trivial_Lib, True)

        stdout, stderr, statuscode = cli.run(
            ['-t', Test_Target, '--plain', 'link'], cwd=linked_in_module)
        self.assertEqual(statuscode, 0)
        self.assertTrue(
            os.path.exists(
                os.path.join(globalInstallDirectory(), 'test-trivial-lib')))

        test_module = util.writeTestFiles(util.Test_Testing_Trivial_Lib_Dep,
                                          True)
        stdout, stderr, statuscode = cli.run(
            ['-t', Test_Target, '--plain', 'list'], cwd=test_module)
        self.assertIn('missing', stdout + stderr)

        stdout, stderr, statuscode = cli.run(
            ['-t', Test_Target, '--plain', 'link', 'test-trivial-lib'],
            cwd=test_module)
        self.assertEqual(statuscode, 0)
        self.assertNotIn('broken', stdout + stderr)

        stdout, stderr, statuscode = cli.run(
            ['-t', Test_Target, '--plain', 'list'], cwd=test_module)
        self.assertNotIn('missing', stdout + stderr)

        util.rmRf(test_module)
        util.rmRf(linked_in_module)
示例#2
0
文件: install.py 项目: bearsh/yotta
def installComponent(args):
    path = folders.globalInstallDirectory(
    ) if args.act_globally else os.getcwd()
    logging.debug('install component %s to %s' % (args.component, path))

    # !!! FIXME: should support other URL specs, spec matching should be in
    # access module
    github_ref_match = GitHub_Ref_RE.match(args.component)
    try:
        if github_ref_match:
            component_name = github_ref_match.group(1)
            access.satisfyVersion(component_name,
                                  args.component,
                                  available=dict(),
                                  search_paths=[path],
                                  working_directory=path)
        else:
            component_name = args.component
            access.satisfyVersion(component_name,
                                  '*',
                                  available=dict(),
                                  search_paths=[path],
                                  working_directory=path)
    except access_common.Unavailable as e:
        logging.error('%s', e)
        return 1
    os.chdir(component_name)
    return installDeps(args, component.Component(os.getcwd()))
示例#3
0
文件: install.py 项目: bearsh/yotta
def installComponent(args):
    path = folders.globalInstallDirectory() if args.act_globally else os.getcwd()
    logging.debug('install component %s to %s' % (args.component, path))

    # !!! FIXME: should support other URL specs, spec matching should be in
    # access module
    github_ref_match = GitHub_Ref_RE.match(args.component)
    try:
        if github_ref_match:
            component_name = github_ref_match.group(1)
            access.satisfyVersion(
                      component_name,
                      args.component,
                           available = dict(),
                        search_paths = [path],
                   working_directory = path
            )
        else:
            component_name = args.component
            access.satisfyVersion(
                      component_name,
                                 '*',
                           available = dict(),
                        search_paths = [path],
                   working_directory = path
            )
    except access_common.Unavailable as e:
        logging.error('%s', e)
        return 1
    os.chdir(component_name)
    return installDeps(args, component.Component(os.getcwd()))
示例#4
0
文件: remove.py 项目: yuben75/yotta
def removeGlobally(module_or_target):
    # folders, , get places to install things, internal
    from yotta.lib import folders
    if module_or_target == 'module':
        global_dir = folders.globalInstallDirectory()
        p = validate.currentDirectoryModule()
    else:
        global_dir = folders.globalTargetInstallDirectory()
        p = validate.currentDirectoryTarget()
    if p is None:
        return 1
    path = os.path.join(global_dir, p.getName())
    return rmLinkOrDirectory(path, ('%s is not linked globally' % p.getName()))
示例#5
0
文件: link.py 项目: headlessme/yotta
    def testLink(self):
        linked_in_module = util.writeTestFiles(util.Test_Trivial_Lib, True)

        stdout, stderr, statuscode = cli.run(['-t', Test_Target, '--plain', 'link'], cwd=linked_in_module)
        self.assertEqual(statuscode, 0)
        self.assertTrue(os.path.exists(os.path.join(globalInstallDirectory(), 'test-trivial-lib')))

        test_module = util.writeTestFiles(util.Test_Testing_Trivial_Lib_Dep, True)
        stdout, stderr, statuscode = cli.run(['-t', Test_Target, '--plain', 'list'], cwd=test_module)
        self.assertIn('missing', stdout+stderr)

        stdout, stderr, statuscode = cli.run(['-t', Test_Target, '--plain', 'link', 'test-trivial-lib'], cwd=test_module)
        self.assertEqual(statuscode, 0)
        self.assertNotIn('broken', stdout+stderr)

        stdout, stderr, statuscode = cli.run(['-t', Test_Target, '--plain', 'list'], cwd=test_module)
        self.assertNotIn('missing', stdout+stderr)

        util.rmRf(test_module)
        util.rmRf(linked_in_module)
示例#6
0
文件: install.py 项目: ARMmbed/yotta
def installComponent(args):
    path = folders.globalInstallDirectory() if args.act_globally else os.getcwd()
    logging.debug('install component %s to %s' % (args.component, path))

    from yotta.lib import sourceparse
    # check if we have both a name and specification
    component_name, component_spec = sourceparse.parseModuleNameAndSpec(args.component)

    try:
        access.satisfyVersion(
                  component_name,
                  component_spec,
                       available = dict(),
                    search_paths = [path],
               working_directory = path
        )
    except access_common.AccessException as e:
        logging.error('%s', e)
        return 1
    os.chdir(component_name)
    return installDeps(args, component.Component(os.getcwd()))
示例#7
0
文件: install.py 项目: yuben75/yotta
def installComponent(args):
    path = folders.globalInstallDirectory(
    ) if args.act_globally else os.getcwd()
    logging.debug('install component %s to %s' % (args.component, path))

    from yotta.lib import sourceparse
    # check if we have both a name and specification
    component_name, component_spec = sourceparse.parseModuleNameAndSpec(
        args.component)

    try:
        access.satisfyVersion(component_name,
                              component_spec,
                              available=dict(),
                              search_paths=[path],
                              working_directory=path)
    except access_common.AccessException as e:
        logging.error('%s', e)
        return 1
    os.chdir(component_name)
    return installDeps(args, component.Component(os.getcwd()))
示例#8
0
文件: link.py 项目: Timmmm/yotta
def execCommand(args, following_args):
    # standard library modules, , ,
    import logging
    import os

    # colorama, BSD 3-Clause license, color terminal output, pip install colorama
    import colorama

    # validate, , validate things, internal
    from yotta.lib import validate
    # folders, , get places to install things, internal
    from yotta.lib import folders
    # fsutils, , misc filesystem utils, internal
    from yotta.lib import fsutils

    c = validate.currentDirectoryModule()
    if not c:
        return 1
    link_module_name = None
    if args.module_or_path:
        link_module_name = args.module_or_path
        err = validate.componentNameValidationError(args.module_or_path)
        if err:
            # check if the module name is really a path to a module
            if os.path.isdir(args.module_or_path):
                # make sure the first half of the link exists,
                src = os.path.abspath(args.module_or_path)
                # if it isn't a valid module, that's an error:
                dep = validate.directoryModule(src)
                if not dep:
                    logging.error("%s is not a valid module: %s", args.module_or_path, dep.getError())
                    return 1
                link_module_name = dep.getName()
                dst = os.path.join(folders.globalInstallDirectory(), link_module_name)
                errcode = tryLink(src, dst)
                if errcode:
                    return errcode
            else:
                logging.error("%s is neither a valid module name, nor a path to an existing module.", args.module_or_path)
                logging.error(err)
                return 1
        fsutils.mkDirP(os.path.join(os.getcwd(), 'yotta_modules'))
        src = os.path.join(folders.globalInstallDirectory(), link_module_name)
        dst = os.path.join(os.getcwd(), 'yotta_modules', link_module_name)
        # if the component is already installed, rm it
        fsutils.rmRf(dst)
    else:
        fsutils.mkDirP(folders.globalInstallDirectory())

        src = os.getcwd()
        dst = os.path.join(folders.globalInstallDirectory(), c.getName())

    if link_module_name:
        realsrc = fsutils.realpath(src)
        if src == realsrc:
            logging.warning(
              ('%s -> %s -> ' % (dst, src)) + colorama.Fore.RED + 'BROKEN' + colorama.Fore.RESET #pylint: disable=no-member
            )
        else:
            logging.info('%s -> %s -> %s' % (dst, src, realsrc))
        # check if the thing we linked is actually a dependency, if it isn't
        # warn about that. To do this we may have to get the current target
        # description. This might fail, in which case we warn that we couldn't
        # complete the check:
        target = c.getTarget(args.target, args.config)
        if target:
            if not c.hasDependencyRecursively(link_module_name, target=target, test_dependencies=True):
                logging.warning(
                    '"%s" is not installed as a dependency, so will not '+
                    ' be built. Perhaps you meant to "yotta install %s" '+
                    'first?',
                    link_module_name,
                    link_module_name
                )
        else:
            logging.warning(
                'Could not check if linked module "%s" is installed as a '+
                'dependency, because target "%s" is not available. Run '
                '"yotta ls" to check.',
                link_module_name,
                args.target
            )
    else:
        logging.info('%s -> %s' % (dst, src))
    return tryLink(src, dst)
示例#9
0
def execCommand(args, following_args):
    # standard library modules, , ,
    import logging
    import os

    # colorama, BSD 3-Clause license, color terminal output, pip install colorama
    import colorama

    # fsutils, , misc filesystem utils, internal
    from yotta.lib import fsutils
    # validate, , validate things, internal
    from yotta.lib import validate
    # folders, , get places to install things, internal
    from yotta.lib import folders
    c = None
    t = None
    link_target_name = None
    if args.target_or_path:
        link_target_name = args.target_or_path
        c = validate.currentDirectoryModule()
        if not c:
            return 1
        err = validate.targetNameValidationError(args.target_or_path)
        if err:
            # check if the target name is really a path to an existing target
            if os.path.isdir(args.target_or_path):
                # make sure the first half of the link exists,
                src = os.path.abspath(args.target_or_path)
                # if it isn't a valid target, that's an error:
                tgt = validate.directoryTarget(src)
                if not tgt:
                    logging.error("%s is not a valid target: %s", args.target_or_path, tgt.getError())
                    return 1
                link_target_name = tgt.getName()
                dst = os.path.join(folders.globalInstallDirectory(), link_target_name)
                errcode = tryLink(src, dst)
                if errcode:
                    return errcode
            else:
                logging.error(err)
                return 1
        fsutils.mkDirP(os.path.join(os.getcwd(), 'yotta_targets'))
        src = os.path.join(folders.globalTargetInstallDirectory(), link_target_name)
        dst = os.path.join(os.getcwd(), 'yotta_targets', link_target_name)
        # if the target is already installed, rm it
        fsutils.rmRf(dst)
    else:
        t = validate.currentDirectoryTarget()
        if not t:
            return 1
        fsutils.mkDirP(folders.globalTargetInstallDirectory())
        src = os.getcwd()
        dst = os.path.join(folders.globalTargetInstallDirectory(), t.getName())

    broken_link = False
    if link_target_name:
        realsrc = fsutils.realpath(src)
        if src == realsrc:
            broken_link = True
            logging.warning(
              ('%s -> %s -> ' % (dst, src)) + colorama.Fore.RED + 'BROKEN' + colorama.Fore.RESET #pylint: disable=no-member
            )
        else:
            logging.info('%s -> %s -> %s' % (dst, src, realsrc))
        # check that the linked target is actually set as the target (or is
        # inherited from by something set as the target), if it isn't, warn the
        # user:
        if c and link_target_name != nameFromTargetSpec(args.target):
            target = c.getTarget(args.target, args.config)
            if target:
                if not target.inheritsFrom(link_target_name):
                    logging.warning(
                        'target "%s" is not used by the current target (%s), so '
                        'this link will have no effect. Perhaps you meant to '
                        'use "yotta target <targetname>" to set the build '
                        'target first.',
                        link_target_name,
                        nameFromTargetSpec(args.target)
                    )
            else:
                logging.warning(
                    'Could not check if linked target "%s" is used by the '+
                    'current target "%s": run "yotta target" to check.',
                    link_target_name,
                    nameFromTargetSpec(args.target)
                )

    else:
        logging.info('%s -> %s' % (dst, src))
    try:
        fsutils.symlink(src, dst)
    except Exception as e:
        if broken_link:
            logging.error('failed to create link (create the first half of the link first)')
        else:
            logging.error('failed to create link: %s', e)
示例#10
0
文件: link.py 项目: DaMouse404/yotta
def execCommand(args, following_args):
    # standard library modules, , ,
    import logging
    import os

    # colorama, BSD 3-Clause license, color terminal output, pip install colorama
    import colorama

    # validate, , validate things, internal
    from yotta.lib import validate
    # folders, , get places to install things, internal
    from yotta.lib import folders
    # fsutils, , misc filesystem utils, internal
    from yotta.lib import fsutils

    c = validate.currentDirectoryModule()
    if not c:
        return 1
    if args.component:
        err = validate.componentNameValidationError(args.component)
        if err:
            logging.error(err)
            return 1
        fsutils.mkDirP(os.path.join(os.getcwd(), 'yotta_modules'))
        src = os.path.join(folders.globalInstallDirectory(), args.component)
        dst = os.path.join(os.getcwd(), 'yotta_modules', args.component)
        # if the component is already installed, rm it
        fsutils.rmRf(dst)
    else:
        fsutils.mkDirP(folders.globalInstallDirectory())

        src = os.getcwd()
        dst = os.path.join(folders.globalInstallDirectory(), c.getName())

    broken_link = False
    if args.component:
        realsrc = fsutils.realpath(src)
        if src == realsrc:
            broken_link = True
            logging.warning(
              ('%s -> %s -> ' % (dst, src)) + colorama.Fore.RED + 'BROKEN' + colorama.Fore.RESET #pylint: disable=no-member
            )
        else:
            logging.info('%s -> %s -> %s' % (dst, src, realsrc))
        # check if the thing we linked is actually a dependency, if it isn't
        # warn about that. To do this we may have to get the current target
        # description. This might fail, in which case we warn that we couldn't
        # complete the check:
        target = c.getTarget(args.target, args.config)
        if target:
            if not c.hasDependencyRecursively(args.component, target=target, test_dependencies=True):
                logging.warning(
                    '"%s" is not installed as a dependency, so will not '+
                    ' be built. Perhaps you meant to "yotta install %s" '+
                    'first?',
                    args.component,
                    args.component
                )
        else:
            logging.warning(
                'Could not check if linked module "%s" is installed as a '+
                'dependency, because target "%s" is not available. Run '
                '"yotta ls" to check.',
                args.component,
                args.target
            )
    else:
        logging.info('%s -> %s' % (dst, src))

    try:
        fsutils.symlink(src, dst)
    except Exception as e:
        if broken_link:
            logging.error('failed to create link (create the first half of the link first)')
        else:
            logging.error('failed to create link: %s', e)
示例#11
0
def execCommand(args, following_args):
    # standard library modules, , ,
    import logging
    import os

    # colorama, BSD 3-Clause license, color terminal output, pip install colorama
    import colorama

    # validate, , validate things, internal
    from yotta.lib import validate
    # folders, , get places to install things, internal
    from yotta.lib import folders
    # fsutils, , misc filesystem utils, internal
    from yotta.lib import fsutils

    c = validate.currentDirectoryModule()
    if not c:
        return 1
    link_module_name = None
    if args.module_or_path:
        link_module_name = args.module_or_path
        err = validate.componentNameValidationError(args.module_or_path)
        if err:
            # check if the module name is really a path to a module
            if os.path.isdir(args.module_or_path):
                # make sure the first half of the link exists,
                src = os.path.abspath(args.module_or_path)
                # if it isn't a valid module, that's an error:
                dep = validate.directoryModule(src)
                if not dep:
                    logging.error("%s is not a valid module: %s",
                                  args.module_or_path, dep.getError())
                    return 1
                link_module_name = dep.getName()
                dst = os.path.join(folders.globalInstallDirectory(),
                                   link_module_name)
                errcode = tryLink(src, dst)
                if errcode:
                    return errcode
            else:
                logging.error(
                    "%s is neither a valid module name, nor a path to an existing module.",
                    args.module_or_path)
                logging.error(err)
                return 1
        fsutils.mkDirP(os.path.join(os.getcwd(), 'yotta_modules'))
        src = os.path.join(folders.globalInstallDirectory(), link_module_name)
        dst = os.path.join(os.getcwd(), 'yotta_modules', link_module_name)
        # if the component is already installed, rm it
        fsutils.rmRf(dst)
    else:
        fsutils.mkDirP(folders.globalInstallDirectory())

        src = os.getcwd()
        dst = os.path.join(folders.globalInstallDirectory(), c.getName())

    if link_module_name:
        realsrc = fsutils.realpath(src)
        if src == realsrc:
            logging.warning(('%s -> %s -> ' % (dst, src)) + colorama.Fore.RED +
                            'BROKEN' + colorama.Fore.RESET  #pylint: disable=no-member
                            )
        else:
            logging.info('%s -> %s -> %s' % (dst, src, realsrc))
        # check if the thing we linked is actually a dependency, if it isn't
        # warn about that. To do this we may have to get the current target
        # description. This might fail, in which case we warn that we couldn't
        # complete the check:
        target = c.getTarget(args.target, args.config)
        if target:
            if not c.hasDependencyRecursively(
                    link_module_name, target=target, test_dependencies=True):
                logging.warning(
                    '"%s" is not installed as a dependency, so will not ' +
                    ' be built. Perhaps you meant to "yotta install %s" ' +
                    'first?', link_module_name, link_module_name)
        else:
            logging.warning(
                'Could not check if linked module "%s" is installed as a ' +
                'dependency, because target "%s" is not available. Run '
                '"yotta ls" to check.', link_module_name, args.target)
    else:
        logging.info('%s -> %s' % (dst, src))
    return tryLink(src, dst)