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

Source Code for Module conary.commit

 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 os 
15  import tempfile 
16   
17  from conary import conaryclient 
18  from conary import versions 
19  from conary.lib import log 
20  from conary.repository import changeset 
21  from conary.repository import errors 
22  from conary.repository import filecontainer 
23   
24 -def doCommit(cfg, changeSetFile, targetLabel):
25 client = conaryclient.ConaryClient(cfg) 26 repos = client.getRepos() 27 28 try: 29 cs = changeset.ChangeSetFromFile(changeSetFile) 30 except filecontainer.BadContainer: 31 log.error("invalid changeset %s", changeSetFile) 32 return 1 33 34 if cs.isLocal(): 35 if not targetLabel: 36 log.error("committing local changesets requires a targetLabel") 37 label = versions.Label(targetLabel) 38 cs.setTargetShadow(repos, label) 39 commitCs = cs.makeAbsolute(repos) 40 41 (fd, changeSetFile) = tempfile.mkstemp() 42 43 os.close(fd) 44 commitCs.writeToFile(changeSetFile) 45 46 try: 47 # hopefully the file hasn't changed underneath us since we 48 # did the check at the top of doCommit(). We should probably 49 # add commitChangeSet method that takes a fd. 50 try: 51 repos.commitChangeSetFile(changeSetFile) 52 except errors.CommitError, e: 53 print e 54 finally: 55 if targetLabel: 56 os.unlink(changeSetFile)
57
58 -def doLocalCommit(db, changeSetFile):
59 cs = changeset.ChangeSetFromFile(changeSetFile) 60 if not cs.isLocal(): 61 log.error("repository changesets must be applied with update instead") 62 else: 63 db.commitChangeSet(cs, set(), rollbackPhase = db.ROLLBACK_PHASE_LOCAL, 64 updateDatabase = False)
65