Package conary :: Module clone
[hide private]
[frames] | no frames]

Source Code for Module conary.clone

  1  # 
  2  # Copyright (c) 2005-2008 rPath, Inc. 
  3  # 
  4  # This program is distributed under the terms of the Common Public License, 
  5  # version 1.0. A copy of this license should have been distributed with this 
  6  # source file in a file called LICENSE. If it is not present, the license 
  7  # is always available at http://www.rpath.com/permanent/licenses/CPL-1.0. 
  8  # 
  9  # This program is distributed in the hope that it will be useful, but 
 10  # without any warranty; without even the implied warranty of merchantability 
 11  # or fitness for a particular purpose. See the Common Public License for 
 12  # full details. 
 13  # 
 14  import itertools 
 15   
 16  from conary import callbacks 
 17  from conary import errors 
 18  from conary import versions 
 19  from conary import conaryclient 
 20  from conary.conaryclient import ConaryClient, cmdline 
 21  from conary.build.cook import signAbsoluteChangesetByConfig 
 22  from conary.conarycfg import selectSignatureKey 
 23  from conary.deps import deps 
 24   
25 -def displayCloneJob(cs):
26 indent = ' ' 27 def _sortTroveNameKey(x): 28 name = x.getName() 29 return (not name.endswith(':source'), x.getNewFlavor(), name)
30 csTroves = sorted(cs.iterNewTroveList(), key=_sortTroveNameKey) 31 32 for csTrove in csTroves: 33 newInfo = str(csTrove.getNewVersion()) 34 flavor = csTrove.getNewFlavor() 35 if not flavor.isEmpty(): 36 newInfo += '[%s]' % flavor 37 38 print "%sClone %-20s (%s)" % (indent, csTrove.getName(), newInfo) 39
40 -def CloneTrove(cfg, targetBranch, troveSpecList, updateBuildInfo = True, 41 info = False, cloneSources = False, message = None, 42 test = False, fullRecurse = False, ignoreConflicts = False, 43 exactFlavors = False):
44 client = ConaryClient(cfg) 45 repos = client.getRepos() 46 47 targetBranch = versions.VersionFromString(targetBranch) 48 if not isinstance(targetBranch, versions.Branch): 49 raise errors.ParseError('Cannot specify full version "%s" to clone to - must specify target branch' % targetBranch) 50 51 troveSpecs = [ cmdline.parseTroveSpec(x) for x in troveSpecList] 52 53 componentSpecs = [ x[0] for x in troveSpecs 54 if ':' in x[0] and x[0].split(':')[1] != 'source'] 55 if componentSpecs: 56 raise errors.ParseError('Cannot clone components: %s' % ', '.join(componentSpecs)) 57 58 59 trovesToClone = repos.findTroves(cfg.installLabelPath, 60 troveSpecs, cfg.flavor, 61 exactFlavors = exactFlavors) 62 trovesToClone = list(set(itertools.chain(*trovesToClone.itervalues()))) 63 64 if not client.cfg.quiet: 65 callback = conaryclient.callbacks.CloneCallback(client.cfg, message) 66 else: 67 callback = callbacks.CloneCallback() 68 69 okay, cs = client.createCloneChangeSet(targetBranch, trovesToClone, 70 updateBuildInfo=updateBuildInfo, 71 infoOnly=info, callback=callback, 72 fullRecurse=fullRecurse, 73 cloneSources=cloneSources) 74 if not okay: 75 return 76 return _finishClone(client, cfg, cs, callback, info=info, 77 test=test, ignoreConflicts=ignoreConflicts)
78
79 -def _convertLabelOrBranch(lblStr, template):
80 try: 81 if not lblStr: 82 return None 83 if lblStr[0] == '/': 84 v = versions.VersionFromString(lblStr) 85 if isinstance(v, versions.Branch): 86 return v 87 # Some day we could lift this restriction if its useful. 88 raise errors.ParseError('Cannot specify version to promote' 89 ' - must specify branch or label') 90 91 92 hostName = template.getHost() 93 nameSpace = template.getNamespace() 94 tag = template.branch 95 96 if lblStr[0] == ':': 97 lblStr = '%s@%s%s' % (hostName, nameSpace, lblStr) 98 elif lblStr[0] == '@': 99 lblStr = '%s%s' % (hostName, lblStr) 100 elif lblStr[-1] == '@': 101 lblStr = '%s%s:%s' % (lblStr, nameSpace, tag) 102 return versions.Label(lblStr) 103 except Exception, msg: 104 raise errors.ParseError('Error parsing %r: %s' % (lblStr, msg))
105
106 -def promoteTroves(cfg, troveSpecs, targetList, skipBuildInfo=False, 107 info=False, message=None, test=False, 108 ignoreConflicts=False, cloneOnlyByDefaultTroves=False, 109 cloneSources = False, allFlavors = False, client=None, 110 targetFile = None, exactFlavors = None, 111 excludeGroups = False):
112 targetMap = {} 113 searchPath = [] 114 for fromLoc, toLoc in targetList: 115 context = cfg.buildLabel 116 fromLoc = _convertLabelOrBranch(fromLoc, context) 117 if fromLoc is not None: 118 if isinstance(fromLoc, versions.Branch): 119 context = fromLoc.label() 120 else: 121 context = fromLoc 122 searchPath.append(context) 123 toLoc = _convertLabelOrBranch(toLoc, context) 124 targetMap[fromLoc] = toLoc 125 126 troveSpecs = [ cmdline.parseTroveSpec(x, False) for x in troveSpecs ] 127 if exactFlavors: 128 allFlavors = False 129 elif allFlavors: 130 cfg.flavor = [] 131 troveSpecFlavors = {} 132 for troveSpec in troveSpecs: 133 troveSpecFlavors.setdefault( 134 (troveSpec[0], troveSpec[1], None), 135 []).append(troveSpec[2]) 136 troveSpecs = list(troveSpecFlavors) 137 138 139 client = ConaryClient(cfg) 140 if not searchPath: 141 searchPath = cfg.buildLabel 142 searchSource = client.getSearchSource(installLabelPath=searchPath) 143 results = searchSource.findTroves(troveSpecs, 144 bestFlavor=not allFlavors, 145 exactFlavors=exactFlavors) 146 if allFlavors: 147 trovesToClone = [] 148 for troveSpec, troveTups in results.items(): 149 specFlavors = troveSpecFlavors[troveSpec] 150 for specFlavor in specFlavors: 151 if specFlavor is None: 152 matchingTups = troveTups 153 else: 154 matchingTups = [ x for x in troveTups 155 if x[2].stronglySatisfies(specFlavor)] 156 # we only clone the latest version for all troves. 157 # bestFlavor=False resturns the leaves for all flavors, so 158 # we may need to cut some out. 159 latest = max([x[1] for x in matchingTups]) 160 matchingTups = [ x for x in matchingTups if x[1] == latest ] 161 trovesToClone.extend(matchingTups) 162 else: 163 trovesToClone = itertools.chain(*results.itervalues()) 164 trovesToClone = list(set(trovesToClone)) 165 166 if not client.cfg.quiet: 167 callback = conaryclient.callbacks.CloneCallback(client.cfg, message) 168 else: 169 callback = callbacks.CloneCallback() 170 171 okay, cs = client.createSiblingCloneChangeSet( 172 targetMap, trovesToClone, 173 updateBuildInfo=not skipBuildInfo, 174 infoOnly=info, callback=callback, 175 cloneOnlyByDefaultTroves=cloneOnlyByDefaultTroves, 176 cloneSources=cloneSources, 177 excludeGroups=excludeGroups) 178 if not okay: 179 return False 180 return _finishClone(client, cfg, cs, callback, info=info, 181 test=test, ignoreConflicts=ignoreConflicts, 182 targetFile=targetFile)
183
184 -def _finishClone(client, cfg, cs, callback, info=False, test=False, 185 ignoreConflicts=False, targetFile=None):
186 repos = client.repos 187 if cfg.interactive or info: 188 print 'The following clones will be created:' 189 displayCloneJob(cs) 190 191 if info: 192 return 193 194 if cfg.interactive: 195 print 196 okay = cmdline.askYn('continue with clone? [y/N]', default=False) 197 if not okay: 198 return 199 200 if targetFile: 201 cs.writeToFile(targetFile) 202 elif not test: 203 repos.commitChangeSet(cs, callback=callback) 204 return cs
205