summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/ext/papermanager.py78
-rw-r--r--ranger/gui/widgets/browsercolumn.py2
2 files changed, 76 insertions, 4 deletions
diff --git a/ranger/ext/papermanager.py b/ranger/ext/papermanager.py
index 6c422659..932505c9 100644
--- a/ranger/ext/papermanager.py
+++ b/ranger/ext/papermanager.py
@@ -52,15 +52,87 @@ class PaperManager(object):
             return result
 
     def set_paper_info(self, filename, update_dict):
-        pass
+        result = None
+        found = False
+        valid = (filename, basename(filename))
+        first_metafile = None
+
+        if not self.deep_search:
+            metafile = next(self._get_metafile_names(filename))
+            return self._set_pager_info_raw(filename, update_dict, metafile)
+
+        for i, metafile in enumerate(self._get_metafile_names(filename)):
+            if i == 0:
+                first_metafile = metafile
+
+            csvfile = None
+            try:
+                csvfile = open(metafile, "r")
+            except:
+                # .paperinfo file doesn't exist... look for another one.
+                pass
+            else:
+                reader = csv.reader(csvfile, skipinitialspace=True)
+                for row in reader:
+                    name, year, title, authors, url = row
+                    if name in valid:
+                        return self._set_pager_info_raw(filename, update_dict,
+                                metafile)
+            finally:
+                if csvfile:
+                    csvfile.close()
+
+        # No .paperinfo file found, so let's create a new one in the same path
+        # as the given file.
+        if first_metafile:
+            return self._set_pager_info_raw(filename, update_dict, first_metafile)
+
+    def _set_pager_info_raw(self, filename, update_dict, metafile):
+        valid = (filename, basename(filename))
+
+        try:
+            with open(metafile, "r") as infile:
+                reader = csv.reader(infile, skipinitialspace=True)
+                rows = list(reader)
+        except IOError:
+            rows = []
+
+        with open(metafile, "w") as outfile:
+            writer = csv.writer(outfile)
+            found = False
+
+            # Iterate through all rows and write them back to the file.
+            for row in rows:
+                if not found and row[0] in valid:
+                    # When finding the row that corresponds to the given filename,
+                    # update the items with the information from update_dict.
+                    self._fill_row_with_ostruct(row, update_dict)
+                    found = True
+                writer.writerow(row)
+
+            # If the row was never found, create a new one.
+            if not found:
+                row = [basename(filename), None, None, None, None]
+                self._fill_row_with_ostruct(row, update_dict)
+                writer.writerow(row)
+
+    def _fill_row_with_ostruct(self, row, update_dict):
+        for key, value in update_dict.items():
+            if key == "year":
+                row[1] = value
+            elif key == "title":
+                row[2] = value
+            elif key == "authors":
+                row[3] = value
+            elif key == "url":
+                row[4] = value
 
     def _get_metafile_content(self, metafile):
         if metafile in self.metafile_cache:
             return self.metafile_cache[metafile]
         else:
             if exists(metafile):
-                reader = csv.reader(open(metafile, "r"),
-                        skipinitialspace=True)
+                reader = csv.reader(open(metafile, "r"), skipinitialspace=True)
 
                 entries = list(entry for entry in reader if len(entry) == 5)
                 self.metafile_cache[metafile] = entries
diff --git a/ranger/gui/widgets/browsercolumn.py b/ranger/gui/widgets/browsercolumn.py
index 3757af4b..12523648 100644
--- a/ranger/gui/widgets/browsercolumn.py
+++ b/ranger/gui/widgets/browsercolumn.py
@@ -310,7 +310,7 @@ class BrowserColumn(Pager):
             if use_linemode == "filename":
                 infostring = self._draw_infostring_display(drawn, space)
             elif use_linemode == "papertitle":
-                if paperinfo:
+                if paperinfo and paperinfo.authors:
                     authorstring = paperinfo.authors
                     if ',' in authorstring:
                         authorstring = authorstring[0:authorstring.find(",")]
urce in trace' href='/akkartik/mu/commit/subx/039debug.cc?h=hlt&id=02684e8d7cb5292867ebcdea06879b94ba63aef4'>02684e8d ^
47a15082 ^
02684e8d ^


3ae1fd00 ^
02684e8d ^




3ae1fd00 ^

02684e8d ^





f7f0d631 ^
e92fa89e ^


f7f0d631 ^









120a7408 ^
f7f0d631 ^
120a7408 ^
f7f0d631 ^










1f0f3813 ^
f7f0d631 ^
02684e8d ^
28746b36 ^

























8ba17d83 ^



a2593892 ^

8ba17d83 ^
a2593892 ^
8ba17d83 ^





02684e8d ^







































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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175