← Back to team overview

phatch-dev team mailing list archive

[Bug 382763] Re: Phatch doesn't match FreeDesktop folder specs

 

$ bzr diff
=== modified file 'phatch/core/api.py'
--- phatch/core/api.py	2009-05-22 02:52:50 +0000
+++ phatch/core/api.py	2009-06-03 02:46:55 +0000
@@ -28,6 +28,7 @@
 from message import send
 from settings import create_settings
 from unicoding import ensure_unicode, exception_to_unicode, ENCODING
+from formField import ensure_path
 
 #---classes
     
@@ -68,18 +69,19 @@
     
 #---init/exit
 def init():
-    verify_app_user_path()
+    verify_app_user_paths()
     import_actions()
     
 def exit():
     pass
         
 
-def verify_app_user_path():
-    for path in [ct.APP_USER_PATH,ct.APP_USER_PATH,ct.USER_ACTIONLISTS_PATH,
-            ct.USER_ACTIONS_PATH,ct.USER_MASKS_PATH,ct.USER_WATERMARKS_PATH]:
-        if not os.path.exists(path):
-            os.mkdir(path)
+def verify_app_user_paths():
+    for path in [ct.USER_DATA_PATH, ct.USER_CONFIG_PATH,
+            ct.USER_CACHE_PATH, ct.USER_ACTIONLISTS_PATH,
+            ct.USER_ACTIONS_PATH, ct.USER_BIN_PATH, ct.USER_MASKS_PATH,
+            ct.USER_HIGHLIGHTS_PATH, ct.USER_WATERMARKS_PATH]:
+        ensure_path(path)
 
 #---various
 def title(f):
@@ -89,7 +91,7 @@
 def init_error_log_file():
     global ERROR_LOG_FILE, ERROR_LOG_COUNTER
     ERROR_LOG_COUNTER   = 0
-    ERROR_LOG_FILE      = codecs.open(ct.ERROR_LOG_PATH, 'wb',
+    ERROR_LOG_FILE      = codecs.open(ct.USER_LOG_PATH, 'wb',
                             encoding=ENCODING,errors='replace')
 
 def log_error(message,filename,action=None,label='Error'):
@@ -407,12 +409,9 @@
     modules = \
         [import_module(os.path.basename(os.path.splitext(filename)[0]),
             'actions') 
-            for filename in glob.glob(os.path.join(ct.ACTIONS_PATH,'*.py'))]+\
+            for filename in glob.glob(os.path.join(ct.PHATCH_ACTIONS_PATH,'*.py'))]+\
         [import_module(os.path.basename(os.path.splitext(filename)[0])) for 
             filename in glob.glob(os.path.join(ct.USER_ACTIONS_PATH,'*.py'))]
-##    for filename in glob.glob(os.path.join(ct.ACTIONS_PATH,'*.py')):
-##        basename= os.path.basename(os.path.splitext(filename)[0])
-##        module  = import_module(basename,'actions')
     ACTIONS = {}
     for module in modules:
         try:
@@ -420,14 +419,14 @@
         except AttributeError:
             continue
         #register action
-        ACTIONS[cl.label]   = cl
+        ACTIONS[cl.label]       = cl
     #ACTION_LABELS
-    ACTION_LABELS                          = ACTIONS.keys()
+    ACTION_LABELS               = ACTIONS.keys()
     ACTION_LABELS.sort()
     #ACTION_FIELDS
-    ACTION_FIELDS = {}
+    ACTION_FIELDS               = {}
     for label in ACTIONS:
-        ACTION_FIELDS[label]  = ACTIONS[label]()._fields
+        ACTION_FIELDS[label]    = ACTIONS[label]()._fields
 
 def save_actionlist(filename,data):
     """data = {'actions':...}"""

=== modified file 'phatch/core/config.py'
--- phatch/core/config.py	2009-05-28 12:36:21 +0000
+++ phatch/core/config.py	2009-06-03 02:47:07 +0000
@@ -24,13 +24,31 @@
     USER_PATH   = USER_PATH.decode(sys.getfilesystemencoding())
 except:
     pass
