Esempio n. 1
0
    def setUp(self):
        Registry.load_default_settings()

        s = Registry.getSchema("org.pybliographer/pubmed/0.1")
        fmt = Store.get("memory")

        self.db = fmt.dbcreate(None, s)
Esempio n. 2
0
    def testSimple(self):
        Registry.load_default_settings()

        source = pybut.src('ut_bst', 'abbrv.bst')
        o = BST.BST(open(source))

        db = Store.get('memory').dbcreate(
            None, Registry.getSchema('org.pybliographer/bibtex/0.1'))
        reader = BibTeX.Reader()
        rs = reader.parse(open(pybut.src('ut_bst', 'simple.bib')), db)
        
        state = BST.State(rs, db)
        o.Run(state)

        output = """\
\\begin{thebibliography}{1}

\\bibitem{1}
Frederic Gobry and First Last.
\\newblock This is a title.
\\newblock {\em My journal}, 12(123), 2007.

\\bibitem{2}
Frederic Gobry and First Last.
\\newblock {\em This is a title}.

\\end{thebibliography}
"""
        self.failUnlessEqual(state.output, output)
Esempio n. 3
0
    def _check (self, base):

        f = pybut.dbname ()

        s = Registry.getSchema('org.pybliographer/bibtex/0.1')
        
        db = Store.get ('file').dbcreate (f, s)

        self.parser = WithComments ('latin-1')

        rs = self.parser.parse(open(fp('%s.bib' % base)), db)
        db.rs.update(rs)
        db.save ()

        # mess a bit with the file to discard the schema
        tree = Compat.ElementTree.ElementTree(file=open(f))
        for s in tree.findall('./pyblio-schema'):
            s.clear()
        for s in tree.findall('./txo-group'):
            s.clear()

        tree.write(open(f, 'w'), encoding="utf-8")
        
        pybut.fileeq (f, fp('%s.xml' % base))

        Store.get ('file').dbdestroy (f, nobackup = True)
        return
Esempio n. 4
0
    def setUp(self):
        Registry.load_default_settings()

        s = Registry.getSchema("org.pybliographer/pubmed/0.1")
        fmt = Store.get("memory")

        self.db = fmt.dbcreate(None, s)

        self.cnx = PubMed(self.db)
        self.port = reactor.listenTCP(8000, Server())
Esempio n. 5
0
    def parse (self, file):
        schema = Registry.getSchema("org.pybliographer/wok/0.1")
        
        fd = open (file)

        self.fn = pybut.dbname ()
        self.db = Store.get('file').dbcreate (self.fn, schema)
        
        self.p = ISI.Reader()
        self.p.parse(fd, self.db)
        return
Esempio n. 6
0
    def setUp(self):
        Registry.load_default_settings()

        s = Registry.getSchema("org.pybliographer/wok/0.1")
        fmt = Store.get("memory")

        self.db = fmt.dbcreate(None, s)

        self.cnx = WOK.WOK(self.db)
        self.port = reactor.listenTCP(8000, Server())

        self.cnx.baseURL = "http://localhost:8000/esti"
        return
Esempio n. 7
0
    def setUp(self):
        Registry.load_default_settings()

        s = Registry.getSchema('org.pybliographer/crossref/0.1')
        fmt = Store.get('memory')

        self.db = fmt.dbcreate(None, s)

        self.cnx = CrossRef.DOIQuery(self.db, 'user', 'pass')
        self.cnx.baseURL = 'http://localhost:8000/query'
        
        self.port = reactor.listenTCP(8000, Server())
        return
Esempio n. 8
0
    def data_results(self, ctx, data):
        query = IRequest(ctx).args.get('q', None)
        if query is None:
            return None

        query = query[0].decode('utf-8')
        log.msg("QUERYING %r" % query, msgtype="QUERY")

        s = Registry.getSchema('org.pybliographer/pubmed/0.1')
        db = Store.get('memory').dbcreate(None, s)

        remote = PubMed.PubMed(db)
        d, rs = remote.search(query, maxhits=20)

        def success(total):
            bibtex = Adapter.adapt_schema(db, 'org.pybliographer/bibtex/0.1')
            return True, query, bibtex, total

        def failure(failure):
            return False, query, failure, 0

        d.addCallback(success).addErrback(failure)
        
        return d
