summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lepus.uberspace.de>2015-01-13 14:29:43 +0100
committerhut <hut@lepus.uberspace.de>2015-01-13 14:49:36 +0100
commit90d0eb6ed3211022c3b600521aee85568b9ed905 (patch)
tree2193bbb1eaa22a6186e9489c646e2b986e8de9d1
parente0a236c01fa8fe7e5c3dbbe26d6551ff282748d9 (diff)
downloadranger-90d0eb6ed3211022c3b600521aee85568b9ed905.tar.gz
start turning ext.papermanager to core.metadata
-rw-r--r--ranger/config/commands.py6
-rw-r--r--ranger/config/rc.conf8
-rw-r--r--ranger/container/settings.py2
-rw-r--r--ranger/core/actions.py4
-rw-r--r--ranger/core/fm.py8
-rw-r--r--ranger/core/metadata.py (renamed from ranger/ext/papermanager.py)53
-rw-r--r--ranger/gui/widgets/browsercolumn.py2
7 files changed, 38 insertions, 45 deletions
diff --git a/ranger/config/commands.py b/ranger/config/commands.py
index a8813de2..5d303b86 100644
--- a/ranger/config/commands.py
+++ b/ranger/config/commands.py
@@ -1378,7 +1378,7 @@ class paper(Command):
                 col.need_redraw = True
 
     def _paper_fill_console(self, key):
-        paperinfo = self.fm.papermanager.get_paper_info(self.fm.thisfile.path)
+        paperinfo = self.fm.metadata.get_metadata(self.fm.thisfile.path)
         if key in paperinfo and paperinfo[key]:
             existing_value = paperinfo[key]
         else:
@@ -1398,11 +1398,11 @@ class paper_title(paper):
     def execute(self):
         update_dict = dict()
         update_dict[self._key] = self.rest(1)
-        self.fm.papermanager.set_paper_info(self.fm.thisfile.path, update_dict)
+        self.fm.metadata.set_metadata(self.fm.thisfile.path, update_dict)
         self._process_command_stack()
 
     def tab(self):
-        paperinfo = self.fm.papermanager.get_paper_info(self.fm.thisfile.path)
+        paperinfo = self.fm.metadata.get_metadata(self.fm.thisfile.path)
         if paperinfo[self._key]:
             return self.arg(0) + " " + paperinfo[self._key]
 
diff --git a/ranger/config/rc.conf b/ranger/config/rc.conf
index 4c8fd799..a9e1fa23 100644
--- a/ranger/config/rc.conf
+++ b/ranger/config/rc.conf
@@ -174,10 +174,10 @@ set show_selection_in_titlebar true
 # increases CPU load.
 set idle_delay 2000
 
-# When the paper manager module looks for metadata, should it only look for a
-# ".paperinfo" file in the current directory, or do a deep search and check all
-# directories above the current one as well?
-set papermanager_deep_search false
+# When the metadata manager module looks for metadata, should it only look for
+# a ".metadata.json" file in the current directory, or do a deep search and
+# check all directories above the current one as well?
+set metadata_deep_search false
 
 # ===================================================================
 # == Local Options
diff --git a/ranger/container/settings.py b/ranger/container/settings.py
index 106ef5fb..55585029 100644
--- a/ranger/container/settings.py
+++ b/ranger/container/settings.py
@@ -28,10 +28,10 @@ ALLOWED_SETTINGS = {
     'idle_delay': int,
     'max_console_history_size': (int, type(None)),
     'max_history_size': (int, type(None)),
+    'metadata_deep_search': bool,
     'mouse_enabled': bool,
     'open_all_images': bool,
     'padding_right': bool,
-    'papermanager_deep_search': bool,
     'preview_directories': bool,
     'preview_files': bool,
     'preview_images': bool,
diff --git a/ranger/core/actions.py b/ranger/core/actions.py
index 82ceeba3..c7468be9 100644
--- a/ranger/core/actions.py
+++ b/ranger/core/actions.py
@@ -52,8 +52,8 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware):
         self.garbage_collect(-1)
         self.enter_dir(old_path)
         self.change_mode('normal')
