コード例 #1
0
ファイル: clone.py プロジェクト: pombreda/conary-1
def _convertLabelOrBranch(lblStr, template):
    try:
        if not lblStr:
            return None
        if lblStr[0] == '/':
            v = versions.VersionFromString(lblStr)
            if isinstance(v, versions.Branch):
                return v
            # Some day we could lift this restriction if its useful.
            raise errors.ParseError('Cannot specify version to promote'
                                    ' - must specify branch or label')
        if not template:
            return versions.Label(lblStr)

        hostName = template.getHost()
        nameSpace = template.getNamespace()
        tag = template.branch

        if lblStr[0] == ':':
            lblStr = '%s@%s%s' % (hostName, nameSpace, lblStr)
        elif lblStr[0] == '@':
            lblStr = '%s%s' % (hostName, lblStr)
        elif lblStr[-1] == '@':
            lblStr = '%s%s:%s' % (lblStr, nameSpace, tag)
        return versions.Label(lblStr)
    except Exception, msg:
        raise errors.ParseError('Error parsing %r: %s' % (lblStr, msg))
コード例 #2
0
ファイル: trovetup.py プロジェクト: pombreda/conary-1
    def fromString(cls, ttstr, withFrozenFlavor=False):
        try:
            ttstr = _cast(ttstr)
        except UnicodeEncodeError:
            raise errors.ParseError("Trove tuple must be ASCII safe")

        equals = ttstr.count('=')
        left = ttstr.count('[')
        right = ttstr.count(']')
        if equals != 1 or left not in (0, 1) or right != left:
            raise errors.ParseError("Not a valid trove tuple")

        equals = ttstr.find('=')
        left = ttstr.find('[')
        right = ttstr.find(']')

        name = ttstr[:equals]
        if left < 0:
            # No flavor.
            assert right < 0
            left = right = len(ttstr)
        elif right != len(ttstr) - 1:
            raise errors.ParseError("Not a valid trove tuple")
        version = ttstr[equals + 1:left]
        flavor = ttstr[left + 1:right]
        if not version:
            raise errors.ParseError("Not a valid trove tuple")
        return cls(name, version, flavor)
コード例 #3
0
ファイル: clone.py プロジェクト: pombreda/conary-1
def CloneTrove(cfg,
               targetBranch,
               troveSpecList,
               updateBuildInfo=True,
               info=False,
               cloneSources=False,
               message=None,
               test=False,
               fullRecurse=False,
               ignoreConflicts=False,
               exactFlavors=False):
    client = ConaryClient(cfg)
    repos = client.getRepos()

    targetBranch = versions.VersionFromString(targetBranch)
    if not isinstance(targetBranch, versions.Branch):
        raise errors.ParseError(
            'Cannot specify full version "%s" to clone to - must specify target branch'
            % targetBranch)

    troveSpecs = [cmdline.parseTroveSpec(x) for x in troveSpecList]

    componentSpecs = [
        x[0] for x in troveSpecs
        if ':' in x[0] and x[0].split(':')[1] != 'source'
    ]
    if componentSpecs:
        raise errors.ParseError('Cannot clone components: %s' %
                                ', '.join(componentSpecs))

    trovesToClone = repos.findTroves(cfg.installLabelPath,
                                     troveSpecs,
                                     cfg.flavor,
                                     exactFlavors=exactFlavors)
    trovesToClone = list(set(itertools.chain(*trovesToClone.itervalues())))

    if not client.cfg.quiet:
        callback = client_callbacks.CloneCallback(client.cfg, message)
    else:
        callback = callbacks.CloneCallback()

    okay, cs = client.createCloneChangeSet(targetBranch,
                                           trovesToClone,
                                           updateBuildInfo=updateBuildInfo,
                                           infoOnly=info,
                                           callback=callback,
                                           fullRecurse=fullRecurse,
                                           cloneSources=cloneSources)
    if not okay:
        return
    return _finishClone(client,
                        cfg,
                        cs,
                        callback,
                        info=info,
                        test=test,
                        ignoreConflicts=ignoreConflicts)
