about summary refs log blame commit diff stats
path: root/doc/pydoc/ranger.shared.settings.html
blob: ddee912db52505697136b96f2a29480abe18ec67 (plain) (tree)
1
2
3
4
5
6
7
8
9
10

                                                                
                                                                   






                                                                                                                                                                                                                                                     
                                                                                                                                                                                                                   
                                                                                                                              
     



                                                                                                                                           
     






                                                                                                                                                                              

                                                                           




                                                                                                  
                                                                                                                       

                                                                                                       
                                                                           





                                                                                                  
                                                                                    




                                                                                                       
                                                                                                                                                                                                    




                                                                                                       




                                                                           





                                                                                                                                                                                                                                               
                                                           








                                                                                                                                                         

                                                                                      



                                                               
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module ranger.shared.settings</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</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>.<a href="ranger.shared.html"><font color="#ffffff">shared</font></a>.settings</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/code/ranger/ranger/shared/settings.py">/home/hut/code/ranger/ranger/shared/settings.py</a></font></td></tr></table>
    <p><tt>#&nbsp;Copyright&nbsp;(C)&nbsp;2009,&nbsp;2010&nbsp;&nbsp;Roman&nbsp;Zimbelmann&nbsp;&lt;romanz@lavabit.com&gt;<br>
#<br>
#&nbsp;This&nbsp;program&nbsp;is&nbsp;free&nbsp;software:&nbsp;you&nbsp;can&nbsp;redistribute&nbsp;it&nbsp;and/or&nbsp;modify<br>
#&nbsp;it&nbsp;under&nbsp;the&nbsp;terms&nbsp;of&nbsp;the&nbsp;GNU&nbsp;General&nbsp;Public&nbsp;License&nbsp;as&nbsp;published&nbsp;by<br>
#&nbsp;the&nbsp;Free&nbsp;Software&nbsp;Foundation,&nbsp;either&nbsp;version&nbsp;3&nbsp;of&nbsp;the&nbsp;License,&nbsp;or<br>
#&nbsp;(at&nbsp;your&nbsp;option)&nbsp;any&nbsp;later&nbsp;version.<br>
#<br>
#&nbsp;This&nbsp;program&nbsp;is&nbsp;distributed&nbsp;in&nbsp;the&nbsp;hope&nbsp;that&nbsp;it&nbsp;will&nbsp;be&nbsp;useful,<br>
#&nbsp;but&nbsp;WITHOUT&nbsp;ANY&nbsp;WARRANTY;&nbsp;without&nbsp;even&nbsp;the&nbsp;implied&nbsp;warranty&nbsp;of<br>
#&nbsp;MERCHANTABILITY&nbsp;or&nbsp;FITNESS&nbsp;FOR&nbsp;A&nbsp;PARTICULAR&nbsp;PURPOSE.&nbsp;&nbsp;See&nbsp;the<br>
#&nbsp;GNU&nbsp;General&nbsp;Public&nbsp;License&nbsp;for&nbsp;more&nbsp;details.<br>
#<br>
#&nbsp;You&nbsp;should&nbsp;have&nbsp;received&nbsp;a&nbsp;copy&nbsp;of&nbsp;the&nbsp;GNU&nbsp;General&nbsp;Public&nbsp;License<br>
#&nbsp;along&nbsp;with&nbsp;this&nbsp;program.&nbsp;&nbsp;If&nbsp;not,&nbsp;see&nbsp;&lt;<a href="http://www.gnu.org/licenses/">http://www.gnu.org/licenses/</a>&gt;.</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>Modules</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.html">ranger</a><br>
</td><td width="25%" valign=top><a href="sys.html">sys</a><br>
</td><td width="25%" valign=top></td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ee77aa">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
    
