| 1 | #! /usr/bin/python |
|---|
| 2 | # -*- mode: python; coding: utf-8 -*- |
|---|
| 3 | # :Progetto: vcpx -- Codeville details |
|---|
| 4 | # :Creato: gio 05 mag 2005 23:47:45 CEST |
|---|
| 5 | # :Autore: Lele Gaifax <lele@nautilus.homeip.net> |
|---|
| 6 | # |
|---|
| 7 | |
|---|
| 8 | """ |
|---|
| 9 | This module implements the backends for Codeville. |
|---|
| 10 | """ |
|---|
| 11 | |
|---|
| 12 | __docformat__ = 'reStructuredText' |
|---|
| 13 | |
|---|
| 14 | from shwrap import SystemCommand, shrepr |
|---|
| 15 | from target import SyncronizableTargetWorkingDir, TargetInitializationFailure |
|---|
| 16 | |
|---|
| 17 | class CdvAdd(SystemCommand): |
|---|
| 18 | COMMAND = "cdv add %(entry)s" |
|---|
| 19 | |
|---|
| 20 | class CdvCommit(SystemCommand): |
|---|
| 21 | COMMAND = "cdv commit -m %(comment)s %(entries)s" |
|---|
| 22 | |
|---|
| 23 | def __call__(self, output=None, dry_run=False, **kwargs): |
|---|
| 24 | logmessage = kwargs.get('logmessage') |
|---|
| 25 | kwargs['comment'] = shrepr(logmessage) |
|---|
| 26 | |
|---|
| 27 | return SystemCommand.__call__(self, output=output, |
|---|
| 28 | dry_run=dry_run, **kwargs) |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | class CdvWorkingDir(SyncronizableTargetWorkingDir): |
|---|
| 32 | |
|---|
| 33 | ## SyncronizableTargetWorkingDir |
|---|
| 34 | |
|---|
| 35 | def _addEntries(self, root, entries): |
|---|
| 36 | """ |
|---|
| 37 | Add a sequence of entries. |
|---|
| 38 | """ |
|---|
| 39 | |
|---|
| 40 | c = SystemCommand(working_dir=root, command="cdv add %(entries)s") |
|---|
| 41 | c(entries=' '.join([shrepr(e.name) for e in entries])) |
|---|
| 42 | |
|---|
| 43 | def _commit(self,root, date, author, remark, changelog=None, entries=None): |
|---|
| 44 | """ |
|---|
| 45 | Commit the changeset. |
|---|
| 46 | """ |
|---|
| 47 | |
|---|
| 48 | c = CdvCommit(working_dir=root) |
|---|
| 49 | |
|---|
| 50 | logmessage = "%s\nOriginal author: %s\nDate: %s" % (remark, author, |
|---|
| 51 | date) |
|---|
| 52 | if changelog: |
|---|
| 53 | logmessage = logmessage + '\n\n' + changelog |
|---|
| 54 | |
|---|
| 55 | if entries: |
|---|
| 56 | entries = ' '.join([shrepr(e) for e in entries]) |
|---|
| 57 | else: |
|---|
| 58 | entries = '.' |
|---|
| 59 | |
|---|
| 60 | c(logmessage=logmessage, entries=entries) |
|---|
| 61 | |
|---|
| 62 | def _removeEntries(self, root, entries): |
|---|
| 63 | """ |
|---|
| 64 | Remove a sequence of entries. |
|---|
| 65 | """ |
|---|
| 66 | |
|---|
| 67 | c = SystemCommand(working_dir=root, command="cdv remove %(entries)s") |
|---|
| 68 | c(entries=' '.join([shrepr(e.name) for e in entries])) |
|---|
| 69 | |
|---|
| 70 | def _renameEntry(self, root, oldentry, newentry): |
|---|
| 71 | """ |
|---|
| 72 | Rename an entry. |
|---|
| 73 | """ |
|---|
| 74 | |
|---|
| 75 | c = SystemCommand(working_dir=root, |
|---|
| 76 | command="cdv rename %(old)s %(new)s") |
|---|
| 77 | c(old=shrepr(oldentry), new=repr(newentry)) |
|---|
| 78 | |
|---|
| 79 | def initializeNewWorkingDir(self, root, repository, module, subdir, revision): |
|---|
| 80 | """ |
|---|
| 81 | Initialize a new working directory, just extracted from |
|---|
| 82 | some other VC system, importing everything's there. |
|---|
| 83 | """ |
|---|
| 84 | |
|---|
| 85 | from datetime import datetime |
|---|
| 86 | from target import AUTHOR, HOST, BOOTSTRAP_PATCHNAME, \ |
|---|
| 87 | BOOTSTRAP_CHANGELOG |
|---|
| 88 | |
|---|
| 89 | now = datetime.now() |
|---|
| 90 | self._initializeWorkingDir(root, repository, module, subdir) |
|---|
| 91 | self._commit(root, now, '%s@%s' % (AUTHOR, HOST), |
|---|
| 92 | BOOTSTRAP_PATCHNAME % module, |
|---|
| 93 | BOOTSTRAP_CHANGELOG % locals(), |
|---|
| 94 | entries=[subdir, '%s/...' % subdir]) |
|---|
| 95 | |
|---|
| 96 | def _initializeWorkingDir(self, root, repository, module, subdir, addentry=None): |
|---|
| 97 | """ |
|---|
| 98 | Execute `cdv init`. |
|---|
| 99 | """ |
|---|
| 100 | |
|---|
| 101 | from os import getenv |
|---|
| 102 | from os.path import join |
|---|
| 103 | |
|---|
| 104 | c = SystemCommand(working_dir=root, command="cdv init") |
|---|
| 105 | c(output=True) |
|---|
| 106 | |
|---|
| 107 | if c.exit_status: |
|---|
| 108 | raise TargetInitializationFailure( |
|---|
| 109 | "'cdv init' returned status %s" % c.exit_status) |
|---|
| 110 | |
|---|
| 111 | c = SystemCommand(working_dir=root, command="cdv set user %(user)s") |
|---|
| 112 | c(user=getenv('CDV_USER') or getenv('LOGNAME')) |
|---|
| 113 | |
|---|
| 114 | SyncronizableTargetWorkingDir._initializeWorkingDir(self, root, |
|---|
| 115 | repository, module, |
|---|
| 116 | subdir, CdvAdd) |
|---|