예제 #1
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()))
예제 #2
0
파일: validate.py 프로젝트: bearsh/yotta
def currentDirectoryModuleOrTarget():
    # Component, , represents an installed component, internal
    from yotta.lib import component
    # Target, , represents an installed target, internal
    from yotta.lib import target
    # Pack, , base class for targets and components, internal
    from yotta.lib import pack
    wd = os.getcwd()
    errors = []
    p = None
    try:
        p = component.Component(wd)
    except pack.InvalidDescription as e:
        errors.append(e)
    if not p:
        try:
            p = target.Target(wd)
        except pack.InvalidDescription as e:
            errors.append(e)
    if not p:
        for e in errors:
            logging.debug(e)
        logging.error(
            'The current directory does not contain a valid module or target.')
        return None
    return p
예제 #3
0
def execCommand(args, following_args):
    sc = args.subsubcommand

    # if the current directory contains a component or a target, get it
    cwd = os.getcwd()
    c = component.Component(cwd)
    t = target.Target(cwd)

    if args.module:
        p = None
    else:
        p = c
        if t and not c:
            p = t

    if not p and not args.module:
        logging.error('a module must be specified (the current directory does not contain a valid module)')
        return 1

    if sc in ('list', 'ls', ''):
        return listOwners(args, p)
    elif sc in ('remove', 'rm'):
        return removeOwner(args, p)
    elif sc in ('add',):
        return addOwner(args, p)
예제 #4
0
 def test_relative_ignores(self):
     c = component.Component(self.test_dir)
     self.assertTrue(c.ignores('a/b/c/d/e/f/test.txt'))
     self.assertTrue(c.ignores('a/b/test.txt'))
     self.assertTrue(c.ignores('source/a/b/c/d/e/f/test.txt'))
     self.assertTrue(c.ignores('source/a/b/test.txt'))
     self.assertTrue(c.ignores('test/anothertest/ignoredbyfname.c'))
     self.assertTrue(c.ignores('test/someothertest/alsoignored.c'))
예제 #5
0
 def test_glob_ignores(self):
     c = component.Component(self.test_dir)
     self.assertTrue(c.ignores('a/b/c/test.txt'))
     self.assertTrue(c.ignores('a/b/test.txt'))
     self.assertTrue(c.ignores('a/b/test.c'))
     self.assertTrue(c.ignores('source/a/b/c/test.txt'))
     self.assertTrue(c.ignores('source/a/b/test.txt'))
     self.assertTrue(c.ignores('source/a/b/test.c'))
예제 #6
0
def displayCurrentTarget(args):
    if not args.plain:
        DIM = colorama.Style.DIM  #pylint: disable=no-member
        BRIGHT = colorama.Style.BRIGHT  #pylint: disable=no-member
        GREEN = colorama.Fore.GREEN  #pylint: disable=no-member
        RED = colorama.Fore.RED  #pylint: disable=no-member
        RESET = colorama.Style.RESET_ALL  #pylint: disable=no-member
    else:
        DIM = BRIGHT = GREEN = RED = RESET = u''

    line = u''

    c = component.Component(os.getcwd())
    if c.isApplication():
        app_path = c.path
    else:
        app_path = None

    derived_target, errors = target.getDerivedTarget(
        args.target,
        c.targetsPath(),
        application_dir=app_path,
        install_missing=False,
        shrinkwrap=c.getShrinkwrap())
    for error in errors:
        logging.error(error)

    if derived_target is None:
        line = BRIGHT + RED + args.target + u' missing' + RESET
    else:
        for t in derived_target.hierarchy:
            if len(line):
                line += '\n'
            if t:
                line += t.getName() + DIM + u' ' + str(t.getVersion()) + RESET
                if t.installedLinked():
                    line += GREEN + BRIGHT + u' -> ' + RESET + GREEN + fsutils.realpath(
                        t.path)
            else:
                line += BRIGHT + RED + t.getName() + DIM + u' ' + str(
                    t.getVersion()) + BRIGHT + u' missing'
            line += RESET
        base_spec = t.baseTargetSpec()
        if base_spec:
            # if the last target in the hierarchy has a base spec, then the
            # hierarchy is incomplete:
            line += '\n' + BRIGHT + RED + base_spec.name + u' ' + base_spec.versionReq(
            ) + u' missing'

    if u'unicode' in str(type(line)):
        # python 2.7
        print(line.encode('utf-8'))
    else:
        print(line)
    return len(errors)