-APP_USER_PATH           = os.path.join(USER_PATH,'.phatch')
-USER_ACTIONS_PATH       = os.path.join(APP_USER_PATH,'actions')
-USER_BIN_PATH           = os.path.join(APP_USER_PATH,'bin')
-USER_FONTS_PATH         = os.path.join(APP_USER_PATH,'fonts')
-USER_MASKS_PATH         = os.path.join(APP_USER_PATH,'masks')
-USER_HIGHLIGHTS_PATH    = os.path.join(APP_USER_PATH,'highlights')
-USER_WATERMARKS_PATH    = os.path.join(APP_USER_PATH,'watermarks')
+
+def env(var,*paths):
+    paths   = (USER_PATH,)+paths
+    return os.environ.get(var,os.path.join(*paths))
+
+if sys.platform.startswith('linux'):
+    USER_DATA_PATH  = env('XDG_DATA_HOME', 
+                            USER_PATH,'.local','share','phatch')
+    USER_CONFIG_PATH= env('XDG_CONFIG_HOME','.config','phatch')
+    USER_CACHE_PATH = env('XDG_CACHE_HOME','.cache','phatch')
+else:
+    #TODO: what would be the best user path for these platforms?
+    USER_DATA_PATH  = USER_CONFIG_PATH = USER_CACHE_PATH =\
+                            os.path.join(USER_PATH,'phatch')
+    
+USER_ACTIONS_PATH       = os.path.join(USER_DATA_PATH,'actions')
+USER_ACTIONLISTS_PATH   = os.path.join(USER_DATA_PATH,'actionlists')
+USER_BIN_PATH           = os.path.join(USER_DATA_PATH,'bin')
+USER_FONTS_PATH         = os.path.join(USER_CACHE_PATH,'fonts')
+USER_LOG_PATH           = os.path.join(USER_CACHE_PATH,'log')
+USER_MASKS_PATH         = os.path.join(USER_DATA_PATH,'masks')
+USER_HIGHLIGHTS_PATH    = os.path.join(USER_DATA_PATH,'highlights')
+USER_PREVIEW_PATH       = os.path.join(USER_CACHE_PATH,'preview')
+USER_SETTINGS_PATH      = os.path.join(USER_CONFIG_PATH,'settings.cPickle')
+USER_WATERMARKS_PATH    = os.path.join(USER_DATA_PATH,'watermarks')
 
 def check_config_paths(config_paths):
     global SYSTEM_INSTALL
@@ -41,7 +59,8 @@
         return config_paths
     SYSTEM_INSTALL      = True
     PHATCH_SHARE_PATH   = os.path.join(sys.prefix, "share") #also for win?