Esempio n. 9
0
    def __init__(self, legacy, citator, wp):
        self.citator = citator
        schema = Registry.getSchema('org.pybliographer/bibtex/0.1')
        self.db = Store.get('memory').dbcreate(None, schema)
        self.legacy = legacy
        self.reader = BibTeX.Reader()
        # TODO: once we have per-field queries in pyblio-1.3, directly
        # search for the key instead of keeping this cache
        self.mapping = {}

        self.citator.prepare(self.db, wp, _extract_id)
        
        # pre-fill the pyblio db with the bibtex records indicated in
        # the document, in the extra field. We don't have a clean way
        # to obtain the same record id as the last time when importing
        # from bibtex, so we create a new db afresh, and shuffle
        # things in a second pass.
        tmp = Store.get('memory').dbcreate(None, schema)
        renaming = {}

        self.missing = []
        fetched = self.citator.wp.fetch()
        if fetched is None:
            return

        for pyblio_uid, name, bibtex_key in fetched:
            full_key = Key(legacy, str(bibtex_key))
            if not legacy.has_key(full_key):
                self.missing.append(bibtex_key)
                continue
            tmp_key = self._transfer_entry(tmp, full_key)
            renaming[tmp_key] = pyblio_uid
            self.mapping[full_key] = pyblio_uid

        for tmp_key, record in tmp.entries.iteritems():
            self.db.add(record, key=renaming[tmp_key])
