~ubuntu-branches/debian/stretch/phatch/stretch

« back to all changes in this revision

Viewing changes to phatch/actions/rename.py

  • Committer: Package Import Robot
  • Author(s): Emilio Pozuelo Monfort, Stani M, Emilio Pozuelo Monfort
  • Date: 2010-03-12 14:04:02 UTC
  • mfrom: (1.1.11)
  • Revision ID: package-import@ubuntu.com-20100312140402-3fw7sgzusw2y365o
Tags: 0.2.7-1
[ Stani M ]
* Upstream bugfix release (Closes LP: #472978, #487435, #516763, #516858, 
  #525999, #526047, #526235, #526237, #526489, #529343, #529429, #525831, 
  #526237, #529544, #529605, #531375, #531705, #531728, #532346, #532356, 
  #532540, #532544, #533068, #534723, #534834, #534835, #535189, #535192,
  #536820)
* debian/control: Add python-nautilus to phatch-nautilus's Depends

[ Emilio Pozuelo Monfort ]
* debian/rules:
  - Adapt for the upstream changes.
* debian/copyright:
  - Updated for the new version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
# Embedded icon is designed by Igor Kekeljevic (http://www.admiror-ns.co.yu).
20
20
 
 
21
# Follows PEP8
 
22
 
21
23
from core import ct, models
22
24
from lib.reverse_translation import _t
23
25
 
24
26
#no need to lazily import these as they are always imported
25
 
import os, shutil
 
27
import os
 
28
import shutil
 
29
 
26
30
 
27
31
class Action(models.Action):
28
32
    """Defined variables: <filename> <type> <folder> <width> <height>"""
29
33
 
30
 
    label       = _t('Rename')
31
 
    author      = 'Stani'
32
 
    email       = 'spe.stani.be@gmail.com'
33
 
    version     = '0.1'
34
 
    tags        = [_t('file')]
35
 
    __doc__     = _t('Rename the original image')
36
 
    valid_last  = True
 
34
    label = _t('Rename')
 
35
    author = 'Stani'
 
36
    email = 'spe.stani.be@gmail.com'
 
37
    version = '0.1'
 
38
    tags = [_t('file')]
 
39
    __doc__ = _t('Rename the original image')
 
40
    valid_last = True
37
41
 
38
 
    def interface(self,fields):
39
 
        fields[_t('File Name')]    = self.FileNameField(choices=self.FILENAMES)
40
 
        fields[_t('In')]           = self.FolderField(self.DEFAULT_FOLDER,
 
42
    def interface(self, fields):
 
43
        fields[_t('File Name')] = self.FileNameField(choices=self.FILENAMES)
 
44
        fields[_t('In')] = self.FolderField(self.DEFAULT_FOLDER,
41
45
                                        choices=self.FOLDERS)
42
46
 
43
 
    def apply(self,photo,setting,cache):
 
47
    def apply(self, photo, setting, cache):
44
48
        #get info
45
 
        info                    = photo.info
 
49
        info = photo.info
46
50
        #get file values
47
 
        folder, filename, typ   = self.is_done_info(info)
48
 
        if setting('overwrite_existing_images') or not os.path.exists(filename):
 
51
        folder, filename, typ = self.is_done_info(info)
 
52
        if setting('overwrite_existing_images') \
 
53
                or not os.path.exists(filename):
49
54
            #ensure folder
50
55
            filename = self.ensure_path_or_desktop(folder, photo, filename)
51
56
            #do it
52
 
            os.rename(info['path'],filename)
 
57
            os.rename(info['path'], filename)
53
58
        return photo
54
59
 
55
 
    def is_done_info(self,info):
56
 
        folder      = self.get_field('In',info)
57
 
        filename    = self.get_field('File Name',info)
58
 
        typ         = info['type']
59
 
        return folder, os.path.join(folder,'%s.%s'%(filename,typ)), typ
 
60
    def is_done_info(self, info):
 
61
        folder = self.get_field('In', info)
 
62
        filename = self.get_field('File Name', info)
 
63
        typ = info['type']
 
64
        return folder, os.path.join(folder, '%s.%s' % (filename, typ)), typ
60
65
 
61
66
    def is_overwrite_existing_images_forced(self):
62
67
        """Force overwrite when using default values."""