-        if self.papermanager:
-            self.papermanager.reset()
+        if self.metadata:
+            self.metadata.reset()
 
     def change_mode(self, mode):
         if mode == self.mode:
diff --git a/ranger/core/fm.py b/ranger/core/fm.py
index 816bf5f1..87c14f7a 100644
--- a/ranger/core/fm.py
+++ b/ranger/core/fm.py
@@ -20,7 +20,7 @@ from ranger.gui.ui import UI
 from ranger.container.bookmarks import Bookmarks
 from ranger.core.runner import Runner
 from ranger.ext.img_display import ImageDisplayer
-from ranger.ext.papermanager import PaperManager
+from ranger.core.metadata import MetadataManager
 from ranger.ext.rifle import Rifle
 from ranger.container.directory import Directory
 from ranger.ext.signals import SignalDispatcher
@@ -61,7 +61,7 @@ class FM(Actions, SignalDispatcher):
         self.loader = Loader()
         self.copy_buffer = set()
         self.do_cut = False
-        self.papermanager = PaperManager()
+        self.metadata = MetadataManager()
 
         try:
             self.username = pwd.getpwuid(os.geteuid()).pw_name
@@ -164,8 +164,8 @@ class FM(Actions, SignalDispatcher):
             self.notify(text, bad=True)
         self.run = Runner(ui=self.ui, logfunc=mylogfunc, fm=self)
 