Esempio n. 10
0
"""

import sys

from twisted.internet import reactor

from Pyblio import Registry, Store
from Pyblio.External import WOK

query, output = sys.argv[1:]

# Create a database that is capable of storing Web of Science results.
Registry.load_default_settings()

s = Registry.getSchema('org.pybliographer/wok/0.1')
fmt = Store.get('file')

db = fmt.dbcreate(output, s)

# Initialize the connection to the database
wok = WOK.WOK(db)

# Perform a search. In return, we obtain the result set that will be
# filled in with the results, and a deferred that will fire once the
# query is over.
d, rs = wok.search(query)

def success(total):
    print "wok: successfully fetched %d records" % total
    db.save()
Esempio n. 11
0
from Pyblio import Store, Registry

Registry.load_default_settings()

schema = Registry.getSchema("org.pybliographer/bibtex/0.1")
store = Store.get('file')

db = store.dbcreate('mydb.bip', schema)
Esempio n. 12
0
    def __init__(self, base):
        OneToOneAdapter.__init__(self, base)

        self.schema = Registry.getSchema('org.pybliographer/bibtex/0.1')
        return
Esempio n. 13
0
# regression testsuite for OpenOffice.org integration

from Pyblio.Cite.WP.OpenOffice import OOo
from Pyblio.Format import B, one
from Pyblio import Registry, Attribute, Store

Registry.load_default_settings()
s  = Registry.getSchema('org.pybliographer/bibtex/0.1')
db = Store.get('memory').dbcreate(None, s)

style = u'This has key ' + B[one('id')]
formatter = style(db)

# tests begin here
oo = OOo()
oo.connect()

oo.text.setString(u'')

refs = [(1, 'a', 'bibtex-a'),
        (2, 'b', 'bibtex-b')]
oo.cite(refs, None)

# check that the citations have been inserted in the document
r = oo.text.getString()
assert r == u'[a][b]', repr(r)

# check that the document can return the existing citations
r = oo.fetch()
assert r == refs, repr(r)
Esempio n. 14
0
    def __init__ (self, document, query, engine, parent=None):
        self.cell = None
        Utils.GladeWindow.__init__(self, parent)

        s = Registry.getSchema(engine.schema)
        db = Store.get('memory').dbcreate(None, s)
        self.pm = engine(db)

        self.document = document
        self.db = db
        url = Fields.URL('file:/dev/null')
        self.parser = Legacy.Format.BibTeX.DataBase(url)
        self._w_fetch.set_title(_("Results for: %s") % query)
        self.writer = BibTeX.Writer()
        # in order to display a compact form of the results, we need
        # to format them. use a mapping on top of the bibtex version.
        self.bibtex = Adapter.adapt_schema(db, 'org.pybliographer/bibtex/0.1')
        self.cite = Citator.Citator()
        self.cite.xmlload(os.path.join(
            Registry.RIP_dirs['system'], 'full.cip'))
        self.cite.prepare(self.bibtex, None)

        model = gtk.ListStore(gobject.TYPE_PYOBJECT, gobject.TYPE_STRING)
        self.cell = gtk.CellRendererText()

        l = gtk.Label()
        l.set_markup(_("Results for <i>%s</i>") % escape(query))
        column = gtk.TreeViewColumn(None, self.cell, markup=1)
        column.set_widget(l)
        l.show()

        self._w_view.append_column(column)
        self._w_view.set_model(model)

        callback = self.pm.count(query)

        self._w_progress.set_fraction(0.0)
        self._w_progress.set_text(_("Fetching results"))

        def failure(failure):
            self._w_stop.set_sensitive(False)
            if failure.check(Exceptions.QueryError):
                message = _("Failed to get results")
                secondary = str(failure.value)
            else:
                message = failure.getErrorMessage()
                secondary = failure.getTraceback()
            d = gtk.MessageDialog(self._w_fetch,
                                  gtk.DIALOG_DESTROY_WITH_PARENT,
                                  gtk.MESSAGE_ERROR, gtk.BUTTONS_OK,
                                  message)
            if secondary:
                d.format_secondary_text(secondary)
            d.run()
            d.destroy()

        def fallback(failure):
            print failure

        def done_count(total):
            self._total = total
            self._got = 0.0
            target = min(total, 100)
            def set_progress():
                if target > 0:
                    ratio = min(self._got / target, 1.0)
                else:
                    ratio = 0
                self._w_progress.set_fraction(ratio)
                self._w_progress.set_text(_("Done %d/%d (%d total)") % (
                    len(db.entries), target, self._total))
            set_progress()

            l2cb, rs = self.pm.search(query, maxhits=100)
            def _on_add(k):
                v = self.bibtex[k]
                t = HTML.generate(self.cite.formatter(v))
                model.append((k, t))
                self._got += 1
                set_progress()
            rs.register('add-item', _on_add)
            # ensure this function won't be garbage collected too
            # quickly
            self._on_add = _on_add

            def done(total):
                self._w_stop.set_sensitive(False)
                self._w_progress.set_fraction(1.0)
                self._w_progress.set_text(_("Done %d (%d total)") % (
                    len(db.entries), total))
            l2cb.addCallback(done).\
                addErrback(failure).\
                addErrback(fallback)

        callback.addCallback(done_count).\
            addErrback(failure).\
            addErrback(fallback)
Esempio n. 15
0
from twisted.internet import reactor

from Pyblio import Registry, Store, Adapter, init_logging
from Pyblio.External import PubMed

# Do you want some debug information?
#init_logging()
#log = logging.getLogger('pyblio')
#log.setLevel(logging.DEBUG)

query, output = sys.argv[1:]

# Create a database that is capable of storing Web of Science results.
Registry.load_default_settings()

s = Registry.getSchema('org.pybliographer/pubmed/0.1')

# Create a temporary in-memory database
fmt = Store.get('memory')
db = fmt.dbcreate(None, s)

# Initialize the connection to the database
remote = PubMed.PubMed(db)

# Perform a search. In return, we obtain the result set that will be
# filled in with the results, and a deferred that will fire once the
# query is over.
d, rs = remote.search(query, maxhits=20)

def success(total):
    print "pubmed: successfully fetched %d/%d records" % (len(db.entries), total)
Esempio n. 16
0
import sys, os

in_f, out_f = sys.argv[1:3]

from Pyblio.Parsers.Semantic import BibTeX
from Pyblio import Store, Registry

Registry.load_default_settings()

# This id refers to the bibtex format as known by pybliographer by
# default.
sid = "org.pybliographer/bibtex/0.1"

# Get the schema associated with the specified id
schema = Registry.getSchema(sid)

# Create a new db using this schema. We need to ensure the file does
# not exist yet.
try: os.unlink(out_f)
except OSError: pass

db = Store.get('file').dbcreate(out_f, schema)

# Import the content of the bibtex file into it
fd = open(in_f)

reader = BibTeX.Reader()
reader.parse(fd, db)

db.save()