-    PHATCH_FONTS_PATH   = os.path.join(PHATCH_SHARE_PATH,"phatch","fonts")
+    PHATCH_FONTS_PATH   = os.path.join(PHATCH_SHARE_PATH,
+                            "phatch","fonts")
 
     if sys.platform.startswith('win'):
         sys.stderr.write(
@@ -51,21 +70,29 @@
         sys.exit()
     else:
         return {
-            "PHATCH_IMAGE_PATH" : os.path.join(PHATCH_SHARE_PATH,"phatch","images"),
-            "PHATCH_LOCALE_PATH": os.path.join(PHATCH_SHARE_PATH,"locale"),
-            "PHATCH_DOCS_PATH"  : os.path.join(PHATCH_SHARE_PATH,"phatch","docs"),
+            "PHATCH_IMAGE_PATH" : os.path.join(PHATCH_SHARE_PATH,
+                                    "phatch","images"),
+            "PHATCH_LOCALE_PATH": os.path.join(PHATCH_SHARE_PATH,
+                                    "locale"),
+            "PHATCH_DOCS_PATH"  : os.path.join(PHATCH_SHARE_PATH,
+                                    "phatch","docs"),
             "PHATCH_FONTS_PATH" : PHATCH_FONTS_PATH,
-            "PHATCH_ACTIONLISTS_PATH": os.path.join(PHATCH_SHARE_PATH,"phatch","actionlists"),
+            "PHATCH_ACTIONLISTS_PATH": os.path.join(PHATCH_SHARE_PATH,
+                                    "phatch","actionlists"),
         }
         
 def add_user_paths(config_paths):
-    config_paths["USER_PATH"]           = USER_PATH
-    config_paths["APP_USER_PATH"]       = APP_USER_PATH
-    config_paths["USER_ACTIONS_PATH"]   = USER_ACTIONS_PATH
-    config_paths["USER_FONTS_PATH"]     = USER_FONTS_PATH
-    config_paths["USER_MASKS_PATH"]     = USER_MASKS_PATH
-    config_paths["USER_HIGHLIGHTS_PATH"]= USER_HIGHLIGHTS_PATH
-    config_paths["USER_WATERMARKS_PATH"]= USER_WATERMARKS_PATH
+    config_paths.update({
+        "USER_PATH"             : USER_PATH,
+        "USER_ACTIONS_PATH"     : USER_ACTIONS_PATH,
+        "USER_BIN_PATH"         : USER_BIN_PATH,
+        "USER_FONTS_PATH"       : USER_FONTS_PATH,
+        "USER_MASKS_PATH"       : USER_MASKS_PATH,
+        "USER_HIGHLIGHTS_PATH"  : USER_HIGHLIGHTS_PATH,
+        "USER_PREVIEW_PATH"     : USER_PREVIEW_PATH,
+        "USER_SETTINGS_PATH"    : USER_SETTINGS_PATH,
+        "USER_WATERMARKS_PATH"  : USER_WATERMARKS_PATH,
+    })
 
 def fix_python_path(phatch_python_path=None):
     if not phatch_python_path:

=== modified file 'phatch/core/ct.py'
--- phatch/core/ct.py	2009-04-14 22:29:45 +0000
+++ phatch/core/ct.py	2009-06-03 02:37:51 +0000
@@ -18,8 +18,10 @@
 from data import license
 from data.info import INFO
 from translation import _t
-from config import USER_PATH, APP_USER_PATH, USER_ACTIONS_PATH,\
-    USER_MASKS_PATH, USER_WATERMARKS_PATH
+from config import USER_PATH, USER_DATA_PATH, USER_CONFIG_PATH,\
+    USER_CACHE_PATH, USER_ACTIONLISTS_PATH, USER_ACTIONS_PATH,\
+    USER_BIN_PATH, USER_HIGHLIGHTS_PATH, USER_LOG_PATH,\
+    USER_MASKS_PATH, USER_SETTINGS_PATH, USER_WATERMARKS_PATH
 
 #---description
 DESCRIPTION             = _('Photo Batch Processor')
@@ -62,15 +64,10 @@
     FILE    = sys.argv[0]
 else:
     FILE    = __file__
-PATH            = os.path.dirname(os.path.dirname(FILE))
+PATH                = os.path.dirname(os.path.dirname(FILE))
+PHATCH_ACTIONS_PATH = os.path.join(PATH,'actions')
 
-PATH_DELIMITER  = ';'
-ACTIONS_PATH    = os.path.join(PATH,'actions')
-USER_ACTIONLISTS_PATH   = os.path.join(APP_USER_PATH,'actionlists')
-USER_FONTS_PATH         = os.path.join(APP_USER_PATH,'fonts')
-SETTINGS_PATH           = os.path.join(APP_USER_PATH,'settings.cPickle')
-ERROR_LOG_PATH          = os.path.join(APP_USER_PATH,'error_log.txt')
-PREVIEW_PATH            = os.path.join(APP_USER_PATH,'preview')
+PATH_DELIMITER          = ';'
 
 LABEL_PHATCH_ACTIONLIST = '%s %s %%s...'%(INFO['name'],_('with'))
 LABEL_PHATCH_RECENT     = _('%s Recent')%INFO['name']

=== modified file 'phatch/pyWx/dialogs.py'
--- phatch/pyWx/dialogs.py	2009-05-21 03:04:27 +0000
+++ phatch/pyWx/dialogs.py	2009-06-03 02:42:17 +0000
@@ -351,9 +351,9 @@
         
     def OnViewSource(self,event):
         import actions
-        action      = self.actions[self.list.GetSelection()]
+        action      = self.actions[self.GetSelection()]
         module      = action.__module__.split('.')[-1]
-        filename    = os.path.join(ct.ACTIONS_PATH,'%s.py'%module)
+        filename    = os.path.join(ct.PHATCH_ACTIONS_PATH,'%s.py'%module)
         message     = open(filename).read()
         dir, base   = os.path.split(filename)
         send.frame_show_scrolled_message(message,'%s - %s'%(base,dir),
@@ -506,4 +506,4 @@
     app.MainLoop()
     
 if __name__ == '__main__':
-    test()
\ No newline at end of file
+    test()

=== modified file 'phatch/pyWx/gui.py'
--- phatch/pyWx/gui.py	2009-05-29 02:54:18 +0000
+++ phatch/pyWx/gui.py	2009-06-03 02:40:22 +0000
@@ -492,15 +492,15 @@
         frame.Show()
         
     def on_menu_tools_show_log(self,event):
-        if os.path.exists(ct.ERROR_LOG_PATH):
-            log_file    = open(ct.ERROR_LOG_PATH)
+        if os.path.exists(ct.USER_LOG_PATH):
+            log_file    = open(ct.USER_LOG_PATH)
             msg         = log_file.read().strip()
             log_file.close()
             if not msg:
                 msg     = _('Hooray, no issues!')
         else:
             msg         = _ ('Nothing has been logged yet.')
-        self.show_scrolled_message(msg,'%s - %s'%(_('Log'),ct.ERROR_LOG_PATH))
+        self.show_scrolled_message(msg,'%s - %s'%(_('Log'),ct.USER_LOG_PATH))
         
     def on_menu_tools_python_shell(self,event):
         import shell
@@ -542,7 +542,7 @@
             '',
             _('You only need to know PIL to write a plugin for Phatch,')+' ',
             _('as Phatch will generate the user interface automatically.'),
-            _('Study the action plugins in:')+' '+ct.ACTIONS_PATH,
+            _('Study the action plugins in:')+' '+ct.PHATCH_ACTIONS_PATH,
             '',
             _('If you want to contribute a plugin for Phatch,')+' '+\
             "%s: %s."%(_('please email'),ct.CONTACT)
@@ -861,14 +861,14 @@
         cli             = {}
         for key in ['no_save']:
             cli[key] = settings[key]
-        if os.path.exists(ct.SETTINGS_PATH):
-            f               = open(ct.SETTINGS_PATH,'rb')
+        if os.path.exists(ct.USER_SETTINGS_PATH):
+            f               = open(ct.USER_SETTINGS_PATH,'rb')
             self.settings.update(cPickle.load(f))
             f.close()
         self.settings.update(cli)
             
     def _saveSettings(self):
-        f   = open(ct.SETTINGS_PATH,'wb')
+        f   = open(ct.USER_SETTINGS_PATH,'wb')
         settings    = self.settings.copy()
         cPickle.dump(self.settings,f)
         f.close()

$ bzr commit -m "follow freedesktop folder specifications"
Committing to: /home/stani/sync/python/phatch/trunk/                           
modified phatch/core/api.py                                                    
modified phatch/core/config.py
modified phatch/core/ct.py
modified phatch/pyWx/dialogs.py
modified phatch/pyWx/gui.py
Committed revision 625.  

** Changed in: phatch
       Status: In Progress => Fix Committed

-- 
Phatch doesn't match FreeDesktop folder specs
https://bugs.launchpad.net/bugs/382763
You received this bug notification because you are a member of Phatch
Developers, which is subscribed to Phatch.

Status in Phatch = Photo & Batch!: Fix Committed

Bug description:
Phatch places its configuration files in
/home/.phatch directory which doesn't match FreeDesktop directories specs :

The default for $XDG_CONFIG_HOME is $HOME/.config, the default for
$XDG_DATA_HOME is $HOME/.local/share. So all applications should look for
those environment variables and use those default values if the variables
are not set.

This is quite important since it's not possible to easily backup config
& data files if these files are not stored at the right place

See http://www.freedesktop.org/wiki/Specifications/basedir-spec
See also
http://ploum.frimouvy.org/?184-cleaning-user-preferences-keeping-user-data
(main post and comment#8)



References