-
-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
606483e
commit c47f209
Showing
17 changed files
with
249 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
App Filesystems | ||
=============== | ||
|
||
Filesystems for platform specific application directories. | ||
|
||
.. automodule:: fs.appfs | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
fs.mode | ||
======= | ||
|
||
.. automodule:: fs.mode | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
fs.tools | ||
======== | ||
|
||
.. automodule:: fs.tools | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
from __future__ import unicode_literals | ||
|
||
def make_repr(class_name, args): | ||
def make_repr(class_name, *args, **kwargs): | ||
"""Generate a repr string.""" | ||
arguments = [ | ||
"{!s}={!r}".format(name, value) | ||
for name, value, default in args | ||
arguments = [repr(arg) for arg in args] | ||
arguments.extend([ | ||
"{}={!r}".format(name, value) | ||
for name, (value, default) in kwargs.items() | ||
if value != default | ||
] | ||
]) | ||
return "{}({})".format(class_name, ', '.join(arguments)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
""" | ||
A collection of filesystems that map to application specific locations | ||
defined by the OS. | ||
These classes abstract away the different requirements for user data | ||
across platforms, which vary in their conventions. They are all | ||
subclasses of :class:`fs.osfs.OSFS`. | ||
""" | ||
# Thanks to authors of https://pypi.python.org/pypi/appdirs | ||
|
||
# see http://technet.microsoft.com/en-us/library/cc766489(WS.10).aspx | ||
|
||
from .osfs import OSFS | ||
from ._repr import make_repr | ||
from appdirs import AppDirs | ||
|
||
__all__ = ['UserDataFS', | ||
'UserConfigFS', | ||
'SiteDataFS', | ||
'SiteConfigFS', | ||
'UserCacheFS', | ||
'UserLogFS'] | ||
|
||
|
||
class _AppFS(OSFS): | ||
""" | ||
Abstract base class for an app FS. | ||
""" | ||
app_dir = None | ||
|
||
def __init__(self, | ||
appname, | ||
author=None, | ||
version=None, | ||
roaming=False, | ||
create=True): | ||
self.app_dirs = AppDirs(appname, author, version, roaming) | ||
self.create = create | ||
super(_AppFS, self).__init__( | ||
getattr(self.app_dirs, self.app_dir), | ||
create=create | ||
) | ||
|
||
def __repr__(self): | ||
return make_repr( | ||
self.__class__.__name__, | ||
self.app_dirs.appname, | ||
author=(self.app_dirs.appauthor, None), | ||
version=(self.app_dirs.version, None), | ||
roaming=(self.app_dirs.roaming, False), | ||
create=(self.create, True) | ||
) | ||
|
||
def __str__(self): | ||
return "<{} '{}'>".format( | ||
self.__class__.__name__.lower(), | ||
self.app_dirs.appname | ||
) | ||
|
||
class UserDataFS(_AppFS): | ||
""" | ||
A filesystem for per-user application data. | ||
:param str appname: The name of the application. | ||
:param str author: The name of the author (used on Windows). | ||
:param str version: Optional version string, if a unique location | ||
per version of the application is required. | ||
:param bool roaming: If ``True``, use a *roaming* profile on | ||
Windows. | ||
:param bool create: If ``True`` (the default) the directory will | ||
be created if it does not exist. | ||
""" | ||
app_dir = 'user_data_dir' | ||
|
||
|
||
class UserConfigFS(_AppFS): | ||
""" | ||
A filesystem for per-user config data. | ||
:param str appname: The name of the application. | ||
:param str author: The name of the author (used on Windows). | ||
:param str version: Optional version string, if a unique location | ||
per version of the application is required. | ||
:param bool roaming: If ``True``, use a *roaming* profile on | ||
Windows, see http://technet.microsoft.com/en- | ||
us/library/cc766489(WS.10).aspx | ||
:param bool create: If ``True`` (the default) the directory will | ||
be created if it does not exist. | ||
""" | ||
app_dir = 'user_config_dir' | ||
|
||
|
||
class UserCacheFS(_AppFS): | ||
""" | ||
A filesystem for per-user application cache data. | ||
:param str appname: The name of the application. | ||
:param str author: The name of the author (used on Windows). | ||
:param str version: Optional version string, if a unique location | ||
per version of the application is required. | ||
:param bool roaming: If ``True``, use a *roaming* profile on | ||
Windows. | ||
:param bool create: If ``True`` (the default) the directory will | ||
be created if it does not exist. | ||
""" | ||
app_dir = 'user_cache_dir' | ||
|
||
|
||
class SiteDataFS(_AppFS): | ||
""" | ||
A filesystem for application site data. | ||
:param str appname: The name of the application. | ||
:param str author: The name of the author (used on Windows). | ||
:param str version: Optional version string, if a unique location | ||
per version of the application is required. | ||
:param bool roaming: If ``True``, use a *roaming* profile on | ||
Windows. | ||
:param bool create: If ``True`` (the default) the directory will | ||
be created if it does not exist. | ||
""" | ||
app_dir = 'site_data_dir' | ||
|
||
|
||
class SiteConfigFS(_AppFS): | ||
""" | ||
A filesystem for application config data. | ||
:param str appname: The name of the application. | ||
:param str author: The name of the author (used on Windows). | ||
:param str version: Optional version string, if a unique location | ||
per version of the application is required. | ||
:param bool roaming: If ``True``, use a *roaming* profile on | ||
Windows. | ||
:param bool create: If ``True`` (the default) the directory will | ||
be created if it does not exist. | ||
""" | ||
app_dir = 'site_config_dir' | ||
|
||
|
||
class UserLogFS(_AppFS): | ||
""" | ||
A filesystem for per-user application log data. | ||
:param str appname: The name of the application. | ||
:param str author: The name of the author (used on Windows). | ||
:param str version: Optional version string, if a unique location | ||
per version of the application is required. | ||
:param bool roaming: If ``True``, use a *roaming* profile on | ||
Windows. | ||
:param bool create: If ``True`` (the default) the directory will | ||
be created if it does not exist. | ||
""" | ||
app_dir = 'user_log_dir' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.