summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--module/InitHomeDir.py62
-rwxr-xr-xpyLoadCore.py27
2 files changed, 42 insertions, 47 deletions
diff --git a/module/InitHomeDir.py b/module/InitHomeDir.py
index 8515310ef..a45c0cd83 100644
--- a/module/InitHomeDir.py
+++ b/module/InitHomeDir.py
@@ -19,7 +19,6 @@
This modules inits working directories and global variables, pydir and homedir
"""
-
from os import makedirs
from os import path
from os import chdir
@@ -27,54 +26,55 @@ from sys import platform
from sys import argv
import __builtin__
-__builtin__.pypath = path.abspath(path.join(__file__,"..",".."))
+__builtin__.pypath = path.abspath(path.join(__file__, "..", ".."))
homedir = ""
if platform == 'nt':
- homedir = path.expanduser("~")
- if homedir == "~":
- import ctypes
- 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
+ homedir = path.expanduser("~")
+ if homedir == "~":
+ import ctypes
+
+ 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("~")
+ 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)
+ pos = args.find("--configdir=")
+ end = args.find("-", pos + 12)
- if end == -1:
- configdir = args[pos+12:].strip()
- else:
- configdir = args[pos+12:end].strip()
+ if end == -1:
+ configdir = args[pos + 12:].strip()
+ else:
+ configdir = args[pos + 12:end].strip()
elif path.exists(path.join(pypath, "module", "config", "configdir")):
- f = open(path.join(pypath, "module", "config", "configdir"), "rb")
- c = f.read().strip()
- configdir = path.join(pypath, c)
+ f = open(path.join(pypath, "module", "config", "configdir"), "rb")
+ c = f.read().strip()
+ f.close()
+ configdir = path.join(pypath, c)
else:
- if platform in ("posix","linux2"):
- configdir = path.join(homedir, ".pyload")
- else:
- configdir = path.join(homedir, "pyload")
+ if platform in ("posix", "linux2"):
+ configdir = path.join(homedir, ".pyload")
+ else:
+ configdir = path.join(homedir, "pyload")
if not path.exists(configdir):
- makedirs(configdir, 0700)
+ makedirs(configdir, 0700)
__builtin__.configdir = configdir
chdir(configdir)
diff --git a/pyLoadCore.py b/pyLoadCore.py
index eb990bab7..f3c9bef6c 100755
--- a/pyLoadCore.py
+++ b/pyLoadCore.py
@@ -889,13 +889,8 @@ def deamon():
print >>sys.stderr, "fork #2 failed: %d (%s)" % (e.errno, e.strerror)
sys.exit(1)
- from resource import getrlimit, RLIMIT_NOFILE, RLIM_INFINITY # Resource usage information.
- maxfd = getrlimit(RLIMIT_NOFILE)[1]
- if maxfd == RLIM_INFINITY:
- maxfd = 1024
-
- # Iterate through and close all file descriptors.
- for fd in range(0, maxfd):
+ # Iterate through and close some file descriptors.
+ for fd in range(0, 3):
try:
os.close(fd)
except OSError: # ERROR, fd wasn't open to begin with (ignored)
@@ -914,12 +909,12 @@ if __name__ == "__main__":
if "--daemon" in sys.argv:
deamon()
-
- pyload_core = Core()
- try:
- pyload_core.start()
- except KeyboardInterrupt:
- pyload_core.shutdown()
- pyload_core.log.info(_("killed pyLoad from Terminal"))
- pyload_core.removeLogger()
- _exit(1)
+ else:
+ pyload_core = Core()
+ try:
+ pyload_core.start()
+ except KeyboardInterrupt:
+ pyload_core.shutdown()
+ pyload_core.log.info(_("killed pyLoad from Terminal"))
+ pyload_core.removeLogger()
+ _exit(1)