~ursinha/lp-qa-tools/bzr-tarmacland

« back to all changes in this revision

Viewing changes to pqm_submit.py

  • Committer: Andrew Bennetts
  • Date: 2009-10-14 06:47:52 UTC
  • Revision ID: andrew@bemusement.org-20091014064752-28xlcdfphzli4dce
Slightly hackish way to allow submitting branches I don't have locally.

Show diffs side-by-side

added added

removed removed

Lines of Context:
75
75
        If any of public_location, submit_location or message are
76
76
        omitted, they will be calculated from source_branch.
77
77
        """
78
 
        if source_branch is None:
 
78
        if source_branch is None and public_location is None:
79
79
            raise errors.NoMergeSource()
80
80
        self.source_branch = source_branch
81
81
        self.tree = tree
100
100
        self.public_location = public_location
101
101
 
102
102
        if submit_location is None:
 
103
            if self.source_branch is None:
 
104
                raise errors.BzrError(
 
105
                    "Cannot determine submit location to use.")
103
106
            config = self.source_branch.get_config()
104
107
            # First check the deprecated pqm_branch config key:
105
108
            submit_location = config.get_user_option('pqm_branch')
166
169
        unsigned_text = ''.join(self.to_lines())
167
170
        unsigned_text = unsigned_text.encode('ascii') #URLs should be ascii
168
171
 
169
 
        strategy = gpg.GPGStrategy(self.source_branch.get_config())
 
172
        if self.source_branch:
 
173
            config = self.source_branch.get_config()
 
174
        else:
 
175
            config = _mod_config.GlobalConfig()
 
176
        strategy = gpg.GPGStrategy(config)
170
177
        return strategy.sign(unsigned_text)
171
178
 
172
179
    def to_email(self, mail_from, mail_to, sign=True):
185
192
        return message
186
193
 
187
194
 
 
195
class StackedConfig(_mod_config.Config):
 
196
 
 
197
    def __init__(self):
 
198
        super(StackedConfig, self).__init__()
 
199
        self._sources = []
 
200
 
 
201
    def add_source(self, source):
 
202
        self._sources.append(source)
 
203
 
 
204
    def _get_user_option(self, option_name):
 
205
        """See Config._get_user_option."""
 
206
        for source in self._sources:
 
207
            value = source._get_user_option(option_name)
 
208
            if value is not None:
 
209
                return value
 
210
        return None
 
211
 
 
212
    def _get_user_id(self):
 
213
        for source in self._sources:
 
214
            value = source._get_user_id()
 
215
            if value is not None:
 
216
                return value
 
217
        return None
 
218
 
 
219
 
188
220
def submit(branch, message, dry_run=False, public_location=None,
189
 
           submit_location=None, tree=None):
 
221
           submit_location=None, tree=None, ignore_local=False):
190
222
    """Submit the given branch to the pqm."""
191
 
    config = branch.get_config()
 
223
    config = StackedConfig()
 
224
    if branch:
 
225
        config.add_source(branch.get_config())
 
226
    else:
 
227
        if public_location:
 
228
            config.add_source(_mod_config.LocationConfig(public_location))
 
229
        config.add_source(_mod_config.GlobalConfig())
192
230
 
193
231
    submission = PQMSubmission(
194
232
        source_branch=branch, public_location=public_location, message=message,
204
242
        raise NoPQMSubmissionAddress(branch)
205
243
    mail_to = mail_to.encode('utf8') # same here
206
244
 
207
 
    submission.check_tree()
208
 
    submission.check_public_branch()
 
245
    if not ignore_local:
 
246
        submission.check_tree()
 
247
        submission.check_public_branch()
209
248
 
210
249
    message = submission.to_email(mail_from, mail_to)
211
250