about summary refs log tree commit diff stats
path: root/apps/ex3
blob: 9e3d3a5a387f575f3f076b3a2f15bc89ab5fa1c0 (plain)
ofshex dumpascii
0000 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 02 00 03 00 01 00 00 00 d3 00 00 09 34 00 00 00 .ELF........................4...
0020 00 00 00 00 00 00 00 00 34 00 20 00 02 00 00 00 00 00 00 00 01 00 00 00 74 00 00 00 74 00 00 09 ........4...............t...t...
0040 74 00 00 09 7b 00 00 00 7b 00 00 00 05 00 00 00 00 10 00 00 01 00 00 00 ef 00 00 00 ef 00 00 0a t...{...{.......................
0060 ef 00 00 0a 00 00 00 00 00 00 00 00 06 00 00 00 00 10 00 00 b8 01 00 00 00 cd 80 b8 03 00 00 00 ................................
0080 cd 80 c3 b8 04 00 00 00 cd 80 c3 b8 05 00 00 00 cd 80 c3 b8 06 00 00 00 cd 80 c3 b8 08 00 00 00 ................................
00a0 cd 80 c3 b8 0a 00 00 00 cd 80 c3 b8 26 00 00 00 cd 80 c3 b8 5a 00 00 00 cd 80 c3 b8 36 00 00 00 ............&.......Z.......6...
00c0 cd 80 c3 b8 a2 00 00 00 cd 80 c3 b8 09 01 00 00 cd 80 c3 bb 00 00 00 00 b9 01 00 00 00 81 f9 0a ................................
00e0 00 00 00 7f 05 01 cb 41 eb f3 e8 85 ff ff ff .......A.......
'n57' href='#n57'>57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
# Copyright (C) 2009, 2010  Roman Zimbelmann <romanz@lavabit.com>
#
# 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/>.

"""Shared objects contain singleton variables which can be
inherited, essentially acting like global variables."""

from ranger.ext.lazy_property import lazy_property

class Awareness(object):
	pass

class EnvironmentAware(Awareness):
	# This creates an instance implicitly, mainly for unit tests
	@lazy_property
	def env(self):
		from ranger.core.environment import Environment
		return Environment(".")

class FileManagerAware(Awareness):
	# This creates an instance implicitly, mainly for unit tests
	@lazy_property
	def fm(self):
		from ranger.core.fm import FM
		return FM()

class SettingsAware(Awareness):
	# This creates an instance implicitly, mainly for unit tests
	@lazy_property
	def settings(self):
		from ranger.ext.openstruct import OpenStruct
		return OpenStruct()

	@staticmethod
	def _setup(clean=True):
		from ranger.container.settingobject import SettingObject, \
				ALLOWED_SETTINGS
		import ranger
		import sys
		settings = SettingObject()

		from ranger.gui.colorscheme import _colorscheme_name_to_class
		settings.signal_bind('setopt.colorscheme',
				_colorscheme_name_to_class, priority=1)

		def postprocess_paths(signal):
			import os
			signal.value = os.path.expanduser(signal.value)
		settings.signal_bind('setopt.preview_script',
				postprocess_paths, priority=1)

		if not clean:
			# add the custom options to the list of setting sources
			sys.path[0:0] = [ranger.arg.confdir]
			try:
				import options as my_options
			except ImportError:
				pass
			else:
				settings._setting_sources.append(my_options)
			del sys.path[0]

		from ranger.defaults import options as default_options
		settings._setting_sources.append(default_options)
		assert all(hasattr(default_options, setting) \
				for setting in ALLOWED_SETTINGS), \
				"Ensure that all options are defined in the defaults!"
		SettingsAware.settings = settings