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

Source Code for Module conary.cscmd

  1  # 
  2  # Copyright (c) 2004-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 conaryclient 
 17  from conary import versions 
 18  from conary.conaryclient import cmdline 
 19  from conary.lib import log 
 20  from conary.local import update 
 21  from conary.repository import errors 
 22   
23 -def computeTroveList(client, applyList):
24 # As dumb as this may sound, the same trove may be present multiple times 25 # in applyList, so remove duplicates 26 toFind = set() 27 for (n, (oldVer, oldFla), (newVer, newFla), isAbs) in applyList: 28 if n[0] in ('-', '+'): 29 n = n[1:] 30 31 found = False 32 if oldVer or (oldFla is not None): 33 toFind.add((n, oldVer,oldFla)) 34 found = True 35 36 if newVer or (newFla is not None): 37 toFind.add((n, newVer, newFla)) 38 found = True 39 40 if not found: 41 toFind.add((n, None, None)) 42 43 repos = client.getRepos() 44 results = repos.findTroves(client.cfg.installLabelPath, toFind, 45 client.cfg.flavor) 46 47 for troveSpec, trovesFound in results.iteritems(): 48 if len(trovesFound) > 1: 49 log.error("trove %s has multiple matches on " 50 "installLabelPath", troveSpec[0]) 51 52 primaryCsList = [] 53 54 for (n, (oldVer, oldFla), (newVer, newFla), isAbs) in applyList: 55 if n[0] == '-': 56 updateByDefault = False 57 else: 58 updateByDefault = True 59 60 if n[0] in ('-', '+'): 61 n = n[1:] 62 63 found = False 64 if oldVer or (oldFla is not None): 65 oldVer, oldFla = results[n, oldVer, oldFla][0][1:] 66 found = True 67 68 if newVer or (newFla is not None): 69 newVer, newFla = results[n, newVer, newFla][0][1:] 70 found = True 71 72 if not found: 73 if updateByDefault: 74 newVer, newFla = results[n, None, None][0][1:] 75 else: 76 oldVer, oldFla = results[n, None, None][0][1:] 77 78 primaryCsList.append((n, (oldVer, oldFla), (newVer, newFla), isAbs)) 79 80 return primaryCsList
81
82 -def ChangeSetCommand(cfg, troveSpecs, outFileName, recurse = True, 83 callback = None):
84 client = conaryclient.ConaryClient(cfg) 85 applyList = cmdline.parseChangeList(troveSpecs, allowChangeSets=False) 86 87 primaryCsList = computeTroveList(client, applyList) 88 89 client.createChangeSetFile(outFileName, primaryCsList, recurse = recurse, 90 callback = callback, 91 excludeList = cfg.excludeTroves)
92
93 -def LocalChangeSetCommand(db, cfg, item, outFileName):
94 client = conaryclient.ConaryClient(cfg) 95 96 name, ver, flv = cmdline.parseTroveSpec(item) 97 troveList = client.db.findTrove(None, (name, ver, flv)) 98 troveList = client.db.getTroves(troveList) 99 100 list = [] 101 for outerTrove in troveList: 102 for trove in db.walkTroveSet(outerTrove): 103 ver = trove.getVersion() 104 origTrove = db.getTrove(trove.getName(), ver, trove.getFlavor(), 105 pristine = True) 106 ver = ver.createShadow(versions.LocalLabel()) 107 list.append((trove, origTrove, ver, update.UpdateFlags())) 108 109 incomplete = [ db.troveIsIncomplete(x[1].getName(), x[1].getVersion(), 110 x[1].getFlavor()) for x in list ] 111 incomplete = [ x[0][1] for x in itertools.izip(list, incomplete) if x[1] ] 112 if incomplete: 113 raise errors.ConaryError('''\ 114 Cannot create a local changeset using an incomplete troves: Please ensure 115 you have the latest conary and then reinstall these troves: 116 %s 117 ''' % '\n '.join('%s=%s[%s]' % (x.getName(),x.getVersion(),x.getFlavor()) for x in incomplete)) 118 119 result = update.buildLocalChanges(db, list, root = cfg.root, 120 updateContainers = True) 121 if not result: return 122 cs = result[0] 123 124 for outerTrove in troveList: 125 cs.addPrimaryTrove(outerTrove.getName(), 126 outerTrove.getVersion().createShadow( 127 versions.LocalLabel()), 128 outerTrove.getFlavor()) 129 130 for (changed, fsTrove) in result[1]: 131 if changed: 132 break 133 134 if not changed: 135 log.error("there have been no local changes") 136 else: 137 cs.writeToFile(outFileName)
138