ActiveState/appdirs — pull request #41 by cpburnz (2014-04-27 04:20:42+00:00)
Title: Support Jython on Windows and Mac

The `*_dir()` methods do not work on Windows or Mac in Jython. In Jython, `sys.platform` is `javaX.Y.Z` which incorrectly causes the paths to treated as Unix/Posix paths. This pull request adds support for them.

NOTE: In order to support Jython in Windows, the user must include the [JNA](https://github.com/twall/jna) jars so that the win32 API can be accessed to query the directory paths.

I ran the following tests on Windows XP, Mac OSX, and Linux (Xubuntu) with both Python and Jython to verify the changes worked and did not inadvertently break anything.

Python: CPython 2.6.1
Platform: Darwin-10.8.0-i386-64bit
Appdirs: 1.2.0

>>> from appdirs import *
>>> dirs = AppDirs('SuperApp', 'Acme')
>>> dirs.site_data_dir
'/Library/Application Support/SuperApp'
>>> dirs.user_data_dir
'/Users/calebburns/Library/Application Support/SuperApp'
>>> dirs.user_cache_dir
'/Users/calebburns/Library/Caches/SuperApp'
>>> dirs.user_log_dir
'/Users/calebburns/Library/Logs/SuperApp'

Python: CPython 2.6.1
Platform: Darwin-10.8.0-i386-64bit
Appdirs: 1.3.0 (modified)

>>> from appdirs import *
>>> dirs = AppDirs('SuperApp', 'Acme')
>>> dirs.site_data_dir
'/Library/Application Support/SuperApp'
>>> dirs.user_data_dir
'/Users/calebburns/Library/Application Support/SuperApp'
>>> dirs.user_cache_dir
'/Users/calebburns/Library/Caches/SuperApp'
>>> dirs.user_log_dir
'/Users/calebburns/Library/Logs/SuperApp'

Python: Jython 2.7.0
Platform: Java-1.6.0_17-Java_HotSpot-TM-_64-Bit_Server_VM,_14.3-b01-101,_Apple_Inc.-on-Mac_OS_X-10.6.8-x86_64
Appdirs: 1.2.0

>>> from appdirs import *
>>> dirs = AppDirs('SuperApp', 'Acme')
>>> dirs.site_data_dir
'/etc/xdg/superapp'
>>> dirs.user_data_dir
'/Users/calebburns/.config/superapp'
>>> dirs.user_cache_dir
'/Users/calebburns/.cache/superapp'
>>> dirs.user_log_dir
'/Users/calebburns/.cache/superapp/log'

Python: Jython 2.7.0
Platform: Java-1.6.0_17-Java_HotSpot-TM-_64-Bit_Server_VM,_14.3-b01-101,_Apple_Inc.-on-Mac_OS_X-10.6.8-x86_64
Appdirs: 1.3.0 (modified)

>>> from appdirs import *
>>> dirs = AppDirs('SuperApp', 'Acme')
>>> dirs.site_data_dir
'/Library/Application Support/SuperApp'
>>> dirs.user_data_dir
'/Users/calebburns/Library/Application Support/SuperApp'
>>> dirs.user_cache_dir
'/Users/calebburns/Library/Caches/SuperApp'
>>> dirs.user_log_dir
'/Users/calebburns/Library/Logs/SuperApp'

Python: CPython 2.7.4
Platform: Windows-XP-5.1.2600-SP3
Appdirs: 1.3.0

>>> from appdirs import *
>>> dirs = AppDirs('SuperApp', 'Acme')
>>> dirs.site_data_dir
u'C:\\Documents and Settings\\All Users\\Application Data\\Acme\\SuperApp'
>>> dirs.user_data_dir
u'C:\\Documents and Settings\\Administrator\\Local Settings\\Application Data\\Acme\\SuperApp'
>>> dirs.user_cache_dir
u'C:\\Documents and Settings\\Administrator\\Local Settings\\Application Data\\Acme\\SuperApp\\Cache'
>>> dirs.user_log_dir
u'C:\\Documents and Settings\\Administrator\\Local Settings\\Application Data\\Acme\\SuperApp\\Logs'

Python: CPython 2.7.4
Platform: Windows-XP-5.1.2600-SP3
Appdirs: 1.3.0 (modified)

>>> from appdirs import *
>>> dirs = AppDirs('SuperApp', 'Acme')
>>> dirs.site_data_dir
u'C:\\Documents and Settings\\All Users\\Application Data\\Acme\\SuperApp'
>>> dirs.user_data_dir
u'C:\\Documents and Settings\\Administrator\\Local Settings\\Application Data\\Acme\\SuperApp'
>>> dirs.user_cache_dir
u'C:\\Documents and Settings\\Administrator\\Local Settings\\Application Data\\Acme\\SuperApp\\Cache'
>>> dirs.user_log_dir
u'C:\\Documents and Settings\\Administrator\\Local Settings\\Application Data\\Acme\\SuperApp\\Logs'

Python: Jython 2.7.0
Platform: Java-1.7.0_55-Java_HotSpot-TM-_Client_VM,_24.55-b03,_Oracle_Corporation-on-Windows_XP-5.1-x86
Appdirs: 1.3.0

>>> from appdirs import *
>>> dirs = AppDirs('SuperApp', 'Acme')
>>> dirs.site_data_dir
'/usr/local/share\\SuperApp'
>>> dirs.user_data_dir
'C:\\Documents and Settings\\Administrator/.local/share\\SuperApp'
>>> dirs.user_cache_dir
'C:\\Documents and Settings\\Administrator/.cache\\SuperApp'
>>> dirs.user_log_dir
'C:\\Documents and Settings\\Administrator/.cache\\SuperApp\\log'

Python: Jython 2.7.0
Platform: Java-1.7.0_55-Java_HotSpot-TM-_Client_VM,_24.55-b03,_Oracle_Corporation-on-Windows_XP-5.1-x86
Appdirs: 1.3.0 (modified)

>>> from appdirs import *
>>> dirs = AppDirs('SuperApp', 'Acme')
>>> dirs.site_data_dir
u'C:\\Documents and Settings\\All Users\\Application Data\\Acme\\SuperApp'
>>> dirs.user_data_dir
u'C:\\Documents and Settings\\Administrator\\Local Settings\\Application Data\\Acme\\SuperApp'
>>> dirs.user_cache_dir
u'C:\\Documents and Settings\\Administrator\\Local Settings\\Application Data\\Acme\\SuperApp\\Cache'
>>> dirs.user_log_dir
u'C:\\Documents and Settings\\Administrator\\Local Settings\\Application Data\\Acme\\SuperApp\\Logs'

Python: CPython 2.7.4
Platform: Linux-3.8.0-35-generic-x86_64-with-Ubuntu-13.04-raring
Appdirs: 1.3.0

>>> from appdirs import *
>>> dirs = AppDirs('SuperApp', 'Acme')
>>> dirs.site_data_dir
'/usr/share/xubuntu/SuperApp'
>>> dirs.user_data_dir
'/home/caleb/.local/share/SuperApp'
>>> dirs.user_cache_dir
'/home/caleb/.cache/SuperApp'
>>> dirs.user_log_dir
'/home/caleb/.cache/SuperApp/log'

Python: CPython 2.7.4
Platform: Linux-3.8.0-35-generic-x86_64-with-Ubuntu-13.04-raring
Appdirs: 1.3.0 (modified)

>>> from appdirs import *
>>> dirs = AppDirs('SuperApp', 'Acme')
>>> dirs.site_data_dir
'/usr/share/xubuntu/SuperApp'
>>> dirs.user_data_dir
'/home/caleb/.local/share/SuperApp'
>>> dirs.user_cache_dir
'/home/caleb/.cache/SuperApp'
>>> dirs.user_log_dir
'/home/caleb/.cache/SuperApp/log'

Python: Jython 2.7.0
Platform: Java-1.7.0_51-OpenJDK_64-Bit_Server_VM,_24.45-b08,_Oracle_Corporation-on-Linux-3.8.0-35-generic-amd64
Appdirs: 1.3.0

>>> from appdirs import *
>>> dirs = AppDirs('SuperApp', 'Acme')
>>> dirs.site_data_dir
'/usr/share/xubuntu/SuperApp'
>>> dirs.user_data_dir
'/home/caleb/.local/share/SuperApp'
>>> dirs.user_cache_dir
'/home/caleb/.cache/SuperApp'
>>> dirs.user_log_dir
'/home/caleb/.cache/SuperApp/log'

Python: Jython 2.7.0
Platform: Java-1.7.0_51-OpenJDK_64-Bit_Server_VM,_24.45-b08,_Oracle_Corporation-on-Linux-3.8.0-35-generic-amd64
Appdirs: 1.3.0 (modified)

>>> from appdirs import *
>>> dirs = AppDirs('SuperApp', 'Acme')
>>> dirs.site_data_dir
'/usr/share/xubuntu/SuperApp'
>>> dirs.user_data_dir
'/home/caleb/.local/share/SuperApp'
>>> dirs.user_cache_dir
'/home/caleb/.cache/SuperApp'
>>> dirs.user_log_dir
'/home/caleb/.cache/SuperApp/log'