Permalink
Browse files

Deprecate applib.base.Locations and applib.locations in favour 'appdi…

…rs'. closes #1
  • Loading branch information...
1 parent 51a680a commit b6248b9a147e9eb9ad07b08f327e1b431551c878 @srid srid committed Sep 1, 2010
Showing with 15 additions and 258 deletions.
  1. +1 −0 NEWS.txt
  2. +9 −35 applib/base.py
  3. +2 −219 applib/location.py
  4. +2 −0 setup.cfg
  5. +1 −4 setup.py
View
@@ -6,6 +6,7 @@ News
*Release date: ??-2010*
+- #1: Deprecate applib.base.Locations and applib.locations in favour 'appdirs'
- #3: sh.unpack now ensures single top-level directory
- #4: Stop using `unicode` (py3k); applib now depends on the `six` package
View
@@ -4,6 +4,8 @@
from os.path import abspath, join, expanduser
import logging
+from appdirs import AppDirs
+
from applib import location, log
from applib.log import LogawareCmdln as Cmdln
@@ -32,7 +34,8 @@ def __init__(self, name, company, compatibility_version=None):
self.name = name
self.company = company
self.compatibility_version = compatibility_version
- self.locations = Locations(self)
+ self.locations = AppDirs2(
+ name, company, compatibility_version, roaming=False)
def run(self, cmdln_class):
"""Run the application using the given cmdln processor.
@@ -45,43 +48,14 @@ def run(self, cmdln_class):
cmdln_class(install_console=True).main()
-class Locations(object):
- """A object holding the locations that are generic to an application.
-
- The following locations are available:
-
- - user_data_dir: Directory to store the user's settings
- - site_data_dir: Directory to store global application settings
- - user_cache_dir: Directory to keep temperory/cache files
- - log_file_path: Location of the application log file
- """
-
- def __init__(self, app):
- self.app = app
-
- @property
- def user_data_dir(self):
- return location.user_data_dir(
- self.app.name, self.app.company, self.app.compatibility_version)
-
- @property
- def site_data_dir(self):
- return location.site_data_dir(
- self.app.name, self.app.company, self.app.compatibility_version)
-
- @property
- def user_cache_dir(self):
- return location.user_cache_dir(
- self.app.name, self.app.company, self.app.compatibility_version)
-
+class AppDirs2(AppDirs):
@property
def log_file_path(self):
- if sys.platform.startswith('win'):
- return join(self.user_cache_dir, self.app.name + '.log')
- elif sys.platform.startswith('darwin'):
- return join(expanduser('~/Library/Logs'), self.app.name + '.log')
+ if sys.platform in ('win32', 'darwin'):
+ name = self.appname + '.log'
else:
- return join(expanduser('~'), '.'+self.app.name.lower() + '.log')
+ name = self.appname.lower() + '.log'
+ return join(self.log_dir, name)
if __name__ == '__main__':
View
@@ -1,223 +1,6 @@
-#!/usr/bin/env python
-# Copyright (c) 2005-2008 ActiveState Software Inc.
-# License: MIT
-
-"""This module includes some method for determining application-specific dirs.
-
-Utility Functions:
- user_data_dir(...) path to user-specific app data dir
- site_data_dir(...) path to all users shared app data dir
- user_cache_dir(...) path to user-specific app cache dir
-"""
-# Dev Notes:
-# - MSDN on where to store app data files:
-# http://support.microsoft.com/default.aspx?scid=kb;en-us;310294#XSLTH3194121123120121120120
-#
-#TODO:
-# - Add cross-platform versions of other abstracted dir locations, like
-# a prefs dir, something like bundle/Contents/SharedSupport
-# on OS X, etc.
-# http://developer.apple.com/documentation/MacOSX/Conceptual/BPRuntimeConfig/Concepts/UserPreferences.html
-# http://developer.apple.com/documentation/MacOSX/Conceptual/BPFileSystem/index.html
-# http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/enums/csidl.asp
-
-__author__ = "Trent Mick"
-
-
-import sys
-import os
-
-from six.strdata import u
-
-class Error(Exception):
- pass
-
-
-
-def user_data_dir(appname, owner=None, version=None):
- r"""Return full path to the user-specific data dir for this application.
-
- "appname" is the name of application.
- "owner" (only required and used on Windows) is the name of the
- owner or distributing body for this application. Typically
- it is the owning company name.
- "version" is an optional version path element to append to the
- path. You might want to use this if you want multiple versions
- of your app to be able to run independently. If used, this
- would typically be "<major>.<minor>".
-
- Typical user data directories are:
- Win XP: C:\Documents and Settings\USER\Application Data\<owner>\<appname>
- Mac OS X: ~/Library/Application Support/<appname>
- Unix: ~/.<lowercased-appname>
-
- For Unix there is no *real* standard here. For example, Firefox uses:
- "~/.mozilla/firefox" which is a "~/.<owner>/<appname>"-type scheme.
- """
- if sys.platform.startswith("win"):
- if owner is None:
- raise Error("must specify 'owner' on Windows")
- path = os.path.join(_get_win_folder("CSIDL_APPDATA"),
- owner, appname)
- elif sys.platform == 'darwin':
- if os.uname()[-1] == 'i386':
- #XXX Folder.FSFindFolder() fails with error -43 on x86. See 42669.
- basepath = os.path.expanduser('~/Library/Application Support')
- else:
- from Carbon import Folder, Folders
- path = Folder.FSFindFolder(Folders.kUserDomain,
- Folders.kApplicationSupportFolderType,
- Folders.kDontCreateFolder)
- basepath = path.FSRefMakePath()
- path = os.path.join(basepath, appname)
- else:
- path = os.path.expanduser("~/." + appname.lower())
- if version:
- path = os.path.join(path, version)
- return path
-
-
-def site_data_dir(appname, owner=None, version=None):
- """Return full path to the user-shared data dir for this application.
-
- "appname" is the name of application.
- "owner" (only required and used on Windows) is the name of the
- owner or distributing body for this application. Typically
- it is the owning company name.
- "version" is an optional version path element to append to the
- path. You might want to use this if you want multiple versions
- of your app to be able to run independently. If used, this
- would typically be "<major>.<minor>".
-
- Typical user data directories are:
- Win XP: C:\Documents and Settings\All Users\Application Data\<owner>\<appname>
- Mac OS X: /Library/Application Support/<appname>
- Unix: /etc/<lowercased-appname>
- """
- if sys.platform.startswith("win"):
- if owner is None:
- raise Error("must specify 'owner' on Windows")
- path = os.path.join(_get_win_folder("CSIDL_COMMON_APPDATA"),
- owner, appname)
- elif sys.platform == 'darwin':
- if os.uname()[-1] == 'i386':
- #XXX Folder.FSFindFolder() fails with error -43 on x86. See 42669.
- basepath = os.path.expanduser('~/Library/Application Support')
- else:
- from Carbon import Folder, Folders
- path = Folder.FSFindFolder(Folders.kLocalDomain,
- Folders.kApplicationSupportFolderType,
- Folders.kDontCreateFolder)
- basepath = os.path.join(path.FSRefMakePath(), appname)
- path = os.path.join(basepath, appname)
- else:
- path = "/etc/"+appname.lower()
- if version:
- path = os.path.join(path, version)
- return path
-
-
-def user_cache_dir(appname, owner=None, version=None):
- r"""Return full path to the user-specific cache dir for this application.
-
- "appname" is the name of application.
- "owner" (only required and used on Windows) is the name of the
- owner or distributing body for this application. Typically
- it is the owning company name.
- "version" is an optional version path element to append to the
- path. You might want to use this if you want multiple versions
- of your app to be able to run independently. If used, this
- would typically be "<major>.<minor>".
-
- Typical user data directories are:
- Win XP: C:\Documents and Settings\USER\Local Settings\Application Data\<owner>\<appname>
- Mac OS X: ~/Library/Caches/<appname>
- Unix: ~/.<lowercased-appname>/caches
-
- For Unix there is no *real* standard here. Note that we are returning
- the *same dir as the user_data_dir()* for Unix. Use accordingly.
- """
- if sys.platform.startswith("win"):
- if owner is None:
- raise Error("must specify 'owner' on Windows")
- path = os.path.join(_get_win_folder("CSIDL_LOCAL_APPDATA"),
- owner, appname)
- elif sys.platform == 'darwin':
- if os.uname()[-1] == 'i386':
- #XXX Folder.FSFindFolder() fails with error -43 on x86. See 42669.
- basepath = os.path.expanduser('~/Library/Caches')
- else:
- from Carbon import Folder, Folders
- path = Folder.FSFindFolder(Folders.kUserDomain,
- Folders.kCachedDataFolderType,
- Folders.kDontCreateFolder)
- basepath = path.FSRefMakePath()
- path = os.path.join(basepath, appname)
- else:
- path = os.path.expanduser("~/.%s/caches" % appname.lower())
- if version:
- path = os.path.join(path, version)
- return path
-
-
-
-
-#---- internal support stuff
-
-def _get_win_folder_from_registry(csidl_name):
- """This is a fallback technique at best. I'm not sure if using the
- registry for this guarantees us the correct answer for all CSIDL_*
- names.
- """
- from six.moves import winreg
-
- shell_folder_name = {
- "CSIDL_APPDATA": "AppData",
- "CSIDL_COMMON_APPDATA": "Common AppData",
- "CSIDL_LOCAL_APPDATA": "Local AppData",
- }[csidl_name]
-
- key = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
- r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders")
- dir, type = winreg.QueryValueEx(key, shell_folder_name)
- return dir
-
-def _get_win_folder_with_pywin32(csidl_name):
- from win32com.shell import shellcon, shell
- dir = shell.SHGetFolderPath(0, getattr(shellcon, csidl_name), 0, 0)
- # Try to make this a unicode path because SHGetFolderPath does
- # not return unicode strings when there is unicode data in the
- # path.
- try:
- dir = u(dir)
- except UnicodeError:
- pass
- return dir
-
-def _get_win_folder_with_ctypes(csidl_name):
- import ctypes
-
- csidl_const = {
- "CSIDL_APPDATA": 26,
- "CSIDL_COMMON_APPDATA": 35,
- "CSIDL_LOCAL_APPDATA": 28,
- }[csidl_name]
-
- buf = ctypes.create_unicode_buffer(1024)
- ctypes.windll.shell32.SHGetFolderPathW(None, csidl_const, None, 0, buf)
- return buf.value
-
-if sys.platform == "win32":
- try:
- import win32com.shell
- _get_win_folder = _get_win_folder_with_pywin32
- except ImportError:
- try:
- import ctypes
- _get_win_folder = _get_win_folder_with_ctypes
- except ImportError:
- _get_win_folder = _get_win_folder_from_registry
+# This module is deprecated
+from appdirs import *
#---- self test code
View
@@ -0,0 +1,2 @@
+[easy_install]
+find_links = http://github.com/srid/appdirs/tarball/master#egg=appdirs
View
@@ -37,9 +37,6 @@
include_package_data=True,
zip_safe=True,
install_requires=[
- 'six'
+ 'appdirs',
],
- entry_points="""
- # -*- Entry points: -*-
- """,
)

0 comments on commit b6248b9

Please sign in to comment.