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