diff options
author | Walter Purcaro <vuolter@gmail.com> | 2014-12-13 01:00:18 +0100 |
---|---|---|
committer | Walter Purcaro <vuolter@gmail.com> | 2014-12-13 01:00:18 +0100 |
commit | 3e497bee36c19c83a90b475a66158947c8713e66 (patch) | |
tree | 38d0172a5f4048cfe213e445e0ae2eec1a9c0394 | |
parent | Use empty string when missing author email (diff) | |
download | pyload-3e497bee36c19c83a90b475a66158947c8713e66.tar.xz |
Fix pyload __init__
-rw-r--r-- | pyload/__init__.py | 47 | ||||
-rw-r--r-- | pyload/config/Setup.py | 23 |
2 files changed, 45 insertions, 25 deletions
diff --git a/pyload/__init__.py b/pyload/__init__.py index 1c9daedbd..03bab80fb 100644 --- a/pyload/__init__.py +++ b/pyload/__init__.py @@ -1,5 +1,17 @@ # -*- coding: utf-8 -*- +from __future__ import with_statement + +import __builtin__ + +import os +import sys + +from codecs import getwriter + +from pyload.utils import get_console_encoding + + __all__ = ["__status_code__", "__status__", "__version_info__", "__version__", "__author_name__", "__author_mail__", "__license__"] __version_info__ = (0, 4, 10) @@ -28,19 +40,11 @@ __authors__ = [("Marius" , "mkaay@mkaay.de" ), ################################# InitHomeDir ################################# -import __builtin__ -import os -import sys - -from codecs import getwriter - -from pyload.utils import get_console_encoding - -projectdir = os.path.abspath(os.path.join(__file__, "..")) +rootdir = os.path.abspath(os.path.join(__file__, "..")) homedir = os.path.expanduser("~") enc = get_console_encoding(sys.stdout.encoding) -sys.os.path.append(os.path.join(projectdir, "lib")) +sys.path.append(os.path.join(rootdir, "lib")) sys.stdout = getwriter(enc)(sys.stdout, errors="replace") if homedir == "~" and os.name == "nt": @@ -62,11 +66,10 @@ if homedir == "~" and os.name == "nt": homedir = path_buf.value try: - p = os.path.join(projectdir, "config", "configdir") - if os.path.exists(p): - f = open(p, "rb") + p = os.path.join(rootdir, "config", "configdir") + + with open(p, "rb") as f: configdir = f.read().strip() - f.close() except IOError: if os.name == "posix": @@ -74,11 +77,19 @@ except IOError: else: configdir = os.path.join(homedir, "pyload") +try: + if not os.path.exists(configdir): + os.makedirs(configdir, 0700) + + os.chdir(configdir) + +except IOError: + sys.exit(1) + __builtin__.owd = os.path.abspath("") #: original working directory -__builtin__.pypath = os.path.abspath(os.path.join(projectdir, "..")) -__builtin__.pycore = None #: Store global Core.Core instance (will be set by Core on its init) +__builtin__.pypath = os.path.abspath(os.path.join(rootdir, "..")) -__builtin__.projectdir = projectdir +__builtin__.rootdir = rootdir __builtin__.homedir = homedir -__builtin__.configdir = configdir
\ No newline at end of file +__builtin__.configdir = configdir diff --git a/pyload/config/Setup.py b/pyload/config/Setup.py index 88e428f93..669f01028 100644 --- a/pyload/config/Setup.py +++ b/pyload/config/Setup.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- # @author: vuolter +from __future__ import with_statement + import __builtin__ import os @@ -417,16 +419,20 @@ class SetupAssistant(object): try: if not path.exists(dirname): makedirs(dirname, 0700) + + chdir(dirname) + if persistent: - c = path.join(projectdir, "config", "configdir") + c = path.join(rootdir, "config", "configdir") if not path.exists(c): makedirs(c, 0700) - f = open(c, "wb") - f.write(dirname) - f.close() - chdir(dirname) - except Exception: + + with open(c, "wb") as f: + f.write(dirname) + + except IOError: return False + else: __builtin__.configdir = dirname return dirname #: return always abspath @@ -440,7 +446,10 @@ class SetupAssistant(object): confdir = self.ask(_("CONFIG PATH"), configdir) confpath = self.set_configdir(confdir) print - if confpath: + if not confpath: + print _("Failed to change the current config path!") + print + else: print _("pyLoad config path successfully changed.") break |