diff options
Diffstat (limited to 'dodai/tools/__init__.py')
-rw-r--r-- | dodai/tools/__init__.py | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/dodai/tools/__init__.py b/dodai/tools/__init__.py index 9d2fad7..ab90cfe 100644 --- a/dodai/tools/__init__.py +++ b/dodai/tools/__init__.py | |||
@@ -15,3 +15,71 @@ | |||
15 | # You should have received a copy of the GNU General Public License | 15 | # You should have received a copy of the GNU General Public License |
16 | # along with Dodai. If not, see <http://www.gnu.org/licenses/>. | 16 | # along with Dodai. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | import sys | ||
19 | import os | ||
20 | import platform | ||
21 | |||
22 | def home_directory(): | ||
23 | """Returns the full real path to the home directory of the user who | ||
24 | is executing this script. | ||
25 | |||
26 | """ | ||
27 | out = None | ||
28 | try: | ||
29 | from win32com.shell import shellcon, shell | ||
30 | out = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0) | ||
31 | except ImportError: | ||
32 | out = os.path.expanduser("~") | ||
33 | return os.path.realpath(out) | ||
34 | |||
35 | def config_directory_system(project_name=None): | ||
36 | """Returns the system config directory with the passed in project | ||
37 | appended to the path. Returns None for windows and java systems. | ||
38 | |||
39 | """ | ||
40 | path = None | ||
41 | if platform.system and platform.system() not in ['Windows', 'Java']: | ||
42 | if project_name: | ||
43 | path = os.path.join('/etc', project_name.strip()) | ||
44 | else: | ||
45 | path = '/etc' | ||
46 | return path | ||
47 | |||
48 | def config_directory_user(project_name): | ||
49 | """Returns the config direcotry of the project which is located in | ||
50 | the user's home directory. Returns None for Java and unknown systems | ||
51 | |||
52 | """ | ||
53 | path = None | ||
54 | project = '.{0}'.format(project_name.strip()) | ||
55 | if platform.system and platform.system() not in ['Java']: | ||
56 | home_dir = home_directory() | ||
57 | path = os.path.join(home_dir, project) | ||
58 | return path | ||
59 | |||
60 | def config_directory_project(): | ||
61 | """Returns the config directory that is located in the same directory | ||
62 | of the executable that ran this script | ||
63 | |||
64 | """ | ||
65 | path = os.path.dirname(os.path.abspath(sys.argv[0])) | ||
66 | return os.path.join(path, 'config') | ||
67 | |||
68 | |||
69 | def config_directories(project_name): | ||
70 | """Returns a list of possible project directories | ||
71 | |||
72 | """ | ||
73 | dirs = [] | ||
74 | dir = config_directory_system(project_name) | ||
75 | if dir: | ||
76 | dirs.append(dir) | ||
77 | dir = config_directory_user(project_name) | ||
78 | if dir: | ||
79 | dirs.append(dir) | ||
80 | dir = config_directory_project() | ||
81 | if dir: | ||
82 | dirs.append(dir) | ||
83 | return dirs | ||
84 | |||
85 | |||