| 1 | # -*- mode: python; coding: utf-8 -*- |
|---|
| 2 | # :Progetto: vcpx -- ArX stuff |
|---|
| 3 | # :Creato: ven 24 giu 2005 20:42:46 CEST |
|---|
| 4 | # :Autore: Lele Gaifax <lele@nautilus.homeip.net> |
|---|
| 5 | # :Licenza: GNU General Public License |
|---|
| 6 | # |
|---|
| 7 | # Modified 2005 by Walter Landry for ArX |
|---|
| 8 | |
|---|
| 9 | """ |
|---|
| 10 | This module implements the backends for ArX. |
|---|
| 11 | """ |
|---|
| 12 | |
|---|
| 13 | __docformat__ = 'reStructuredText' |
|---|
| 14 | |
|---|
| 15 | from shwrap import ExternalCommand, PIPE, ReopenableNamedTemporaryFile |
|---|
| 16 | from target import SyncronizableTargetWorkingDir, TargetInitializationFailure |
|---|
| 17 | |
|---|
| 18 | class ArxWorkingDir(SyncronizableTargetWorkingDir): |
|---|
| 19 | |
|---|
| 20 | ## SyncronizableTargetWorkingDir |
|---|
| 21 | |
|---|
| 22 | def _addPathnames(self, names): |
|---|
| 23 | """ |
|---|
| 24 | Add some new filesystem objects. |
|---|
| 25 | """ |
|---|
| 26 | |
|---|
| 27 | cmd = [self.repository.ARX_CMD, "add"] |
|---|
| 28 | ExternalCommand(cwd=self.basedir, command=cmd).execute(names) |
|---|
| 29 | |
|---|
| 30 | def _commit(self, date, author, patchname, changelog=None, entries=None): |
|---|
| 31 | """ |
|---|
| 32 | Commit the changeset. |
|---|
| 33 | """ |
|---|
| 34 | |
|---|
| 35 | from time import mktime |
|---|
| 36 | from sys import getdefaultencoding |
|---|
| 37 | |
|---|
| 38 | encoding = ExternalCommand.FORCE_ENCODING or getdefaultencoding() |
|---|
| 39 | |
|---|
| 40 | logmessage = "" |
|---|
| 41 | if patchname: |
|---|
| 42 | logmessage=patchname.encode(encoding) |
|---|
| 43 | if changelog: |
|---|
| 44 | if logmessage!="": |
|---|
| 45 | logmessage+="\n\n"+changelog.encode(encoding) |
|---|
| 46 | else: |
|---|
| 47 | logmessage=changelog.encode(encoding) |
|---|
| 48 | |
|---|
| 49 | if logmessage=="": |
|---|
| 50 | logmessage=" " |
|---|
| 51 | |
|---|
| 52 | cmd = [self.repository.ARX_CMD, "commit", "-s", logmessage, |
|---|
| 53 | "--author", author, |
|---|
| 54 | "--date", date.isoformat()] |
|---|
| 55 | c = ExternalCommand(cwd=self.basedir, command=cmd) |
|---|
| 56 | c.execute() |
|---|
| 57 | |
|---|
| 58 | def _removePathnames(self, names): |
|---|
| 59 | """ |
|---|
| 60 | Remove some filesystem object. |
|---|
| 61 | """ |
|---|
| 62 | |
|---|
| 63 | cmd = [self.repository.ARX_CMD, "rm"] |
|---|
| 64 | ExternalCommand(cwd=self.basedir, command=cmd).execute(names) |
|---|
| 65 | |
|---|
| 66 | def _renamePathname(self, oldname, newname): |
|---|
| 67 | """ |
|---|
| 68 | Rename a filesystem object. |
|---|
| 69 | """ |
|---|
| 70 | |
|---|
| 71 | cmd = [self.repository.ARX_CMD, "copy"] |
|---|
| 72 | rename = ExternalCommand(cwd=self.basedir, command=cmd) |
|---|
| 73 | rename.execute(oldname, newname) |
|---|
| 74 | |
|---|
| 75 | def _initializeWorkingDir(self): |
|---|
| 76 | """ |
|---|
| 77 | Setup the ArX working copy |
|---|
| 78 | |
|---|
| 79 | The user must setup a ArX working directory himself. Then |
|---|
| 80 | we simply use 'arx commit', without having to specify an archive |
|---|
| 81 | or branch. ArX looks up the archive and branch in it's _arx |
|---|
| 82 | directory. |
|---|
| 83 | """ |
|---|
| 84 | |
|---|
| 85 | from os.path import exists, join |
|---|
| 86 | from dircache import listdir |
|---|
| 87 | from dualwd import IGNORED_METADIRS |
|---|
| 88 | from os import walk |
|---|
| 89 | |
|---|
| 90 | if not exists(join(self.basedir, '_arx')): |
|---|
| 91 | raise TargetInitializationFailure("Please setup '%s' as an ArX working directory" % self.basedir) |
|---|
| 92 | |
|---|
| 93 | SyncronizableTargetWorkingDir._initializeWorkingDir(self) |
|---|