~ddormer/renamer/1125067-add-prepare-method

« back to all changes in this revision

Viewing changes to renamer/plugins/actions.py

  • Committer: Jonathan Jacobs
  • Date: 2010-10-24 17:41:36 UTC
  • mfrom: (83.2.23 undo-command)
  • Revision ID: korpse@slipgate.za.net-20101024174136-geqsnh247drgj5hu
Merge lp:~renamer-developers/renamer/undo-command.

Implement persistent history of Renamer actions and undoing them.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from renamer import logging, util
 
2
from renamer.plugin import RenamingAction
 
3
 
 
4
 
 
5
 
 
6
class MoveAction(RenamingAction):
 
7
    """
 
8
    File move action.
 
9
 
 
10
    If the source and destination are on different logical devices a
 
11
    copy-delete will be used, unless the C{'one-file-system'} option is
 
12
    specified.
 
13
    """
 
14
    name = 'move'
 
15
 
 
16
 
 
17
    def _move(self, src, dst, options):
 
18
        self.prepare(dst, options)
 
19
        logging.msg('Move: %s => %s' % (src.path, dst.path))
 
20
        util.rename(src, dst, oneFileSystem=options['one-file-system'])
 
21
 
 
22
 
 
23
    # IRenamingAction
 
24
 
 
25
    def do(self, options):
 
26
        self._move(self.src, self.dst, options)
 
27
 
 
28
 
 
29
    def undo(self, options):
 
30
        self._move(self.dst, self.src, options)
 
31
 
 
32
 
 
33
 
 
34
class SymlinkAction(RenamingAction):
 
35
    """
 
36
    Symlink action.
 
37
    """
 
38
    name = 'symlink'
 
39
 
 
40
 
 
41
    # IRenamingAction
 
42
 
 
43
    def do(self, options):
 
44
        self.prepare(self.dst, options)
 
45
        logging.msg('Symlink: %s => %s' % (self.src.path, self.dst.path))
 
46
        self.src.linkTo(self.dst)
 
47
 
 
48
 
 
49
    def undo(self, options):
 
50
        if self.dst.islink():
 
51
            logging.msg('Symlink: Removing %s' % (self.dst.path,))
 
52
            self.dst.remove()