diff options
author | hut <hut@lavabit.com> | 2010-04-18 00:23:04 +0200 |
---|---|---|
committer | hut <hut@lavabit.com> | 2010-04-18 00:23:04 +0200 |
commit | c2238598bfb590367f6c52c4fcbf43d02148a523 (patch) | |
tree | 1f8a731d058077c3d5c87ace3c96cbfebcd3beb6 /ranger | |
parent | 7213292e490a4f6c73a915d2ea6b834c005dd424 (diff) | |
download | ranger-c2238598bfb590367f6c52c4fcbf43d02148a523.tar.gz |
main: added load_settings(). Store apps/keys in fm now.
Also, commands are now loaded from ~/.ranger/commands.py if available
Diffstat (limited to 'ranger')
-rw-r--r-- | ranger/__main__.py | 63 | ||||
-rw-r--r-- | ranger/core/fm.py | 11 | ||||
-rw-r--r-- | ranger/gui/ui.py | 2 | ||||
-rw-r--r-- | ranger/gui/widgets/console.py | 7 | ||||
-rw-r--r-- | ranger/gui/widgets/pager.py | 4 | ||||
-rw-r--r-- | ranger/gui/widgets/taskview.py | 2 | ||||
-rw-r--r-- | ranger/shared/settings.py | 11 |
7 files changed, 57 insertions, 43 deletions
diff --git a/ranger/__main__.py b/ranger/__main__.py index 6b5a21b3..11d2d288 100644 --- a/ranger/__main__.py +++ b/ranger/__main__.py @@ -18,7 +18,7 @@ import os import sys - +import ranger def parse_arguments(): """Parse the program arguments""" @@ -46,18 +46,41 @@ def parse_arguments(): arg = OpenStruct(options.__dict__, targets=positional) arg.confdir = os.path.expanduser(arg.confdir) - if not arg.clean: + return arg + +def load_settings(fm): + if not ranger.arg.clean: try: - os.makedirs(arg.confdir) + os.makedirs(ranger.arg.confdir) except OSError as err: if err.errno != 17: # 17 means it already exists print("This configuration directory could not be created:") - print(arg.confdir) - print("To run ranger without the need for configuration files") - print("use the --clean option.") + print(ranger.arg.confdir) + print("To run ranger without the need for configuration") + print("files, use the --clean option.") raise SystemExit() - sys.path[0:0] = [arg.confdir] - return arg + + sys.path[0:0] = [ranger.arg.confdir] + + try: + import commands + except ImportError: + from ranger.defaults import commands + try: + import keys + except ImportError: + from ranger.defaults import keys + try: + import apps + except ImportError: + from ranger.defaults import apps + del sys.path[0] + else: + from ranger.defaults import commands, keys, apps + fm.commands = commands + fm.keys = keys + fm.apps = apps.CustomApplications() + def main(): """initialize objects and run the filemanager""" @@ -71,7 +94,6 @@ def main(): from signal import signal, SIGINT from locale import getdefaultlocale, setlocale, LC_ALL - import ranger from ranger.ext import curses_interrupt_handler from ranger.core.fm import FM from ranger.core.environment import Environment @@ -105,7 +127,9 @@ def main(): sys.exit(1) elif os.path.isfile(target): thefile = File(target) - FM().execute_file(thefile, mode=arg.mode, flags=arg.flags) + fm = FM() + load_settings(fm) + fm.execute_file(thefile, mode=arg.mode, flags=arg.flags) sys.exit(0) else: path = target @@ -115,18 +139,21 @@ def main(): EnvironmentAware._assign(Environment(path)) try: - my_ui = UI() - my_fm = FM(ui=my_ui) - FileManagerAware._assign(my_fm) + fm = FM() + load_settings(fm) + FileManagerAware._assign(fm) + fm.ui = UI() # Run the file manager - my_fm.initialize() - my_ui.initialize() - my_fm.loop() + fm.initialize() + fm.ui.initialize() + fm.loop() finally: # Finish, clean up - if 'my_ui' in vars(): - my_ui.destroy() + try: + fm.ui.destroy() + except (AttributeError, NameError): + pass if __name__ == '__main__': top_dir = os.path.dirname(sys.path[0]) diff --git a/ranger/core/fm.py b/ranger/core/fm.py index 224ef06f..2cb3eea7 100644 --- a/ranger/core/fm.py +++ b/ranger/core/fm.py @@ -51,12 +51,6 @@ class FM(Actions, SignalDispatcher): self.tabs = {} self.current_tab = 1 self.loader = Loader() - self.apps = self.settings.apps.CustomApplications() - - def mylogfunc(text): - self.notify(text, bad=True) - self.run = Runner(ui=self.ui, apps=self.apps, - logfunc=mylogfunc) self.log.append('Ranger {0} started! Process ID is {1}.' \ .format(__version__, os.getpid())) @@ -94,6 +88,11 @@ class FM(Actions, SignalDispatcher): self.ui = DefaultUI() self.ui.initialize() + def mylogfunc(text): + self.notify(text, bad=True) + self.run = Runner(ui=self.ui, apps=self.apps, + logfunc=mylogfunc) + self.env.signal_bind('cd', self._update_current_tab) def block_input(self, sec=0): diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py index cdaf6cde..2e2f5ada 100644 --- a/ranger/gui/ui.py +++ b/ranger/gui/ui.py @@ -59,7 +59,7 @@ class UI(DisplayableContainer): if commandlist is None: self.commandlist = CommandList() - self.settings.keys.initialize_commands(self.commandlist) + self.fm.keys.initialize_commands(self.commandlist) else: self.commandlist = commandlist self.win = curses.initscr() diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py index 5f45c26f..22539e75 100644 --- a/ranger/gui/widgets/console.py +++ b/ranger/gui/widgets/console.py @@ -24,7 +24,6 @@ import re from collections import deque from . import Widget -from ranger.defaults import commands from ranger.gui.widgets.console_mode import is_valid_mode, mode_to_class from ranger import log, relpath_conf from ranger.core.runner import ALLOWED_FLAGS @@ -63,7 +62,7 @@ class Console(Widget): def __init__(self, win): Widget.__init__(self, win) self.commandlist = CommandList() - self.settings.keys.initialize_console_commands(self.commandlist) + self.fm.keys.initialize_console_commands(self.commandlist) self.clear() self.histories = [] # load histories from files @@ -341,7 +340,7 @@ class CommandConsole(ConsoleWithTab): return command_class(self.line, self.mode) def _get_cmd_class(self): - return commands.get_command(self.line.split()[0]) + return self.fm.commands.get_command(self.line.split()[0]) def _get_tab(self): if ' ' in self.line: @@ -351,7 +350,7 @@ class CommandConsole(ConsoleWithTab): else: return None - return commands.command_generator(self.line) + return self.fm.commands.command_generator(self.line) class QuickCommandConsole(CommandConsole): diff --git a/ranger/gui/widgets/pager.py b/ranger/gui/widgets/pager.py index 2fc8ecda..c0646cdf 100644 --- a/ranger/gui/widgets/pager.py +++ b/ranger/gui/widgets/pager.py @@ -44,9 +44,9 @@ class Pager(Widget): self.commandlist = CommandList() if embedded: - keyfnc = self.settings.keys.initialize_embedded_pager_commands + keyfnc = self.fm.keys.initialize_embedded_pager_commands else: - keyfnc = self.settings.keys.initialize_pager_commands + keyfnc = self.fm.keys.initialize_pager_commands keyfnc(self.commandlist) diff --git a/ranger/gui/widgets/taskview.py b/ranger/gui/widgets/taskview.py index 6e86465c..ec68cb1a 100644 --- a/ranger/gui/widgets/taskview.py +++ b/ranger/gui/widgets/taskview.py @@ -32,7 +32,7 @@ class TaskView(Widget, Accumulator): Accumulator.__init__(self) self.scroll_begin = 0 self.commandlist = CommandList() - self.settings.keys.initialize_taskview_commands(self.commandlist) + self.fm.keys.initialize_taskview_commands(self.commandlist) def draw(self): base_clr = deque() diff --git a/ranger/shared/settings.py b/ranger/shared/settings.py index 44b0e55e..57e00142 100644 --- a/ranger/shared/settings.py +++ b/ranger/shared/settings.py @@ -169,15 +169,4 @@ class SettingsAware(object): for setting in ALLOWED_SETTINGS), \ "Ensure that all options are defined in the defaults!" - try: - import apps - except ImportError: - from ranger.defaults import apps - settings._raw_set('apps', apps) - try: - import keys - except ImportError: - from ranger.defaults import keys - settings._raw_set('keys', keys) - SettingsAware.settings = settings |