1 | """Base class for mergebot actors that do the various kinds of tasks |
---|
2 | """ |
---|
3 | import os |
---|
4 | from mergebot.svn import SvnLib |
---|
5 | SvnOps = SvnLib() |
---|
6 | |
---|
7 | class Actor(object): |
---|
8 | """Base class for mergebot actors""" |
---|
9 | def __init__(self, work_dir, repo_url, repo_dir, ticket, component, |
---|
10 | version, summary, requestor): |
---|
11 | self.work_dir = work_dir |
---|
12 | self.repo_url = repo_url |
---|
13 | self.repo_dir = repo_dir |
---|
14 | self.ticket = ticket |
---|
15 | self.component = component |
---|
16 | self.version = version |
---|
17 | self.summary = summary |
---|
18 | self.requestor = requestor |
---|
19 | |
---|
20 | def execute(self): |
---|
21 | """To be overridden by subclasses. |
---|
22 | Returns a tuple containing: |
---|
23 | a dictionary of fields to update in the ticket |
---|
24 | a comment string |
---|
25 | True on success, False on failure |
---|
26 | """ |
---|
27 | raise NotImplementedError |
---|
28 | |
---|
29 | def logfilename(self): |
---|
30 | """Returns the absolute path of the logfile for this ticket""" |
---|
31 | return os.path.abspath(os.path.join(os.path.dirname(self.work_dir), |
---|
32 | 'ticket-%s.log' % self.ticket)) |
---|
33 | |
---|
34 | def public_url(self): |
---|
35 | """Returns the public URL for this component""" |
---|
36 | return '%s/%s' % (self.repo_url, self.component) |
---|
37 | |
---|
38 | def branch_public_url(self): |
---|
39 | """Returns the public svn url of the branch for this ticket. |
---|
40 | """ |
---|
41 | return '%s/branches/ticket-%s' % (self.public_url(), self.ticket) |
---|
42 | |
---|
43 | def local_url(self): |
---|
44 | """Returns the local URL for this component""" |
---|
45 | return 'file://%s/%s' % (self.repo_dir, self.component) |
---|
46 | |
---|
47 | def baseline_local_url(self): |
---|
48 | """Returns the local svn url this ticket branches from. |
---|
49 | """ |
---|
50 | return '%s/%s' % (self.local_url(), self.version_subdir()) |
---|
51 | |
---|
52 | def branch_local_url(self): |
---|
53 | """Returns the local svn url of the branch for this ticket. |
---|
54 | """ |
---|
55 | return '%s/branches/ticket-%s' % (self.local_url(), self.ticket) |
---|
56 | |
---|
57 | def version_subdir(self): |
---|
58 | """Returns the subdirectory name for the version""" |
---|
59 | if self.version == 'trunk': |
---|
60 | subdir = 'trunk' |
---|
61 | elif self.version.startswith('#'): |
---|
62 | # branched from another ticket |
---|
63 | subdir = 'branches/ticket-%s' % self.version.lstrip('#') |
---|
64 | else: |
---|
65 | # assume release branch |
---|
66 | subdir = 'branches/release-%s' % self.version |
---|
67 | return subdir |
---|
68 | |
---|
69 | def check_required_directories(self): |
---|
70 | """Make sure the various urls we require do exist""" |
---|
71 | if not SvnOps.does_url_exist(self.local_url()): |
---|
72 | return 'Component %s does not exist in the repository.' \ |
---|
73 | % self.component |
---|
74 | if not SvnOps.does_url_exist(self.local_url() + '/branches'): |
---|
75 | return 'No directory in which to create branches for ' \ |
---|
76 | 'component %s in the repository.' % self.component |
---|
77 | if not SvnOps.does_url_exist(self.baseline_local_url()): |
---|
78 | return 'Version %s for component %s does not exist in the ' \ |
---|
79 | 'repository.' % (self.version, self.component) |
---|
80 | return None |
---|
81 | |
---|