예제 #1
0
파일: cli.py 프로젝트: pkgw/bibtools
    def invoke (self, args, app=None, **kwargs):
        from .ads import search_ads

        # XXX need a real option-parsing setup
        rawmode = pop_option ('raw', args)
        large = pop_option ('l', args)

        if len (args) < 1:
            raise multitool.UsageError ('expected arguments')

        search_ads (app, parse_search (args), raw=rawmode, large=large)
예제 #2
0
파일: cli.py 프로젝트: jsoishi/bibtools
    def invoke(self, args, app=None, **kwargs):
        from .ads import search_ads

        # XXX need a real option-parsing setup
        rawmode = pop_option('raw', args)
        large = pop_option('l', args)

        if len(args) < 1:
            raise multitool.UsageError('expected arguments')

        search_ads(app, parse_search(args), raw=rawmode, large=large)
예제 #3
0
파일: cli.py 프로젝트: jsoishi/bibtools
    def invoke(self, args, app=None, **kwargs):
        from .bibtex import get_style_or_die, export_to_bibtex

        ignore_missing = pop_option('i', args)

        if len(args) != 2:
            raise multitool.UsageError('expected exactly 2 arguments')

        stylename = args[0]
        auxfile = args[1]

        style = get_style_or_die(stylename)

        # Load cited nicknames
        citednicks = set()

        for line in io.open(auxfile, 'rt'):
            if not line.startswith(r'\citation{'):
                continue

            line = line.rstrip()

            if line[-1] != '}':
                warn('unexpected cite line in LaTeX aux file: "%s"', line)
                continue

            entries = line[10:-1]

            # We provide a mechanism for ignoring raw bibtex entries
            citednicks.update([e for e in entries.split(',')
                               if not e.startswith('r.')])

        # Ready to write
        export_to_bibtex(app, style, citednicks, ignore_missing=ignore_missing)
예제 #4
0
파일: cli.py 프로젝트: pkgw/bibtools
    def invoke (self, args, app=None, **kwargs):
        from .bibtex import get_style_or_die, export_to_bibtex

        ignore_missing = pop_option ('i', args)

        if len (args) != 2:
            raise multitool.UsageError ('expected exactly 2 arguments')

        stylename = args[0]
        auxfile = args[1]

        style = get_style_or_die (stylename)

        # Load cited nicknames
        citednicks = set ()

        for line in io.open (auxfile, 'rt'):
            if not line.startswith (r'\citation{'):
                continue

            line = line.rstrip ()

            if line[-1] != '}':
                warn ('unexpected cite line in LaTeX aux file: "%s"', line)
                continue

            entries = line[10:-1]

            # We provide a mechanism for ignoring raw bibtex entries
            citednicks.update ([e for e in entries.split (',')
                                if not e.startswith ('r.')])

        # Ready to write
        export_to_bibtex (app, style, citednicks, ignore_missing=ignore_missing)
예제 #5
0
    def invoke(self, args, app=None, **kwargs):
        import re

        nocase = pop_option('i', args)
        fixed = pop_option('f', args)
        refinfo = pop_option('r', args)

        if len(args) != 1:
            raise multitool.UsageError(
                'expected exactly 1 non-option argument')

        regex = args[0]

        if refinfo:
            fields = ['arxiv', 'bibcode', 'doi', 'refdata']
        else:
            fields = ['title', 'abstract']

        try:
            # Could use the Sqlite REGEXP machinery, but it should be somewhat
            # faster to precompile the regex. Premature optimization FTW.

            if fixed:

                def rmatch(i):
                    if i is None:
                        return False
                    return regex in i
            else:
                flags = 0

                if nocase:
                    flags |= re.IGNORECASE

                comp = re.compile(regex, flags)

                def rmatch(i):
                    if i is None:
                        return False
                    return comp.search(i) is not None

            app.db.create_function('rmatch', 1, rmatch)
            q = app.db.pub_fquery('SELECT * FROM pubs WHERE ' +
                                  '||'.join('rmatch(%s)' % f for f in fields))
            print_generic_listing(app.db, q)
        except Exception as e:
            die(e)
예제 #6
0
파일: cli.py 프로젝트: pkgw/bibtools
    def invoke (self, args, app=None, **kwargs):
        import re

        nocase = pop_option ('i', args)
        fixed = pop_option ('f', args)
        refinfo = pop_option ('r', args)

        if len (args) != 1:
            raise multitool.UsageError ('expected exactly 1 non-option argument')

        regex = args[0]

        if refinfo:
            fields = ['arxiv', 'bibcode', 'doi', 'refdata']
        else:
            fields = ['title', 'abstract']

        try:
            # Could use the Sqlite REGEXP machinery, but it should be somewhat
            # faster to precompile the regex. Premature optimization FTW.

            if fixed:
                def rmatch (i):
                    if i is None:
                        return False
                    return regex in i
            else:
                flags = 0

                if nocase:
                    flags |= re.IGNORECASE

                comp = re.compile (regex, flags)

                def rmatch (i):
                    if i is None:
                        return False
                    return comp.search (i) is not None

            app.db.create_function ('rmatch', 1, rmatch)
            q = app.db.pub_fquery ('SELECT * FROM pubs WHERE ' +
                                   '||'.join ('rmatch(%s)' % f for f in fields))
            print_generic_listing (app.db, q)
        except Exception as e:
            die (e)
예제 #7
0
파일: cli.py 프로젝트: jsoishi/bibtools
    def invoke(self, args, app=None, **kwargs):
        long_listing = pop_option('l', args)

        if len(args) != 0:
            raise multitool.UsageError('expected no non-option arguments')

        if long_listing:
            n = 100
        else:
            n = 10

        pubs = app.db.pub_fquery('SELECT DISTINCT p.* FROM pubs AS p, history AS h '
                                 'WHERE p.id == h.pubid ORDER BY date DESC LIMIT ?', n)
        print_generic_listing(app.db, pubs, sort=None)