1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# 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/>.
import curses
import os
import pwd
import socket
from os.path import abspath, normpath, join, expanduser, isdir
from ranger.fsobject.directory import Directory, NoDirectoryGiven
from ranger.container import KeyBuffer, History
from ranger.shared import SettingsAware
class Environment(SettingsAware):
"""A collection of data which is relevant for more than
one class.
"""
cwd = None # current directory
cf = None # current file
copy = None
cmd = None
cut = None
termsize = None
history = None
directories = None
last_search = None
pathway = None
path = None
keybuffer = None
def __init__(self, path):
self.path = abspath(expanduser(path))
self.pathway = ()
self.directories = {}
self.keybuffer = KeyBuffer()
self.copy = set()
self.history = History(self.settings.max_history_size)
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('~')
from ranger.shared import EnvironmentAware
EnvironmentAware.env = self
def key_append(self, key):
"""Append a key to the keybuffer"""
# special keys:
if key == curses.KEY_RESIZE:
self.keybuffer.clear()
self.keybuffer.append(key)
def key_clear(self):
"""Clear the keybuffer"""
self.keybuffer.clear()
def at_level(self, level):
"""
Returns the FileSystemObject at the given level.
level >0 => previews
level 0 => current file/directory
level <0 => parent directories
"""
if level &l
|