<tr><td bgcolor="#ee77aa"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="builtins.html#object">builtins.object</a>
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="ranger.shared.settings.html#SettingsAware">SettingsAware</a>
</font></dt></dl>
</dd>
<dt><font face="helvetica, arial"><a href="ranger.ext.signal_dispatcher.html#SignalDispatcher">ranger.ext.signal_dispatcher.SignalDispatcher</a>(<a href="builtins.html#object">builtins.object</a>)
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="ranger.shared.settings.html#SettingObject">SettingObject</a>
</font></dt></dl>
</dd>
</dl>
 <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#000000" face="helvetica, arial"><a name="SettingObject">class <strong>SettingObject</strong></a>(<a href="ranger.ext.signal_dispatcher.html#SignalDispatcher">ranger.ext.signal_dispatcher.SignalDispatcher</a>)</font></td></tr>
    
<tr><td bgcolor="#ffc8d8"><tt>&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl><dt>Method resolution order:</dt>
<dd><a href="ranger.shared.settings.html#SettingObject">SettingObject</a></dd>
<dd><a href="ranger.ext.signal_dispatcher.html#SignalDispatcher">ranger.ext.signal_dispatcher.SignalDispatcher</a></dd>
<dd><a href="builtins.html#object">builtins.object</a></dd>
</dl>
<hr>
Methods defined here:<br>
<dl><dt><a name="SettingObject-__getattr__"><strong>__getattr__</strong></a>(self, name)</dt></dl>

<dl><dt><a name="SettingObject-__getitem__"><strong>__getitem__</strong></a> = <a href="#SettingObject-__getattr__">__getattr__</a>(self, name)</dt></dl>

<dl><dt><a name="SettingObject-__init__"><strong>__init__</strong></a>(self)</dt></dl>

<dl><dt><a name="SettingObject-__iter__"><strong>__iter__</strong></a>(self)</dt></dl>

<dl><dt><a name="SettingObject-__setattr__"><strong>__setattr__</strong></a>(self, name, value)</dt></dl>

<dl><dt><a name="SettingObject-__setitem__"><strong>__setitem__</strong></a> = <a href="#SettingObject-__setattr__">__setattr__</a>(self, name, value)</dt></dl>

<dl><dt><a name="SettingObject-types_of"><strong>types_of</strong></a>(self, name)</dt></dl>

<hr>
Methods inherited from <a href="ranger.ext.signal_dispatcher.html#SignalDispatcher">ranger.ext.signal_dispatcher.SignalDispatcher</a>:<br>
<dl><dt><a name="SettingObject-signal_bind"><strong>signal_bind</strong></a>(self, signal_name, function, priority<font color="#909090">=0.5</font>, weak<font color="#909090">=False</font>)</dt></dl>

<dl><dt><a name="SettingObject-signal_clear"><strong>signal_clear</strong></a> = __init__(self)</dt></dl>

<dl><dt><a name="SettingObject-signal_emit"><strong>signal_emit</strong></a>(self, signal_name, **kw)</dt></dl>

<dl><dt><a name="SettingObject-signal_unbind"><strong>signal_unbind</strong></a>(self, signal_handler)</dt></dl>

<hr>
Data descriptors inherited from <a href="ranger.ext.signal_dispatcher.html#SignalDispatcher">ranger.ext.signal_dispatcher.SignalDispatcher</a>:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#000000" face="helvetica, arial"><a name="SettingsAware">class <strong>SettingsAware</strong></a>(<a href="builtins.html#object">builtins.object</a>)</font></td></tr>
    
<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
<td colspan=2><tt>#&nbsp;--&nbsp;globalize&nbsp;the&nbsp;settings&nbsp;--<br>&nbsp;</tt></td></tr>
<tr><td>&nbsp;</td>
<td width="100%">Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
<hr>
Data and other attributes defined here:<br>
<dl><dt><strong>settings</strong> = {}</dl>

</td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
    
