Commit 81d84e30 by Erik Hetzner

remove old keymap stuff

parent c5e5f11f
......@@ -3,7 +3,6 @@
"""
# -*- coding: utf-8 -*-
import docutils, docutils.parsers.rst
import ConfigParser
import json
import os
import re
......@@ -18,60 +17,6 @@ from xciterst.util import html2rst
DEFAULT_CITATION_STYLE = "http://www.zotero.org/styles/chicago-author-date"
class ZoteroCitekeyMapper(object):
"""Class used for mapping citekeys to IDs."""
def __init__(self, conn, path=None):
self.conn = conn
# setup key mapping
self.citekey2zotkey = ConfigParser.SafeConfigParser()
self.citekey2zotkey.optionxform = str
if path is not None:
self.citekey2zotkey.read(os.path.relpath(path))
self.zotkey2id = {}
def __getitem__(self, citekey):
"""Get a citation id from a citekey."""
# First, get zotero key from citekey using keymap file
if self.citekey2zotkey.has_option('keymap', citekey):
# return only the first part, the real key - rest is comment
zotkey = re.match("^([0-9A-Z_]+)", self.citekey2zotkey.get('keymap', citekey)).group(1)
else:
zotkey = citekey
# now return the item id
if zotkey in self.zotkey2id:
return self.zotkey2id[zotkey]
else:
return self.batch_get([zotkey])[0]
def get_item_id_dynamic_batch(self, keys):
"""A simpler method for..."""
if len(keys) == 0: return []
data = []
for key in keys:
m = re.match(r"^([A-Z][a-z]+)([A-Z][a-z]+)?([0-9]+)?", key)
data.append([m.group(1), m.group(2), m.group(3)])
return json.loads(self.conn.methods.getItemIdDynamicBatch(data))
def get_item_id_raw_batch(self, keys):
if len(keys) == 0: return []
return json.loads(self.conn.methods.getItemIdRawBatch(keys))
def batch_get(self, keys):
local_keys = [ k for k in keys if self.conn.local_items.has_key(k) and (k not in self.zotkey2id) ]
raw_keys = [ k for k in keys if re.match(r"^[A-Z0-9]{8}$", k) and (k not in self.zotkey2id) ]
dynamic_keys = [ k for k in keys if (k not in local_keys) and (k not in raw_keys) and (k not in self.zotkey2id) ]
for k in local_keys:
self.zotkey2id[k] = "MY-%s"%(k)
for k, i in zip(raw_keys, self.get_item_id_raw_batch(raw_keys)):
self.zotkey2id[k] = i
for k, i in zip(dynamic_keys, self.get_item_id_dynamic_batch(dynamic_keys)):
self.zotkey2id[k] = i
return [ self.zotkey2id[k] for k in keys ]
class ZoteroConnection(xciterst.CiteprocWrapper):
def __init__(self, style, **kwargs):
self.local_items = {}
......@@ -110,7 +55,6 @@ class ZoteroConnection(xciterst.CiteprocWrapper):
def init(style=None):
if style is None: style = DEFAULT_CITATION_STYLE
xciterst.cluster_tracker = xciterst.ClusterTracker()
xciterst.citekeymap = zot4rst.ZoteroCitekeyMapper(xciterst.citeproc, None)
xciterst.citeproc = ZoteroConnection(style)
class ZoteroSetupDirective(docutils.parsers.rst.Directive):
......@@ -122,10 +66,8 @@ class ZoteroSetupDirective(docutils.parsers.rst.Directive):
optional_arguments = 0
has_content = False
option_spec = {'style' : docutils.parsers.rst.directives.unchanged,
'keymap': docutils.parsers.rst.directives.unchanged,
'biblio' : docutils.parsers.rst.directives.unchanged }
def run(self):
xciterst.citekeymap = ZoteroCitekeyMapper(xciterst.citeproc, self.options.get('keymap', None))
if self.options.has_key('biblio'):
xciterst.citeproc.load_biblio(self.options['biblio'])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment