| 1 | #! /usr/bin/python |
|---|
| 2 | # -*- mode: python; coding: utf-8 -*- |
|---|
| 3 | # :Progetto: vcpx -- Monotone details |
|---|
| 4 | # :Creato: Tue Apr 12 01:28:10 CEST 2005 |
|---|
| 5 | # :Autore: Markus Schiltknecht <markus@bluegap.ch> |
|---|
| 6 | # |
|---|
| 7 | |
|---|
| 8 | """ |
|---|
| 9 | This module contains supporting classes for Monotone. |
|---|
| 10 | """ |
|---|
| 11 | |
|---|
| 12 | __docformat__ = 'reStructuredText' |
|---|
| 13 | |
|---|
| 14 | from shwrap import SystemCommand, shrepr |
|---|
| 15 | from source import UpdatableSourceWorkingDir, \ |
|---|
| 16 | ChangesetApplicationFailure, GetUpstreamChangesetsFailure |
|---|
| 17 | from target import SyncronizableTargetWorkingDir, TargetInitializationFailure |
|---|
| 18 | |
|---|
| 19 | class MonotoneCommit(SystemCommand): |
|---|
| 20 | COMMAND = "MONOTONE_AUTHOR=\"%(key)s\" monotone commit --date=\"%(date)s\" %(entries)s" |
|---|
| 21 | |
|---|
| 22 | def __call__(self, output=None, dry_run=False, **kwargs): |
|---|
| 23 | log = open(self.working_dir + "/MT/log", "w"); |
|---|
| 24 | |
|---|
| 25 | logmessage = kwargs.get('logmessage') |
|---|
| 26 | if logmessage: |
|---|
| 27 | log.write(logmessage + "\n") |
|---|
| 28 | |
|---|
| 29 | log.close(); |
|---|
| 30 | |
|---|
| 31 | return SystemCommand.__call__(self, output=output, |
|---|
| 32 | dry_run=dry_run, **kwargs) |
|---|
| 33 | |
|---|
| 34 | class MonotoneAdd(SystemCommand): |
|---|
| 35 | COMMAND = "monotone add %(entry)s" |
|---|
| 36 | |
|---|
| 37 | class MonotoneRemove(SystemCommand): |
|---|
| 38 | COMMAND = "monotone drop %(entry)s" |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | class MonotoneMv(SystemCommand): |
|---|
| 42 | COMMAND = "monotone rename %(old)s %(new)s" |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | class MonotoneWorkingDir(UpdatableSourceWorkingDir, SyncronizableTargetWorkingDir): |
|---|
| 46 | |
|---|
| 47 | ## SyncronizableTargetWorkingDir |
|---|
| 48 | |
|---|
| 49 | def _addEntries(self, root, entries): |
|---|
| 50 | """ |
|---|
| 51 | Add a sequence of entries. |
|---|
| 52 | """ |
|---|
| 53 | |
|---|
| 54 | c = MonotoneAdd(working_dir=root) |
|---|
| 55 | c(entry=' '.join([shrepr(e.name) for e in entries])) |
|---|
| 56 | |
|---|
| 57 | def _commit(self,root, date, author, remark, changelog=None, entries=None): |
|---|
| 58 | """ |
|---|
| 59 | Commit the changeset. |
|---|
| 60 | """ |
|---|
| 61 | |
|---|
| 62 | c = MonotoneCommit(working_dir=root) |
|---|
| 63 | |
|---|
| 64 | if entries: |
|---|
| 65 | entries = ' '.join([shrepr(e) for e in entries]) |
|---|
| 66 | else: |
|---|
| 67 | entries = '.' |
|---|
| 68 | |
|---|
| 69 | c(key=author, logmessage=changelog, date=date, entries=entries) |
|---|
| 70 | |
|---|
| 71 | if c.exit_status: |
|---|
| 72 | raise TargetInitializationFailure( |
|---|
| 73 | "'monotone commit returned %s" % c.exit_status) |
|---|
| 74 | |
|---|
| 75 | def _removeEntries(self, root, entries): |
|---|
| 76 | """ |
|---|
| 77 | Remove a sequence of entries. |
|---|
| 78 | """ |
|---|
| 79 | |
|---|
| 80 | c = MonotoneRemove(working_dir=root) |
|---|
| 81 | c(entry=' '.join([shrepr(e.name) for e in entries])) |
|---|
| 82 | |
|---|
| 83 | def _renameEntry(self, root, oldentry, newentry): |
|---|
| 84 | """ |
|---|
| 85 | Rename an entry. |
|---|
| 86 | """ |
|---|
| 87 | |
|---|
| 88 | c = MonotoneMv(working_dir=root) |
|---|
| 89 | c(old=shrepr(oldentry), new=repr(newentry)) |
|---|
| 90 | |
|---|
| 91 | def _initializeWorkingDir(self, root, repository, module, subdir): |
|---|
| 92 | """ |
|---|
| 93 | Execute `monotone setup`. |
|---|
| 94 | """ |
|---|
| 95 | |
|---|
| 96 | from os.path import join |
|---|
| 97 | |
|---|
| 98 | c = SystemCommand(working_dir=root, command="monotone setup .") |
|---|
| 99 | c(output=True) |
|---|
| 100 | |
|---|
| 101 | if c.exit_status: |
|---|
| 102 | raise TargetInitializationFailure( |
|---|
| 103 | "'monotone setup' returned status %s" % c.exit_status) |
|---|
| 104 | |
|---|
| 105 | c = SystemCommand(working_dir=root, |
|---|
| 106 | command="monotone add %(entry)s") |
|---|
| 107 | c(entry=shrepr(subdir)) |
|---|