summary refs log tree commit diff stats
path: root/ranger/ext/rifle.py
diff options
context:
space:
mode:
authorSamuel Walladge <samuel@swalladge.id.au>2017-02-03 21:43:08 +1030
committernfnty <git@nfnty.se>2017-02-05 09:44:03 +0100
commit24dd1af4f0bd05ad781e0f79723df2b07cb70218 (patch)
treea1433f40cc1a871d65da8f11d5511810bedf4b5d /ranger/ext/rifle.py
parent3fe5f92984e1361d06170e3b6a420ec93a041aaa (diff)
downloadranger-24dd1af4f0bd05ad781e0f79723df2b07cb70218.tar.gz
rifle: Add new option flag `-c`
Diffstat (limited to 'ranger/ext/rifle.py')
-rwxr-xr-xranger/ext/rifle.py34
1 files changed, 27 insertions, 7 deletions
diff --git a/ranger/ext/rifle.py b/ranger/ext/rifle.py
index 89ee7fa2..0bba937d 100755
--- a/ranger/ext/rifle.py
+++ b/ranger/ext/rifle.py
@@ -380,9 +380,7 @@ class Rifle(object):  # pylint: disable=too-many-instance-attributes
                 self.hook_after_executing(command, self._mimetype, self._app_flags)
 
 
-def main():  # pylint: disable=too-many-locals
-    """The main function which is run when you start this program direectly."""
-
+def find_conf_path():
     # Find configuration file path
     if 'XDG_CONFIG_HOME' in os.environ and os.environ['XDG_CONFIG_HOME']:
         conf_path = os.environ['XDG_CONFIG_HOME'] + '/ranger/rifle.conf'
@@ -401,6 +399,17 @@ def main():  # pylint: disable=too-many-locals
         else:
             conf_path = os.path.join(ranger.__path__[0], "config", "rifle.conf")
 
+    if not os.path.isfile(conf_path):
+        sys.stderr.write("Could not find a configuration file.\n"
+                         "Please create one at %s.\n" % default_conf_path)
+        return None
+
+    return conf_path
+
+
+def main():  # pylint: disable=too-many-locals
+    """The main function which is run when you start this program direectly."""
+
     # Evaluate arguments
     from optparse import OptionParser  # pylint: disable=deprecated-module
     parser = OptionParser(usage="%prog [-fhlpw] [files]", version=__version__)
@@ -415,15 +424,26 @@ def main():  # pylint: disable=too-many-locals
                       "the configuration file")
     parser.add_option('-w', type='string', default=None, metavar="PROGRAM",
                       help="open the files with PROGRAM")
+    parser.add_option('-c', type='string', default=None, metavar="CONFIG_FILE",
+                      help="read config from specified file instead of default")
     options, positional = parser.parse_args()
     if not positional:
         parser.print_help()
         raise SystemExit(1)
 
-    if not os.path.isfile(conf_path):
-        sys.stderr.write("Could not find a configuration file.\n"
-                         "Please create one at %s.\n" % default_conf_path)
-        raise SystemExit(1)
+    if options.c is None:
+        conf_path = find_conf_path()
+        if not conf_path:
+            raise SystemExit(1)
+    else:
+        try:
+            conf_path = os.path.abspath(options.c)
+        except OSError as ex:
+            sys.stderr.write("Unable to access specified configuration file: {0}\n".format(ex))
+            raise SystemExit(1)
+        if not os.path.isfile(conf_path):
+            sys.stderr.write("Specified configuration file not found: {0}\n".format(conf_path))
+            raise SystemExit(1)
 
     if options.p.isdigit():
         number = int(options.p)
dd09b1d58710c323264f3bffbf1476ac'>71577c1f ^
3bb1f124 ^
7db1bcee ^
d56f6dc3 ^
5c65599e ^
81190251 ^
447d2358 ^
447d2358 ^

a2726b6a ^

447d2358 ^



a2726b6a ^

447d2358 ^



a2726b6a ^

447d2358 ^



a2726b6a ^

447d2358 ^
a2726b6a ^
49661625 ^
302d0dd5 ^

447d2358 ^
3bb1f124 ^
88f423af ^
7db1bcee ^

00a475cf ^
8db2389d ^


7db1bcee ^
e571ccd8 ^
5c65599e ^
81190251 ^
3e3786eb ^
71577c1f ^

a2726b6a ^

447d2358 ^
a2726b6a ^
447d2358 ^
3bb1f124 ^
00a475cf ^
8db2389d ^


7db1bcee ^
e571ccd8 ^





a2726b6a ^

e571ccd8 ^
a2726b6a ^
a4cadf78 ^
302d0dd5 ^

e571ccd8 ^





8db2389d ^


e571ccd8 ^

5c65599e ^
81190251 ^
447d2358 ^
447d2358 ^
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109