diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2010-07-29 12:09:42 +0200 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2010-07-29 12:09:42 +0200 |
commit | 2ba07aa53d2af572af2c5a43e77725abd46e1b13 (patch) | |
tree | 89ff915a3a476dd9431d38c6e2b39b9de1aeb0f5 /module/InitHomeDir.py | |
parent | Added tag working for changeset 3cca18acfe7d (diff) | |
download | pyload-2ba07aa53d2af572af2c5a43e77725abd46e1b13.tar.xz |
many new stuff, some things already working
Diffstat (limited to 'module/InitHomeDir.py')
-rw-r--r-- | module/InitHomeDir.py | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/module/InitHomeDir.py b/module/InitHomeDir.py new file mode 100644 index 000000000..aa94f698c --- /dev/null +++ b/module/InitHomeDir.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +""" + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, + or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see <http://www.gnu.org/licenses/>. + + @author: RaNaN + + This modules inits working directories and global variables, pydir and homedir +""" + + +from os import mkdir +from os import path +from os import chdir +from sys import platform +from sys import argv + +import __builtin__ +__builtin__.pypath = path.abspath(path.join(__file__,"..","..")) + + +homedir = "" +try: + from win32com.shell import shellcon, shell + homedir = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0) +except ImportError: # quick semi-nasty fallback for non-windows/win32com case + if platform == 'nt': + import ctypes + from ctypes import wintypes, windll + CSIDL_APPDATA = 26 + _SHGetFolderPath = ctypes.windll.shell32.SHGetFolderPathW + _SHGetFolderPath.argtypes = [ctypes.wintypes.HWND, + ctypes.c_int, + ctypes.wintypes.HANDLE, + ctypes.wintypes.DWORD, ctypes.wintypes.LPCWSTR] + + path_buf = ctypes.wintypes.create_unicode_buffer(ctypes.wintypes.MAX_PATH) + result = _SHGetFolderPath(0, CSIDL_APPDATA, 0, 0, path_buf) + homedir = path_buf.value + else: + homedir = path.expanduser("~") + +__builtin__.homedir = homedir + + +args = " ".join(argv[1:]) + +# dirty method to set configdir from commandline arguments + +if "--configdir=" in args: + pos = args.find("--configdir=") + end = args.find("-", pos+12) + + if end == -1: + configdir = args[pos+12:].strip() + else: + configdir = args[pos+12:end].strip() +else: + if platform in ("posix","linux2"): + configdir = path.join(homedir, ".pyload") + else: + configdir = path.join(homedir, "pyload") + +if not path.exists(configdir): + mkdir(configdir, 0700) + +__builtin__.configdir = configdir +chdir(configdir) + +#print "Using %s as working directory." % configdir |