<tr><td bgcolor="#55aa55"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><strong>ALLOWED_SETTINGS</strong> = {'autosave_bookmarks': &lt;class 'bool'&gt;, 'collapse_preview': &lt;class 'bool'&gt;, 'colorscheme': &lt;class 'str'&gt;, 'colorscheme_overlay': (&lt;class 'NoneType'&gt;, &lt;class 'function'&gt;), 'column_ratios': (&lt;class 'tuple'&gt;, &lt;class 'list'&gt;, &lt;class 'set'&gt;), 'dirname_in_tabs': &lt;class 'bool'&gt;, 'display_size_in_main_column': &lt;class 'bool'&gt;, 'display_size_in_status_bar': &lt;class 'bool'&gt;, 'draw_bookmark_borders': &lt;class 'bool'&gt;, 'draw_borders': &lt;class 'bool'&gt;, ...}</td></tr></table>
</body></html>
yes :delete seriously? yeah! """ allow_abbrev = False def execute(self): line = parse(self.line) lastword = line.chunk(-1) if lastword.startswith('y'): # user confirmed deletion! return self.fm.delete() elif self.line.startswith(DELETE_WARNING): # user did not confirm deletion return cwd = self.fm.env.cwd cf = self.fm.env.cf if cwd.marked_items or (cf.is_directory and not cf.is_link \ and len(os.listdir(cf.path)) > 0): # better ask for a confirmation, when attempting to # delete multiple files or a non-empty directory. return self.fm.open_console(DELETE_WARNING) # no need for a confirmation, just delete self.fm.delete() class mark(Command): """ :mark <regexp> Mark all files matching a regular expression. """ do_mark = True def execute(self): import re cwd = self.fm.env.cwd line = parse(self.line) input = line.rest(1) searchflags = re.UNICODE if input.lower() == input: # "smartcase" searchflags |= re.IGNORECASE pattern = re.compile(input, searchflags) for fileobj in cwd.files: if pattern.search(fileobj.basename): cwd.mark_item(fileobj, val=self.do_mark) self.fm.ui.status.need_redraw = True self.fm.ui.need_redraw = True class load_copy_buffer(Command): """ :load_copy_buffer Load the copy buffer from confdir/copy_buffer """ copy_buffer_filename = 'copy_buffer' def execute(self): from ranger.fsobject import File from os.path import exists try: fname = self.fm.confpath(self.copy_buffer_filename) f = open(fname, 'r') except: return self.fm.notify("Cannot open %s" % \ (fname or self.copy_buffer_filename), bad=True) self.fm.env.copy = set(File(g) \ for g in f.read().split("\n") if exists(g)) f.close() self.fm.ui.redraw_main_column() class save_copy_buffer(Command): """ :save_copy_buffer Save the copy buffer to confdir/copy_buffer """ copy_buffer_filename = 'copy_buffer' def execute(self): fname = None try: fname = self.fm.confpath(self.copy_buffer_filename) f = open(fname, 'w') except: return self.fm.notify("Cannot open %s" % \ (fname or self.copy_buffer_filename), bad=True) f.write("\n".join(f.path for f in self.fm.env.copy)) f.close() class unmark(mark): """ :unmark <regexp> Unmark all files matching a regular expression. """ do_mark = False class mkdir(Command): """ :mkdir <dirname> Creates a directory with the name <dirname>. """ def execute(self): from os.path import join, expanduser, lexists from os import mkdir line = parse(self.line) dirname = join(self.fm.env.cwd.path, expanduser(line.rest(1))) if not lexists(dirname): mkdir(dirname) else: self.fm.notify("file/directory exists!", bad=True) class touch(Command): """ :touch <fname> Creates a file with the name <fname>. """ def execute(self): from os.path import join, expanduser, lexists from os import mkdir line = parse(self.line) fname = join(self.fm.env.cwd.path, expanduser(line.rest(1))) if not lexists(fname): open(fname, 'a') else: self.fm.notify("file/directory exists!", bad=True) class edit(Command): """ :edit <filename> Opens the specified file in vim """ def execute(self): line = parse(self.line) if not line.chunk(1): self.fm.edit_file(self.fm.env.cf.path) else: self.fm.edit_file(line.rest(1)) def tab(self): return self._tab_directory_content() class eval_(Command): """ :eval <python code> Evaluates the python code. `fm' is a reference to the FM instance. To display text, use the function `p'. Examples: :eval fm :eval len(fm.env.directories) :eval p("Hello World!") """ name = 'eval' def execute(self): code = parse(self.line).rest(1) fm = self.fm p = fm.notify try: try: result = eval(code) except SyntaxError: exec(code) else: if result: p(result) except Exception as err: p(err) class rename(Command): """ :rename <newname> Changes the name of the currently highlighted file to <newname> """ def execute(self): from ranger.fsobject import File from os import access from os.path import join line = parse(self.line) new_name = line.rest(1) if not new_name: return self.fm.notify('Syntax: rename <newname>', bad=True) if new_name == self.fm.env.cf.basename: return if access(new_name, os.F_OK): return self.fm.notify("Can't rename: file already exists!", bad=True) self.fm.rename(self.fm.env.cf, new_name) f = File(new_name) self.fm.env.cwd.pointed_obj = f self.fm.env.cf = f def tab(self): return self._tab_directory_content() class chmod(Command): """ :chmod <octal number> Sets the permissions of the selection to the octal number. The octal number is between 0 and 777. The digits specify the permissions for the user, the group and others. A 1 permits execution, a 2 permits writing, a 4 permits reading. Add those numbers to combine them. So a 7 permits everything. """ def execute(self): line = parse(self.line) mode = line.rest(1) try: mode = int(mode, 8) if mode < 0 or mode > 0o777: raise ValueError except ValueError: self.fm.notify("Need an octal number between 0 and 777!", bad=True) return for file in self.fm.env.get_selection(): try: os.chmod(file.path, mode) except Exception as ex: self.fm.notify(ex) try: # reloading directory. maybe its better to reload the selected # files only. self.fm.env.cwd.load_content() except: pass class bulkrename(Command): """ :bulkrename This command opens a list of selected files in an external editor. After you edit and save the file, it will generate a shell script which does bulk renaming according to the changes you did in the file. This shell script is opened in an editor for you to review. After you close it, it will be executed. """ def execute(self): import sys import tempfile from ranger.fsobject.file import File from ranger.ext.shell_escape import shell_escape as esc py3 = sys.version > "3" # Create and edit the file list filenames = [f.basename for f in self.fm.env.get_selection()] listfile = tempfile.NamedTemporaryFile() if py3: listfile.write("\n".join(filenames).encode("utf-8")) else: listfile.write("\n".join(filenames)) listfile.flush() self.fm.execute_file([File(listfile.name)], app='editor') listfile.seek(0) if py3: new_filenames = listfile.read().decode("utf-8").split("\n") else: new_filenames = listfile.read().split("\n") listfile.close() if all(a == b for a, b in zip(filenames, new_filenames)): self.fm.notify("No renaming to be done!") return # Generate and execute script cmdfile = tempfile.NamedTemporaryFile() cmdfile.write(b"# This file will be executed when you close the editor.\n") cmdfile.write(b"# Please double-check everything, clear the file to abort.\n") if py3: cmdfile.write("\n".join("mv -vi " + esc(old) + " " + esc(new) \ for old, new in zip(filenames, new_filenames) if old != new).encode("utf-8")) else: cmdfile.write("\n".join("mv -vi " + esc(old) + " " + esc(new) \ for old, new in zip(filenames, new_filenames) if old != new)) cmdfile.flush() self.fm.run(['vim', cmdfile.name]) self.fm.run(['/bin/sh', cmdfile.name], flags='w') cmdfile.close() class filter(Command): """ :filter <string> Displays only the files which contain <string> in their basename. """ def execute(self): line = parse(self.line) self.fm.set_filter(line.rest(1)) self.fm.reload_cwd() class grep(Command): """ :grep <string> Looks for a string in all marked files or directories """ def execute(self): line = parse(self.line) if line.rest(1): action = ['grep', '--color=always', '--line-number'] action.extend(['-e', line.rest(1), '-r']) action.extend(f.path for f in self.fm.env.get_selection()) self.fm.execute_command(action, flags='p')