Changeset 17 for mergebot/trunk/mergebot/BranchActor.py
- Timestamp:
- Jun 8, 2009 3:07:47 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
mergebot/trunk/mergebot/BranchActor.py
r16 r17 1 1 #!/usr/bin/env python 2 2 """Module for creating new branches for tickets""" 3 # Syntax: BranchActor.py ticketnum component version requestor4 3 5 4 import os 6 import sys7 5 import time 8 import trac.env9 6 10 import SvnOps 11 from WorkQueue import MergeBotActor, VersionToDir 12 from TrackerTools import GetRepositoryPublicUrl, GetRepositoryLocalUrl, Task, \ 13 GetLogFile 7 from mergebot import SvnOps 8 from mergebot.Actor import Actor 14 9 15 def branch_action(trac_env, ticketnum, component, version, requestor): 16 "Create the branch" 17 task_obj = Task(trac_env, ticketnum) 10 class BranchActor(Actor): 11 """This class handles creating a new branch for a ticket.""" 12 def execute(self): 13 """Create the branch for the given ticket. 14 """ 15 results = {} 16 # Setup logging 17 logfile = self.logfilename() 18 open(logfile, "a").write("%s: branching ticket %s\n" % (time.asctime(), 19 self.ticket)) 18 20 19 # Setup logging 20 logfile = GetLogFile(trac_env, ticketnum) 21 open(logfile, "a").write("%s: branching ticket %s\n" % (time.asctime(), 22 ticketnum)) 21 # Make sure the various urls we require do exist 22 if not SvnOps.get_branch_info(self.local_url(), logfile): 23 comment = 'Component %s does not exist in the repository.' \ 24 % self.component 25 return results, comment, False 26 if not SvnOps.get_branch_info(self.local_url() + '/branches', logfile): 27 comment = 'No directory in which to create branches for component %s in the repository.' % self.component 28 return results, comment, False 29 if not SvnOps.get_branch_info(self.baseline_local_url(), logfile): 30 comment = 'Version %s for component %s does not exist in the repository.' % (self.version, self.component) 31 return results, comment, False 23 32 24 # Determine the URLS to copy from and to 25 branchdir = "branches/ticket-%s" % (ticketnum) 26 copyfrom = os.path.join(GetRepositoryLocalUrl(trac_env), component, 27 VersionToDir(version)) 28 copyto = os.path.join(GetRepositoryLocalUrl(trac_env), component, branchdir) 33 commit_header = 'Ticket #%s: %s' % (self.ticket, self.summary) 29 34 30 commit_header = "Ticket #%s: %s" % (ticketnum, task_obj.GetSummary()) 35 # Delete the branch if it already exists. This can happen if the branch 36 # was merged, but we're still working on it. 37 if SvnOps.get_branch_info(self.branch_local_url(), logfile): 38 # This branch already exists. 39 commit_message = "\n".join([commit_header, 40 " Delete old branch", 41 ]) 42 new_rev = SvnOps.delete_branch(self.branch_local_url(), 43 commit_message, logfile) 44 if new_rev == -1: 45 results['mergebotstate'] = 'branchfailed' 46 comment = 'Deleting the existing branch failed.' 47 return results, comment, False 31 48 32 # Delete the branch if it already exists. This can happen if the branch 33 # was merged, but we're still working on it. 34 if SvnOps.get_branch_info(copyto, logfile): 35 # This branch already exists. 49 # Do the branch creationg 36 50 commit_message = "\n".join([commit_header, 37 " Delete old branch", 51 " Create branch from %s for %s." % (self.version, 52 self.requestor), 38 53 ]) 39 new_rev = SvnOps.delete_branch(copyto, commit_message, logfile) 40 if new_rev == -1: 41 status = "branchfailed" 42 return status, task_obj 43 44 # Do the branch creationg 45 commit_message = "\n".join([commit_header, 46 " Create branch from %s for %s." % (version, requestor), 47 ]) 48 retval = SvnOps.create_branch(copyfrom, copyto, commit_message, logfile) 49 if retval: 50 # Failed for some reason. 51 status = "branchfailed" 52 else: 53 publiccopyto = os.path.join(GetRepositoryPublicUrl(trac_env), component, 54 branchdir) 55 comment = "\n".join([ 56 "Created branch from %s for %s." % (version, requestor), 57 "", 58 "Browse branch [source:%s source code] and [log:%s commit log]." % 59 (os.path.join(component, branchdir), 60 os.path.join(component, branchdir)), 61 "", 62 "To checkout, run:", 63 "{{{", 64 "svn checkout %s %s-%s" % (publiccopyto, component, ticketnum), 65 "}}}", 54 retval = SvnOps.create_branch(self.baseline_local_url(), 55 self.branch_local_url(), commit_message, logfile) 56 if retval: 57 # Failed for some reason. 58 results['mergebotstate'] = 'branchfailed' 59 comment = 'Failed to create branch.' 60 return results, comment, False 61 results['mergebotstate'] = 'branched' 62 comment = '\n'.join([ 63 'Created branch from %s for %s.' % (self.version, self.requestor), 64 '', 65 'Browse branch [source:%s/branches/ticket-%s source code] and [log:%s/branches/ticket-%s commit log].' % 66 (self.component, self.ticket, self.component, self.ticket), 67 '', 68 'To checkout, run:', 69 '{{{', 70 'svn checkout %s %s-%s' % (self.branch_public_url(), 71 self.component, self.ticket), 72 '}}}', 66 73 ]) 67 task_obj.AddComment(comment) 68 status = "branched" 69 return status, task_obj 70 71 class BranchActor(MergeBotActor): 72 "Actor for creating a new branch." 73 def __init__(self, trac_env): 74 MergeBotActor.__init__(self, trac_env, "branch", branch_action) 75 76 def main(): 77 tracdir = sys.argv[1] 78 trac_env = trac.env.open_environment(tracdir) 79 branchingActor = BranchActor(trac_env) 80 branchingActor.AddTask(sys.argv[2:]) 81 branchingActor.Run() 82 83 if __name__ == "__main__": 84 main() 74 return results, comment, True 85 75 86 76 # vim:foldcolumn=4 foldmethod=indent
Note: See TracChangeset
for help on using the changeset viewer.