예제 #7
0
def directoryModule(path):
    # Component, , represents an installed component, internal
    from yotta.lib import component
    # Pack, , base class for targets and components, internal
    from yotta.lib import pack
    try:
        c = component.Component(path)
    except pack.InvalidDescription as e:
        logging.error(e)
        return None
    return c
예제 #8
0
def execCommand(args, following_args):
    c = component.Component(os.getcwd())
    if c:
        logging.info('The current directory already a contains a module: existing description will be modified')
    elif os.path.isfile(c.getDescriptionFile()):
        logging.error('A module description exists but could not be loaded:')
        logging.error(c.error)
        return 1

    if args.interactive:
        return initInteractive(args, c)
    else:
        return initNonInteractive(args, c)
예제 #9
0
파일: version.py 프로젝트: yuben75/yotta
def execCommand(args, following_args):
    wd = os.getcwd()
    c = component.Component(wd)
    # skip testing for target if we already found a component
    t = None if c else target.Target(wd)
    if not (c or t):
        logging.debug(str(c.getError()))
        if t:
            logging.debug(str(t.getError()))
        logging.error(
            'The current directory does not contain a valid module or target.')
        return 1
    else:
        # only needed separate objects in order to display errors
        p = (c or t)

    if args.action:
        try:
            if not p.vcsIsClean():
                logging.error('The working directory is not clean')
                return 1

            v = p.getVersion()
            pre_script_env = {'YOTTA_OLD_VERSION': str(v)}
            if args.action in ('major', 'minor', 'patch'):
                v.bump(args.action)
            else:
                v = args.action

            pre_script_env['YOTTA_NEW_VERSION'] = str(v)
            errcode = p.runScript('preVersion', pre_script_env)
            if errcode:
                return errcode

            logging.info('@%s' % v)
            p.setVersion(v)

            p.writeDescription()

            errcode = p.runScript('postVersion')
            if errcode:
                return errcode

            p.commitVCS(tag='v' + str(v))
        except vcs.VCSError as e:
            logging.error(e)
    else:
        logging.info(str(p.getVersion()))
예제 #10
0
파일: validate.py 프로젝트: bearsh/yotta
def currentDirectoryModule():
    # Component, , represents an installed component, internal
    from yotta.lib import component
    # Pack, , base class for targets and components, internal
    from yotta.lib import pack
    try:
        c = component.Component(os.getcwd())
    except pack.InvalidDescription as e:
        logging.error(e)
        return None

    if not c:
        logging.error(str(c.error))
        logging.error('The current directory does not contain a valid module.')
        return None
    return c
예제 #11
0
    def test_default_ignores(self):
        default_test_dir = util.writeTestFiles(Default_Test_Files)
        c = component.Component(default_test_dir)
        self.assertTrue(c.ignores('.something.c.swp'))
        self.assertTrue(c.ignores('.something.c~'))
        self.assertTrue(c.ignores('path/to/.something.c.swm'))
        self.assertTrue(c.ignores('path/to/.something.c~'))
        self.assertTrue(c.ignores('.DS_Store'))
        self.assertTrue(c.ignores('.git'))
        self.assertTrue(c.ignores('.hg'))
        self.assertTrue(c.ignores('.svn'))
        self.assertTrue(c.ignores('yotta_modules'))
        self.assertTrue(c.ignores('yotta_targets'))
        self.assertTrue(c.ignores('build'))
        self.assertTrue(c.ignores('.yotta.json'))

        util.rmRf(default_test_dir)
예제 #12
0
def execCommand(args, following_args):
    if args.set_target is None:
        return displayCurrentTarget(args)
    else:
        if not Target_RE.match(args.set_target):
            logging.error('Invalid target: "%s"' %
                          args.set_target)  #, targets must be one of:
            #
            #    a valid name (lowercase letters, numbers, and hyphen)
            #    a github ref (owner/project)
            #    a valid url
            #
            #Note that to use a local directory as a target you can use
            #
            #    # in the directory containing the target package:
            #    yotta link target
            #
            #    # then in the directory of the application to use the target:
            #    yotta link target {targetname}
            #    yotta target {targetname}
            #
            #''')
            return 1
        else:
            if args.set_target.find(',') == -1:
                t = args.set_target + ',*'
            else:
                t = args.set_target
            settings.setProperty('build', 'target', t, not args.save_global)
            settings.setProperty('build', 'targetSetExplicitly', True,
                                 not args.save_global)
            if not args.no_install:
                # if we have a module in the current directory, try to make sure
                # this target is installed
                c = component.Component(os.getcwd())
                if c:
                    target, errors = c.satisfyTarget(t)
                    for err in errors:
                        logging.error(err)
                    if len(errors):
                        logging.error(
                            'NOTE: use "yotta link-target" to test a locally modified target prior to publishing.'
                        )
                        return 1
            return 0
