+from core.lib.desktop import DESKTOP_FOLDER, USER_FOLDER
+if DESKTOP_FOLDER == USER_FOLDER:
+ DESKTOP_FOLDER = os.path.expanduser('~/phatch')
+
+
JPG = ['jpg','jpeg','jpe']
PNG = ['png']
TYPE = '<%s>'%_t('type')
@@ -72,7 +77,17 @@
dpi = self.get_field('Resolution',info) #filename
if setting('create_missing_folders'):
- self.ensure_path(folder)
+ try:
+ self.ensure_path(folder)
+ except OSError, message:
+ base = os.path.basename(filename)
+ photo.log += 'Could not save "%s" in "%s":\n%s\n'\
+ %(base,folder,message)
+ photo.log += 'Will try to save in "%s" instead.\n'\
+ %DESKTOP_FOLDER
+ self.ensure_path(DESKTOP_FOLDER)
+ filename = os.path.join(DESKTOP_FOLDER,base)
+ #construct options options = {'dpi' : (dpi,dpi)}
if self.is_type(typ,PNG):
=== added file 'phatch/core/lib/desktop.py'
--- phatch/core/lib/desktop.py 1970-01-01 00:00:00 +0000
+++ phatch/core/lib/desktop.py 2009-05-25 16:10:46 +0000
@@ -0,0 +1,47 @@
+# Copyright (C) 2007-2008 www.stani.be
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see http://www.gnu.org/licenses/
+
+"""Cross platform library to locate the desktop folder."""
+
+import os
+import re
+import sys
+
+USER_FOLDER = os.path.expanduser('~')
+
+if sys.platform.startswith('win'):
+ # Windows
+ from win32com.shell import shell, shellcon
+ DESKTOP_FOLDER = shell.SHGetFolderPath(0, shellcon.CSIDL_DESKTOP,
+ None, 0)
+elif sys.platform.startswith('darwin'):
+ # Mac: verify this!
+ DESKTOP_FOLDER = os.path.expanduser('~/Desktop')
+else:
+ # Linux
+ user_dirs = os.path.expanduser('~/.config/user-dirs.dirs')
+ if os.path.exists(user_dirs):
+ DESKTOP_FOLDER = os.path.expanduser(
+ re.search('XDG_DESKTOP_DIR="(.*?)"',open(user_dirs).read())\
+ .group(1).replace('$HOME','~'))
+ else:
+ DESKTOP_FOLDER = os.path.expanduser('~/Desktop')
+ del user_dirs
+
+if not os.path.isdir(DESKTOP_FOLDER):
+ DESKTOP_FOLDER = USER_FOLDER
+
+if __name__ == '__main__':
+ sys.stdout.write('Your desktop is: %s\n'%DESKTOP_FOLDER)
$ bzr commit -m "save batched images on the desktop in case of a permission error"
Committing to: /home/stani/sync/python/phatch/trunk/
modified phatch/actions/save.py
added phatch/core/lib/desktop.py
Committed revision 587.
This has been fixed upstream in bzr. The new behaviour is that from now that in case of a permission error, images will be saved on desktop instead.
$ bzr diff actions/ save.py' actions/ save.py 2009-04-14 22:29:45 +0000 actions/ save.py 2009-05-25 16:38:11 +0000
=== modified file 'phatch/
--- phatch/
+++ phatch/
@@ -24,6 +24,11 @@
from core.translation import _t,new
from imtools import get_quality, get_size
+from core.lib.desktop import DESKTOP_FOLDER, USER_FOLDER expanduser( '~/phatch' ) 'jpeg', 'jpe'] field(' Resolution' ,info)
# filename 'create_ missing_ folders' ): path(folder) path(folder) basename( filename) folder, message) path(DESKTOP_ FOLDER) join(DESKTOP_ FOLDER, base)
# construct options
options = {'dpi' : (dpi,dpi)} type(typ, PNG):
+if DESKTOP_FOLDER == USER_FOLDER:
+ DESKTOP_FOLDER = os.path.
+
+
JPG = ['jpg',
PNG = ['png']
TYPE = '<%s>'%_t('type')
@@ -72,7 +77,17 @@
dpi = self.get_
if setting(
- self.ensure_
+ try:
+ self.ensure_
+ except OSError, message:
+ base = os.path.
+ photo.log += 'Could not save "%s" in "%s":\n%s\n'\
+ %(base,
+ photo.log += 'Will try to save in "%s" instead.\n'\
+ %DESKTOP_FOLDER
+ self.ensure_
+ filename = os.path.
+
if self.is_
=== added file 'phatch/ core/lib/ desktop. py' core/lib/ desktop. py 1970-01-01 00:00:00 +0000 core/lib/ desktop. py 2009-05-25 16:10:46 +0000 www.gnu. org/licenses/ expanduser( '~') startswith( 'win'): erPath( 0, shellcon. CSIDL_DESKTOP, startswith( 'darwin' ): expanduser( '~/Desktop' ) expanduser( '~/.config/ user-dirs. dirs') exists( user_dirs) : 'XDG_DESKTOP_ DIR="(. *?)"',open( user_dirs) .read() )\ 1).replace( '$HOME' ,'~')) expanduser( '~/Desktop' ) isdir(DESKTOP_ FOLDER) : write(' Your desktop is: %s\n'%DESKTOP_ FOLDER)
--- phatch/
+++ phatch/
@@ -0,0 +1,47 @@
+# Copyright (C) 2007-2008 www.stani.be
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see http://
+
+"""Cross platform library to locate the desktop folder."""
+
+import os
+import re
+import sys
+
+USER_FOLDER = os.path.
+
+if sys.platform.
+ # Windows
+ from win32com.shell import shell, shellcon
+ DESKTOP_FOLDER = shell.SHGetFold
+ None, 0)
+elif sys.platform.
+ # Mac: verify this!
+ DESKTOP_FOLDER = os.path.
+else:
+ # Linux
+ user_dirs = os.path.
+ if os.path.
+ DESKTOP_FOLDER = os.path.expanduser(
+ re.search(
+ .group(
+ else:
+ DESKTOP_FOLDER = os.path.
+ del user_dirs
+
+if not os.path.
+ DESKTOP_FOLDER = USER_FOLDER
+
+if __name__ == '__main__':
+ sys.stdout.
$ bzr commit -m "save batched images on the desktop in case of a permission error" sync/python/ phatch/ trunk/ actions/ save.py core/lib/ desktop. py
Committing to: /home/stani/
modified phatch/
added phatch/
Committed revision 587.