Exemple #1
0
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
Exemple #2
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)
Exemple #3
0
def directoryTarget(path):
    # Target, , represents an installed target, internal
    from yotta.lib import target
    # Pack, , base class for targets and components, internal
    from yotta.lib import pack
    try:
        t = target.Target(path)
    except pack.InvalidDescription as e:
        logging.error(e)
        return None
    return t
Exemple #4
0
def currentDirectoryTarget():
    # Target, , represents an installed target, internal
    from yotta.lib import target
    # Pack, , base class for targets and components, internal
    from yotta.lib import pack
    try:
        t = target.Target(os.getcwd())
    except pack.InvalidDescription as e:
        logging.error(e)
        return None
    if not t:
        logging.error(str(t.error))
        logging.error('The current directory does not contain a valid target.')
        return None
    return t
Exemple #5
0
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()))