def openBibFile(file): bibobj = None if file.endswith("xml"): bibobj = Bibliography() bibobj.buildRecords(file) else: from skynet.pysave import load, save try: bibobj = PySave.load(file) except Exception, error: pass
def walkForBibs(path, check=False, fields=[]): def checkFolder(args, dirname, files): import glob topdir = os.getcwd() os.chdir(dirname) allbib = args xmlfiles = [elem for elem in files if elem.endswith(".xml")] for file in xmlfiles: allbib.buildRecords(file, check, fields) os.chdir(topdir) if os.path.isfile(path): bib = Bibliography() bib.buildRecords(path, check, fields) return bib # folder, do the walk allbib = Bibliography() os.path.walk(path, checkFolder, allbib) return allbib
def loadCitation(cword): import os import pyvim.pyvim as vim import re import pygtk import gtk import os.path from pylatex.pybib import Record Record.unsetFormat() Record.setDefaults() entries = [] if "~" in cword: cword = "~" + cword.split("~")[-1] if "\cite{" in cword: # we are currently on a citation # get the entries within the citation innards = re.compile(r"cite[{](.*?)[}]").search(cword).groups()[0].strip() if innards: entries = map(lambda x: x.strip(), innards.split(",")) else: entries = [] else: # no citation, but put one in vim.appendAtWord("~\cite{}", ",", ".") cword = "~\cite{}" # build the citation import os.path if not hasattr(PyTexGlobals, "bib"): # import PyGui # filesel = PyGui.FileSelect(os.path.join(os.path.expanduser("~"), "Documents"), setBibliography, main=True) # gtk.main() from pylatex.pybib import Bibliography empty = Bibliography() empty.buildRecords(Bibliography.ENDNOTE_XML_LIB) setattr(PyTexGlobals, "bib", empty) bib = getattr(PyTexGlobals, "bib") title = "Reference at line %d" % vim.PyVimGlobals.line # title = "test" citeobj = Citation(title, bib, entries) gtk.gdk.threads_init() gtk.gdk.threads_enter() gtk.main() gtk.gdk.threads_leave() # use the citation object to generate the new reference entries = citeobj.getEntries() labels = [] for entry in entries: labels.append(str(entry.getAttribute("label"))) newtext = "" if labels: newtext = "~\cite{%s}" % ",".join(labels) vim.replace(cword, newtext)