-        self.settings.signal_bind('setopt.papermanager_deep_search',
-                lambda signal: setattr(signal.fm.papermanager, 'deep_search',
+        self.settings.signal_bind('setopt.metadata_deep_search',
+                lambda signal: setattr(signal.fm.metadata, 'deep_search',
                     signal.value))
 
     def destroy(self):
diff --git a/ranger/ext/papermanager.py b/ranger/core/metadata.py
index 1f258af3..7391dcc6 100644
--- a/ranger/ext/papermanager.py
+++ b/ranger/core/metadata.py
@@ -2,19 +2,12 @@
 # This software is distributed under the terms of the GNU GPL version 3.
 
 """
-A Paper Manager that reads metadata information about papers from a file.
+A Metadata Manager that reads information about files from a json database.
 
-The file is named .paperinfo and is formatted as comma-separated values.
-
-The columns are:
-1. Filename
-2. Date
-3. Title
-4. Authors
-5. URL
+The database is contained in a local .metadata.json file.
 """
 
-PAPERINFO_FILE_NAME = ".paperinfo"
+METADATA_FILE_NAME = ".metadata.json"
 DEEP_SEARCH_DEFAULT = False
 
 import csv
@@ -22,7 +15,7 @@ from os.path import join, dirname, exists, basename
 
 from ranger.ext.openstruct import OpenStruct
 
-class PaperManager(object):
+class MetadataManager(object):
     def __init__(self):
         self.metadata_cache = dict()
         self.metafile_cache = dict()
@@ -32,7 +25,7 @@ class PaperManager(object):
         self.metadata_cache.clear()
         self.metafile_cache.clear()
 
-    def get_paper_info(self, filename):
+    def get_metadata(self, filename):
         try:
             return self.metadata_cache[filename]
         except KeyError:
@@ -51,7 +44,7 @@ class PaperManager(object):
             self.metadata_cache[filename] = result
             return result
 
-    def set_paper_info(self, filename, update_dict):
+    def set_metadata(self, filename, update_dict):
         result = None
         found = False
         valid = (filename, basename(filename))
@@ -59,7 +52,7 @@ class PaperManager(object):
 
         if not self.deep_search:
             metafile = next(self._get_metafile_names(filename))
-            return self._set_paper_info_raw(filename, update_dict, metafile)
+            return self._set_metadata_raw(filename, update_dict, metafile)
 
         for i, metafile in enumerate(self._get_metafile_names(filename)):
             if i == 0:
@@ -69,28 +62,28 @@ class PaperManager(object):
             try:
                 csvfile = open(metafile, "r")
             except:
-                # .paperinfo file doesn't exist... look for another one.
+                # .metadata.json 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_paper_info_raw(filename, update_dict,
+                        return self._set_metadata_raw(filename, update_dict,
                                 metafile)
                 self.metadata_cache[filename] = result
             finally:
                 if csvfile:
                     csvfile.close()
 
-        # No .paperinfo file found, so let's create a new one in the same path
-        # as the given file.
+        # No .metadata.json file found, so let's create a new one in the same
+        # path as the given file.
         if first_metafile:
-            return self._set_paper_info_raw(filename, update_dict, first_metafile)
+            return self._set_metadata_raw(filename, update_dict, first_metafile)
 
-    def _set_paper_info_raw(self, filename, update_dict, metafile):
+    def _set_metadata_raw(self, filename, update_dict, metafile):
         valid = (filename, basename(filename))
-        paperinfo = OpenStruct(filename=filename, title=None, year=None,
+        metadata = OpenStruct(filename=filename, title=None, year=None,
                 authors=None, url=None)
 
         try:
@@ -110,8 +103,8 @@ class PaperManager(object):
                     # 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)
-                    self._fill_ostruct_with_data(paperinfo, row)
-                    self.metadata_cache[filename] = paperinfo
+                    self._fill_ostruct_with_data(metadata, row)
+                    self.metadata_cache[filename] = metadata
                     found = True
                 writer.writerow(row)
 
@@ -119,8 +112,8 @@ class PaperManager(object):
             if not found:
                 row = [basename(filename), None, None, None, None]
                 self._fill_row_with_ostruct(row, update_dict)
-                self._fill_ostruct_with_data(paperinfo, row)
-                self.metadata_cache[filename] = paperinfo
+                self._fill_ostruct_with_data(metadata, row)
+                self.metadata_cache[filename] = metadata
                 writer.writerow(row)
 
     def _get_metafile_content(self, metafile):
@@ -137,17 +130,17 @@ class PaperManager(object):
                 return []
 
     def _get_metafile_names(self, path):
-        # Iterates through the paths of all .paperinfo files that could
+        # Iterates through the paths of all .metadata.json files that could
         # influence the metadata of the given file.
-        # When deep_search is deactivated, this only yields the .paperinfo file
-        # in the same directory as the given file.
+        # When deep_search is deactivated, this only yields the .metadata.json
+        # file in the same directory as the given file.
 
         base = dirname(path)
-        yield join(base, PAPERINFO_FILE_NAME)
+        yield join(base, METADATA_FILE_NAME)
         if self.deep_search:
             dirs = base.split("/")[1:]
             for i in reversed(range(len(dirs))):
-                yield join("/" + "/".join(dirs[0:i]), PAPERINFO_FILE_NAME)
+                yield join("/" + "/".join(dirs[0:i]), METADATA_FILE_NAME)
 
     def _fill_ostruct_with_data(self, ostruct, dataset):
         # Copy data from a CSV row to a dict/ostruct
diff --git a/ranger/gui/widgets/browsercolumn.py b/ranger/gui/widgets/browsercolumn.py
index 7fe4927b..1dcfa40b 100644
--- a/ranger/gui/widgets/browsercolumn.py
+++ b/ranger/gui/widgets/browsercolumn.py
@@ -252,7 +252,7 @@ class BrowserColumn(Pager):
             paperinfo = None
             use_linemode = drawn._linemode
             if use_linemode == "papertitle":
-                paperinfo = self.fm.papermanager.get_paper_info(drawn.path)
+                paperinfo = self.fm.metadata.get_metadata(drawn.path)
                 if not paperinfo.title:
                     use_linemode = "filename"