예제 #13
0
파일: install.py 프로젝트: yuben75/yotta
def execCommand(args, following_args):
    if not hasattr(args, 'install_test_deps'):
        vars(args)['install_test_deps'] = 'none'
    if getattr(args, 'save', None):
        logging.warning(
            'the --save option is now the default and is ignored. It will be removed soon.'
        )
    if getattr(args, 'save_target', None):
        logging.warning(
            'the --save-target is now ignored. It will be removed soon.')
    cwd = os.getcwd()
    c = component.Component(cwd)
    if args.component is None:
        return installDeps(args, c)
    elif c or c.exists():
        return installComponentAsDependency(args, c)
    else:
        return installComponent(args)
예제 #14
0
    def test_creation(self):
        # test things about components that don't (and shouldn't) require
        # hitting the network

        with open(os.path.join(self.test_dir, 'module.json'), 'w') as f:
            f.write(test_json)

        c = component.Component(self.test_dir)
        self.assertTrue(c)

        self.assertEqual(c.getName(), 'something')
        self.assertEqual(str(c.getVersion()), '0.0.7')

        deps = c.getDependencies()
        self.assertEqual(list(deps.keys()), deps_in_order)

        test_deps = c.getDependencies(test=True)
        self.assertEqual(list(test_deps.keys()), test_deps_in_order)
예제 #15
0
    def test_component_init(self):
        # test things about components that don't (and shouldn't) require
        # hitting the network
        try:
            shutil.rmtree(testdir)
        except OSError:
            pass

        mkDirP(testdir)
        with open(os.path.join(testdir, 'module.json'), 'w') as f:
            f.write(self.test_json)

        c = component.Component(testdir)
        self.assertTrue(c)

        self.assertEqual(c.getName(), 'yottos')
        self.assertEqual(str(c.getVersion()), '0.0.7')

        deps = c.getDependencies()
        self.assertEqual(list(deps.keys()), self.deps_in_order)
예제 #16
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()))
예제 #17
0
def execCommand(args, following_args):
    if args.set_target is None:
        return displayCurrentTarget(args)
    else:
        from yotta.lib import sourceparse
        from yotta.lib import validate

        name, spec = sourceparse.parseTargetNameAndSpec(args.set_target)
        if not re.match(validate.Target_Name_Regex, name):
            logging.error(
                'Invalid target name: "%s" should use only a-z 0-9 - and +, and start with a letter.'
                % name)
            return 1
        if not sourceparse.isValidSpec(spec):
            logging.error(
                'Could not parse target version specification: "%s"' % spec)
            return 1

        # separating the target name and spec is still done with a comma
        # internally (for now at least), although @ is the recommended way to
        # set it:
        t = '%s,%s' % (name, spec)

        settings.setProperty('build', 'target', t, not args.save_global)
        settings.setProperty('build', 'targetSetExplicitly', True,
                             not args.save_global)
        if not args.no_install:
            # if we have a module in the current directory, try to make sure
            # this target is installed
            c = component.Component(os.getcwd())
            if c:
                target, errors = c.satisfyTarget(t)
                for err in errors:
                    logging.error(err)
                if len(errors):
                    logging.error(
                        'NOTE: use "yotta link-target" to test a locally modified target prior to publishing.'
                    )
                    return 1
        return 0
예제 #18
0
 def test_comments(self):
     c = component.Component(self.test_dir)
     self.assertFalse(c.ignores('comment'))
예제 #19
0
 def test_absolute_ignores(self):
     c = component.Component(self.test_dir)
     self.assertTrue(c.ignores('moo'))
     self.assertTrue(c.ignores('test/foo/ignored.c'))