コード例 #4
0
def createSearchPathFromStrings(searchPath):
    """
        Creates a list of items that can be passed into createSearchSource.

        Valid items in the searchPath include:
            1. troveSpec (foo=:devel) or list of trovespecs
            2. string for label (conary.rpath.com@rpl:devel)
            3. label objects or list of label objects.
    """
    from conary.conaryclient import cmdline
    from conary import conarycfg
    labelList = []
    finalPath = []
    if not isinstance(searchPath, (list, tuple)):
        searchPath = [searchPath]
    for item in searchPath:
        if isinstance(item, conarycfg.CfgLabelList):
            item = tuple(item)
        elif isinstance(item, versions.Label):
            labelList.append(item)
            continue
        elif isinstance(item, (list, tuple)):
            # recurse
            item = list(itertools.chain(*createSearchPathFromStrings(item)))
        elif isinstance(item, str):
            if '=' in item:
                # only troveSpecs have = in them
                item = (cmdline.parseTroveSpec(item), )
            elif '@' in item:
                try:
                    item = versions.Label(item)
                except baseerrors.ParseError, err:
                    raise baseerrors.ParseError(
                        'Error parsing label "%s": %s' % (item, err))
                labelList.append(item)
                continue
            else:
                item = (cmdline.parseTroveSpec(item), )
        else:
            raise baseerrors.ParseError('Unknown searchPath item "%s"' % item)
        # labels don't get here, so we know that this is not part of a
        # labelPath
        if labelList:
            finalPath.append(tuple(labelList))
            labelList = []
        finalPath.append(item)
コード例 #5
0
def createSearchSourceStack(searchSource,
                            searchPath,
                            flavor,
                            db=None,
                            resolveLeavesFirst=True,
                            troveSource=None,
                            useAffinity=True,
                            fallBackToRepos=True):
    """
        Creates a searchSourceStack based on a searchPath.

        Valid parameters include:
            - a label object
            - a trove tuple
            - a trove object
            - a list of any of the above.
    """
    if troveSource is None:
        troveSource = searchSource.getTroveSource()
    if resolveLeavesFirst:
        searchMethod = resolvemethod.RESOLVE_LEAVES_FIRST
    else:
        searchMethod = resolvemethod.RESOLVE_ALL
    searchStack = SearchSourceStack(resolveSearchMethod=searchMethod)

    hasNetworkSearchSource = False
    for item in searchPath:
        if not isinstance(item, (list, tuple)):
            item = [item]
        if isinstance(item[0], versions.Label):
            searchStack.addSource(
                NetworkSearchSource(troveSource,
                                    item,
                                    flavor,
                                    db,
                                    resolveSearchMethod=searchMethod))
            hasNetworkSearchSource = True
        elif isinstance(item[0], trove.Trove):
            s = TroveSearchSource(searchSource.getTroveSource(), item, flavor)
            searchStack.addSource(s)
        elif isinstance(item[0], (list, tuple)):
            if not isinstance(item[0][1], versions.Version):
                item = searchSource.findTroves(item, useAffinity=useAffinity)
                item = list(itertools.chain(*item.itervalues()))
            s = TroveSearchSource(searchSource.getTroveSource(), item, flavor)
            searchStack.addSource(s)
        else:
            raise baseerrors.ParseError('unknown search path item %s' %
                                        (item, ))
    if fallBackToRepos and not hasNetworkSearchSource:
        searchStack.addSource(
            NetworkSearchSource(troveSource, [],
                                flavor,
                                db,
                                resolveSearchMethod=searchMethod))
    return searchStack
コード例 #6
0
ファイル: command.py プロジェクト: pombreda/conary-1
    def requireParameters(self,
                          args,
                          expected=None,
                          allowExtra=False,
                          appendExtra=False,
                          maxExtra=None):
        args = args[1:]  # cut off argv[0]
        command = repr(args[0])
        if isinstance(expected, str):
            expected = [expected]
        if expected is None:
            expected = ['command']
        else:
            expected = ['command'] + expected
        if expected:
            missing = expected[len(args):]
            if missing:
                raise errors.ParseError(
                    '%s missing %s command'
                    ' parameter(s): %s' %
                    (command, len(missing), ', '.join(missing)))
        extra = len(args) - len(expected)
        if not allowExtra and not appendExtra:
            maxExtra = 0
        if maxExtra is not None and extra > maxExtra:
            if maxExtra:
                numParams = '%s-%s' % (len(expected) - 1,
                                       len(expected) + maxExtra - 1)
            else:
                numParams = '%s' % (len(expected) - 1)
            raise errors.ParseError('%s takes %s arguments, received %s' %
                                    (command, numParams, len(args) - 1))

        if appendExtra:
            # final parameter is list
            return args[:len(expected) - 1] + [args[len(expected) - 1:]]
        elif allowExtra:
            return args[:len(expected)] + [args[len(expected):]]
        else:
            return args
