~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/code/model/branchjob.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-09-06 20:10:34 UTC
  • mfrom: (13851.2.3 ubuntu-font-787798)
  • Revision ID: launchpad@pqm.canonical.com-20110906201034-f56n10lcb3fzr5np
[r=bac][ui=sinzui][bug=787798] Use Google Web Fonts so Launchpad
        always displays in Ubuntu font

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
 
1
# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
2
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
3
 
4
4
__all__ = [
30
30
    show_log,
31
31
    )
32
32
from bzrlib.revision import NULL_REVISION
33
 
from bzrlib.revisionspec import (
34
 
    RevisionInfo,
35
 
    RevisionSpec,
36
 
    )
 
33
from bzrlib.revisionspec import RevisionInfo
37
34
from bzrlib.transport import get_transport
38
35
from bzrlib.upgrade import upgrade
39
36
from lazr.delegates import delegates
79
76
    BranchSubscriptionNotificationLevel,
80
77
    )
81
78
from lp.code.interfaces.branchjob import (
82
 
    IBranchDiffJob,
83
 
    IBranchDiffJobSource,
84
79
    IBranchJob,
85
80
    IBranchScanJob,
86
81
    IBranchScanJobSource,
97
92
from lp.code.mail.branch import BranchMailer
98
93
from lp.code.model.branch import Branch
99
94
from lp.code.model.branchmergeproposal import BranchMergeProposal
100
 
from lp.code.model.diff import StaticDiff
101
95
from lp.code.model.revision import RevisionSet
102
96
from lp.codehosting.scanner.bzrsync import BzrSync
103
97
from lp.codehosting.vfs import (
285
279
        return [format_address_for_person(self.requester)]
286
280
 
287
281
 
288
 
class BranchDiffJob(BranchJobDerived):
289
 
    """A Job that calculates the a diff related to a Branch."""
290
 
 
291
 
    implements(IBranchDiffJob)
292
 
    classProvides(IBranchDiffJobSource)
293
 
 
294
 
    @classmethod
295
 
    def create(cls, branch, from_revision_spec, to_revision_spec):
296
 
        """See `IBranchDiffJobSource`."""
297
 
        metadata = cls.getMetadata(from_revision_spec, to_revision_spec)
298
 
        branch_job = BranchJob(branch, BranchJobType.STATIC_DIFF, metadata)
299
 
        return cls(branch_job)
300
 
 
301
 
    @staticmethod
302
 
    def getMetadata(from_revision_spec, to_revision_spec):
303
 
        return {
304
 
            'from_revision_spec': from_revision_spec,
305
 
            'to_revision_spec': to_revision_spec,
306
 
        }
307
 
 
308
 
    @property
309
 
    def from_revision_spec(self):
310
 
        return self.metadata['from_revision_spec']
311
 
 
312
 
    @property
313
 
    def to_revision_spec(self):
314
 
        return self.metadata['to_revision_spec']
315
 
 
316
 
    def _get_revision_id(self, bzr_branch, spec_string):
317
 
        spec = RevisionSpec.from_string(spec_string)
318
 
        return spec.as_revision_id(bzr_branch)
319
 
 
320
 
    def run(self):
321
 
        """See IBranchDiffJob."""
322
 
        bzr_branch = self.branch.getBzrBranch()
323
 
        from_revision_id = self._get_revision_id(
324
 
            bzr_branch, self.from_revision_spec)
325
 
        to_revision_id = self._get_revision_id(
326
 
            bzr_branch, self.to_revision_spec)
327
 
        static_diff = StaticDiff.acquire(
328
 
            from_revision_id, to_revision_id, bzr_branch.repository)
329
 
        return static_diff
330
 
 
331
 
 
332
282
class BranchScanJob(BranchJobDerived):
333
283
    """A Job that scans a branch for new revisions."""
334
284
 
447
397
            shutil.rmtree(upgrade_branch_path)
448
398
 
449
399
 
450
 
class RevisionMailJob(BranchDiffJob):
451
 
    """A Job that calculates the a diff related to a Branch."""
 
400
class RevisionMailJob(BranchJobDerived):
 
401
    """A Job that sends a mail for a scan of a Branch."""
452
402
 
453
403
    implements(IRevisionMailJob)
454
404
 
457
407
    class_job_type = BranchJobType.REVISION_MAIL
458
408
 
459
409
    @classmethod
460
 
    def create(
461
 
        cls, branch, revno, from_address, body, perform_diff, subject):
 
410
    def create(cls, branch, revno, from_address, body, subject):
462
411
        """See `IRevisionMailJobSource`."""
463
412
        metadata = {
464
413
            'revno': revno,
465
414
            'from_address': from_address,
466
415
            'body': body,
467
 
            'perform_diff': perform_diff,
468
416
            'subject': subject,
469
417
        }
470
 
        if isinstance(revno, int) and revno > 0:
471
 
            from_revision_spec = str(revno - 1)
472
 
            to_revision_spec = str(revno)
473
 
        else:
474
 
            from_revision_spec = None
475
 
            to_revision_spec = None
476
 
        metadata.update(BranchDiffJob.getMetadata(from_revision_spec,
477
 
                        to_revision_spec))
478
418
        branch_job = BranchJob(branch, BranchJobType.REVISION_MAIL, metadata)
479
419
        return cls(branch_job)
480
420
 
481
421
    @property
482
422
    def revno(self):
483
 
        revno = self.metadata['revno']
484
 
        if isinstance(revno, int):
485
 
            revno = long(revno)
486
 
        return revno
 
423
        return self.metadata['revno']
487
424
 
488
425
    @property
489
426
    def from_address(self):
490
427
        return str(self.metadata['from_address'])
491
428
 
492
429
    @property
493
 
    def perform_diff(self):
494
 
        return self.metadata['perform_diff']
495
 
 
496
 
    @property
497
430
    def body(self):
498
431
        return self.metadata['body']
499
432
 
503
436
 
504
437
    def getMailer(self):
505
438
        """Return a BranchMailer for this job."""
506
 
        if self.perform_diff and self.to_revision_spec is not None:
507
 
            diff = BranchDiffJob.run(self)
508
 
            transaction.commit()
509
 
            diff_text = diff.diff.text
510
 
        else:
511
 
            diff_text = None
512
439
        return BranchMailer.forRevision(
513
440
            self.branch, self.revno, self.from_address, self.body,
514
 
            diff_text, self.subject)
 
441
            None, self.subject)
515
442
 
516
443
    def run(self):
517
444
        """See `IRevisionMailJob`."""