diff options
author | hut <hut@lavabit.com> | 2012-08-05 05:42:40 +0200 |
---|---|---|
committer | hut <hut@lavabit.com> | 2012-08-05 14:36:33 +0200 |
commit | 33e8913a99e452050576307b7fd65e3469b5cb31 (patch) | |
tree | 077c596e3bfbbe2b73b5f135fbf4797d6cca2a39 | |
parent | 6cb960642b3cf7b62c94962f6308b207ec54dbc2 (diff) | |
download | ranger-33e8913a99e452050576307b7fd65e3469b5cb31.tar.gz |
moved fm.env.{username,hostname,home_path} to fm.*
-rw-r--r-- | ranger/core/environment.py | 22 | ||||
-rw-r--r-- | ranger/core/fm.py | 9 | ||||
-rw-r--r-- | ranger/core/main.py | 2 | ||||
-rw-r--r-- | ranger/gui/ui.py | 4 | ||||
-rw-r--r-- | ranger/gui/widgets/titlebar.py | 10 |
5 files changed, 29 insertions, 18 deletions
diff --git a/ranger/core/environment.py b/ranger/core/environment.py index bd4d3ad9..5ab2b531 100644 --- a/ranger/core/environment.py +++ b/ranger/core/environment.py @@ -2,8 +2,6 @@ # This software is distributed under the terms of the GNU GPL version 3. import os -import pwd -import socket from os.path import abspath, normpath, join, expanduser, isdir from ranger.fsobject import Directory @@ -29,6 +27,18 @@ class EnvironmentCompatibilityWrapper(object): def _set_keybuffer(self, obj): self.fm.ui.keybuffer = obj keybuffer = property(_get_keybuffer, _set_keybuffer) + def _get_username(self): return self.fm.username + def _set_username(self, obj): self.fm.username = obj + username = property(_get_username, _set_username) + + def _get_hostname(self): return self.fm.hostname + def _set_hostname(self, obj): self.fm.hostname = obj + hostname = property(_get_hostname, _set_hostname) + + def _get_home_path(self): return self.fm.home_path + def _set_home_path(self, obj): self.fm.home_path = obj + home_path = property(_get_home_path, _set_home_path) + class Environment(SettingsAware, FileManagerAware, SignalDispatcher, EnvironmentCompatibilityWrapper): """ @@ -48,14 +58,6 @@ class Environment(SettingsAware, FileManagerAware, SignalDispatcher, self._cf = None self.pathway = () self.history = History(self.settings.max_history_size, unique=False) - - try: - self.username = pwd.getpwuid(os.geteuid()).pw_name - except: - self.username = 'uid:' + str(os.geteuid()) - self.hostname = socket.gethostname() - self.home_path = os.path.expanduser('~') - self.signal_bind('move', self._set_cf_from_signal, priority=0.1, weak=True) diff --git a/ranger/core/fm.py b/ranger/core/fm.py index 06c95061..75637390 100644 --- a/ranger/core/fm.py +++ b/ranger/core/fm.py @@ -9,6 +9,8 @@ from time import time from collections import deque import mimetypes import os +import pwd +import socket import stat import sys @@ -56,6 +58,13 @@ class FM(Actions, SignalDispatcher): self.copy_buffer = set() self.do_cut = False + try: + self.username = pwd.getpwuid(os.geteuid()).pw_name + except: + self.username = 'uid:' + str(os.geteuid()) + self.hostname = socket.gethostname() + self.home_path = os.path.expanduser('~') + self.log.append('ranger {0} started! Process ID is {1}.' \ .format(__version__, os.getpid())) self.log.append('Running on Python ' + sys.version.replace('\n','')) diff --git a/ranger/core/main.py b/ranger/core/main.py index 616bf361..1d25c54f 100644 --- a/ranger/core/main.py +++ b/ranger/core/main.py @@ -106,7 +106,7 @@ def main(): print(chr(key)) return 1 if arg.fail_unless_cd else 0 - if fm.env.username == 'root': + if fm.username == 'root': fm.settings.preview_files = False fm.settings.use_preview_script = False if not arg.debug: diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py index 2b6612b1..835c4cc0 100644 --- a/ranger/gui/ui.py +++ b/ranger/gui/ui.py @@ -280,8 +280,8 @@ class UI(DisplayableContainer): DisplayableContainer.draw(self) if self._draw_title and self.settings.update_title: cwd = self.fm.env.cwd.path - if cwd.startswith(self.env.home_path): - cwd = '~' + cwd[len(self.env.home_path):] + if cwd.startswith(self.fm.home_path): + cwd = '~' + cwd[len(self.fm.home_path):] if self.settings.shorten_title: split = cwd.rsplit(os.sep, self.settings.shorten_title) if os.sep in split[0]: diff --git a/ranger/gui/widgets/titlebar.py b/ranger/gui/widgets/titlebar.py index 4ec917b1..fddf2e64 100644 --- a/ranger/gui/widgets/titlebar.py +++ b/ranger/gui/widgets/titlebar.py @@ -91,20 +91,20 @@ class TitleBar(Widget): def _get_left_part(self, bar): # TODO: Properly escape non-printable chars without breaking unicode - if self.env.username == 'root': + if self.fm.username == 'root': clr = 'bad' else: clr = 'good' - bar.add(self.env.username, 'hostname', clr, fixed=True) + bar.add(self.fm.username, 'hostname', clr, fixed=True) bar.add('@', 'hostname', clr, fixed=True) - bar.add(self.env.hostname, 'hostname', clr, fixed=True) + bar.add(self.fm.hostname, 'hostname', clr, fixed=True) bar.add(':', 'hostname', clr, fixed=True) pathway = self.env.pathway if self.settings.tilde_in_titlebar and \ - self.fm.env.cwd.path.startswith(self.env.home_path): - pathway = pathway[self.env.home_path.count('/')+1:] + self.fm.env.cwd.path.startswith(self.fm.home_path): + pathway = pathway[self.fm.home_path.count('/')+1:] bar.add('~/', 'directory', fixed=True) for path in pathway: |