コード例 #7
0
ファイル: mainhandler.py プロジェクト: pombreda/conary-1
    def getCommand(self, argv, cfg):
        # note, cfg is not used by this implementation, but it
        # may be used by classes that derive from this one.
        if len(argv) == 1:
            # no command specified
            return None

        commandName = argv[1]
        if commandName not in self._supportedCommands:
            rc = self.usage()
            raise errors.ParseError("%s: unknown command: '%s'" %
                                    (self.name, commandName))
        return self._supportedCommands[commandName]
コード例 #8
0
ファイル: trovetup.py プロジェクト: tensor5/conary
 def fromString(cls, val, absolute=None):
     try:
         val = _cast(val)
     except UnicodeEncodeError:
         raise errors.ParseError("Job tuple must be ASCII safe")
     name, val = val.split('=')
     if '--' in val:
         old, new = val.split('--')
     else:
         old, new = '', val
     if old:
         old = TroveTuple.fromString('%s=%s' % (name, old))[1:3]
     else:
         old = (None, None)
     if new:
         new = TroveTuple.fromString('%s=%s' % (name, new))[1:3]
     else:
         new = (None, None)
     return cls(name, old, new, absolute)
コード例 #9
0
ファイル: cml.py プロジェクト: pombreda/conary-1
 def parse(self, text):
     # ensure that this is a legal conary upstream version
     rev = versions.Revision(text + '-1')
     if rev.buildCount != None:
         raise errors.ParseError('%s: not a conary upstream version' % text)
     _TextOp.parse(self, text)
コード例 #10
0
def branch(repos,
           cfg,
           newLabel,
           troveSpecs,
           makeShadow=False,
           sourceOnly=False,
           binaryOnly=False,
           allowEmptyShadow=False,
           info=False,
           forceBinary=False,
           ignoreConflicts=False,
           targetFile=None):
    branchType = _getBranchType(binaryOnly, sourceOnly)

    client = conaryclient.ConaryClient(cfg)

    troveSpecs = [updatecmd.parseTroveSpec(x) for x in troveSpecs]

    componentSpecs = [
        x[0] for x in troveSpecs
        if (':' in x[0] and x[0].split(':')[1] != 'source')
    ]
    if componentSpecs:
        raise errors.ParseError(
            'Cannot branch or shadow individual components: %s' %
            ', '.join(componentSpecs))

    result = repos.findTroves(cfg.buildLabel, troveSpecs, cfg.buildFlavor)
    troveList = [x for x in itertools.chain(*result.itervalues())]

    sigKey = selectSignatureKey(cfg, newLabel)

    if makeShadow:
        dups, cs = client.createShadowChangeSet(newLabel, troveList,
                                                allowEmptyShadow=\
                                                    allowEmptyShadow,
                                                branchType=branchType,
                                                sigKeyId=sigKey)
    else:
        dups, cs = client.createBranchChangeSet(newLabel,
                                                troveList,
                                                branchType=branchType,
                                                sigKeyId=sigKey)

    for (name, branch) in dups:
        log.warning("%s already has branch %s", name, branch.asString())

    if not cs:
        return

    if makeShadow:
        branchOps = 'shadows'
    else:
        branchOps = 'branches'

    hasBinary = False
    for trvCs in cs.iterNewTroveList():
        if not trvCs.getName().endswith(':source'):
            hasBinary = True
            break

    if cfg.interactive or info:
        print 'The following %s will be created:' % branchOps
        displayBranchJob(cs, shadow=makeShadow)

    if cfg.interactive:
        print
        if hasBinary and branchType & client.BRANCH_BINARY:
            print 'WARNING: You have chosen to create binary %s. ' \
                  'This is not recommended\nwith this version of cvc.' \
                    % branchOps
            print
        okay = cmdline.askYn('Continue with %s? [y/N]' % branchOps.lower(),
                             default=False)
        if not okay:
            return
    elif (not forceBinary) and hasBinary and branchType & client.BRANCH_BINARY:
        print 'Creating binary %s is only allowed in interactive mode. ' \
              'Rerun cvc\nwith --interactive.' % branchOps
        return 1

    if not info:
        if targetFile:
            cs.writeToFile(targetFile)
        else:
            client.repos.commitChangeSet(cs)