about summary refs log tree commit diff stats
path: root/doc/pydoc/ranger.container.html
blob: df13c17070efeec305ed8166f53596829e23db5d (plain) (blame)
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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: package ranger.container</title>
</head><body bgcolor="#f0f0f8">

<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong><a href="ranger.html"><font color="#ffffff">ranger</font></a>.container</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/hut/ranger/ranger/container/__init__.py">/home/hut/ranger/ranger/container/__init__.py</a></font></td></tr></table>
    <p><tt>This&nbsp;package&nbsp;includes&nbsp;container-objects&nbsp;which&nbsp;are<br>
used&nbsp;to&nbsp;manage&nbsp;stored&nbsp;data</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Package Contents</strong></big></font></td></tr>
    
<tr><td bgcolor="#aa55cc"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="ranger.container.bookmarks.html">bookmarks</a><br>
<a href="ranger.container.commandlist.html">commandlist</a><br>
</td><td width="25%" valign=top><a href="ranger.container.environment.html">environment</a><br>
<a href="ranger.container.history.html">history</a><br>
</td><td width="25%" valign=top><a href="ranger.container.keybuffer.html">keybuffer</a><br>
<a href="ranger.container.tags.html">tags</a><br>
</td><td width="25%" valign=top></td></tr></table></td></tr></table>
</body></html>
pan> """ try: return self[key].go() except (IndexError, KeyError, AttributeError): return False def update_if_outdated(self): if self.last_mtime != self._get_mtime(): self.update() def remember(self, value): """Bookmarks <value> to the key '""" self["'"] = value if self.autosave: self.save() def __iter__(self): return iter(self.dct.items()) def __getitem__(self, key): """Get the bookmark associated with the key""" if key == '`': key = "'" if key in self.dct: return self.dct[key] else: raise KeyError("Nonexistant Bookmark!") def __setitem__(self, key, value): """Bookmark <value> to the key <key>. key is expected to be a 1-character string and element of ALLOWED_KEYS. value is expected to be a filesystemobject. """ if key == '`': key = "'" if key in ALLOWED_KEYS: self.dct[key] = value if self.autosave: self.save() def __contains__(self, key): """Test whether a bookmark-key is defined""" return key in self.dct def update(self): """Update the bookmarks from the bookmark file. Useful if two instances are running which define different bookmarks. """ try: real_dict = self._load_dict() real_dict_copy = real_dict.copy() except OSError: return for key in set(self.dct.keys()) | set(real_dict.keys()): # set some variables if key in self.dct: current = self.dct[key] else: current = None if key in self.original_dict: original = self.original_dict[key] else: original = None if key in real_dict: real = real_dict[key] else: real = None # determine if there have been changes if current == original and current != real: continue # another ranger instance has changed the bookmark if key not in self.dct: del real_dict[key] # the user has deleted it else: real_dict[key] = current # the user has changed it self._set_dict(real_dict, original=real_dict_copy) def save(self): """Save the bookmarks to the bookmarkfile. This is done automatically after every modification if autosave is True.""" import os self.update() if os.access(self.path, os.W_OK): f = open(self.path, 'w') for key, value in self.dct.items(): if type(key) == str\ and key in ALLOWED_KEYS: f.write("{0}:{1}\n".format(str(key), str(value))) f.close() self._update_mtime() def _load_dict(self): import os dct = {} if not os.path.exists(self.path): try: f = open(self.path, 'w') except: raise OSError('Cannot read the given path') f.close() if os.access(self.path, os.R_OK): f = open(self.path, 'r') for line in f: if self.load_pattern.match(line): key, value = line[0], line[2:-1] if key in ALLOWED_KEYS: dct[key] = self.bookmarktype(value) f.close() return dct else: raise OSError('Cannot read the given path') def _set_dict(self, dct, original): if original is None: original = {} self.dct.clear() self.dct.update(dct) self.original_dict = original self._update_mtime() def _get_mtime(self): import os try: return os.stat(self.path).st_mtime except OSError: return None def _update_mtime(self): self.last_mtime = self._get_mtime()