Esempio n. 1
0
    def __init__ (self, parent = None):

        Utils.GladeWindow.__init__ (self, parent)

        # Fill the output format drop-down menu
        menu = gtk.Menu ()
        self._w_menu.set_menu (menu)
        
        outlist = Autoload.available ('output')
        outlist.sort ()
        
        for avail in outlist:
            Utils.popup_add (menu, avail, self._menu_select, avail)

        self._w_menu.set_history (0)
        self.menu_item = outlist [0]

        self._w_style_entry.set_default_path (FormatDialog.style)
        self._w_style.set_text (FormatDialog.style)

        if FormatDialog.output:
            self._w_output_entry.set_default_path (FormatDialog.output)
            self._w_output.set_text (FormatDialog.output)
        
        self._w_format.show ()
        return
Esempio n. 2
0
    def __init__ (self, parent = None, has_auto = True):

        Utils.GladeWindow.__init__ (self, parent)

        liststore = gtk.ListStore (gobject.TYPE_STRING)
        menu = self._w_combobox
        menu.set_model (liststore)
        cell = gtk.CellRendererText()
        menu.pack_start(cell, True)
        menu.add_attribute(cell, 'text', 0)

        liste = Autoload.available ('format')
        liste.sort ()

        self.formats = [ None ]

        if has_auto:
            iter = liststore.append ()
            liststore.set (iter, 0, _(' - According to file suffix - '))
            self.ftype = None
        else:
            self.ftype = liste [0]

        for avail in liste:
            iter = liststore.append ()
            liststore.set (iter, 0, avail)

        self.formats += liste

        menu.set_active (0)
        menu.connect ("changed", self.menu_select)
        return
Esempio n. 3
0
def get_by_regexp (entity, method):
    ''' returns a specific field of the given entity '''

    meth = Autoload.get_by_regexp ("format", entity)

    if meth and meth.data.has_key (method):
	return meth.data [method]

    return None
Esempio n. 4
0
    def _on_validate (self, * arg):

        style  = self._w_style_entry.get_full_path (False)
        output = self._w_output_entry.get_full_path (False)

        FormatDialog.style  = style
        FormatDialog.output = output
        
        format = Autoload.get_by_name ('output', self.menu_item).data

        if style is None or output is None: return
        self._w_format.destroy ()

        self.issue ('format-query', style, format, output)
        return
Esempio n. 5
0
def format (database, style, output, file = sys.stdout, id = 'Bibliography'):
	
	output = Autoload.get_by_name ("output", output).data
	
	url = None
	style = os.path.splitext (style) [0]
	if os.path.exists (style + '.xml'):
		url = Fields.URL (style + '.xml')
	else:
		from Legacy import version
		full = os.path.join (version.pybdir, 'Styles', style)
		full = full + '.xml'
		if os.path.exists (full): url = Fields.URL (full)

	Utils.generate (url, output, database, database.keys (), file)
	return
Esempio n. 6
0
def bibopen (entity, how = None):
    ''' Generic function to open a bibliographic database '''

    def simple_try (url, how):
	# url is Fields.URL instance, only to be passed to opener
	base = None

	if how == None:
	    listedmethods = Autoload.available ("format")

	    for method in listedmethods:
		opener = get_by_name (method, 'open')
		if opener:
		    base = opener (url, 1)
		    if base is not None:
			return base
	    return None

	opener = get_by_name (how, 'open')

	if opener:
	    base = opener (url, 0)
	else:
	    raise Exceptions.FormatError (_("method `%s' provides no opener") % how)

	return base

    # Consider the reference as an URL: url is an Fields.URL instance
    url = Fields.URL (entity)

    if url.url [0] == 'file' and not os.path.exists (url.url [2]):
	raise Exceptions.FileError (_("File `%s' does not exist") % url.get_url ())

    # eventually load a new module
    if how is None:
	handler = Autoload.get_by_regexp ("format", url.get_url ())
	if handler:
	    how = handler.name

    base = simple_try (url, how)

    if base is None:
	raise Exceptions.FormatError (_("don't know how to open `%s'") % entity)

    return base
Esempio n. 7
0
    def simple_try (url, how):
	# url is Fields.URL instance, only to be passed to opener
	base = None

	if how == None:
	    listedmethods = Autoload.available ("format")

	    for method in listedmethods:
		opener = get_by_name (method, 'open')
		if opener:
		    base = opener (url, 1)
		    if base is not None:
			return base
	    return None

	opener = get_by_name (how, 'open')

	if opener:
	    base = opener (url, 0)
	else:
	    raise Exceptions.FormatError (_("method `%s' provides no opener") % how)

	return base
Esempio n. 8
0
    def configure (self):
        fmeth = {}
        
        module = None
        for mod in self.config:
            module = Autoload.get_by_name ('style', mod.module).data
            if module is None:
                raise RuntimeError, "unknown module `%s'" % mod.module

            for item in mod.data:
                if item.att.has_key ('method'):
                    meth = item.att ['method']
                    if module.has_key (item.data):
                        self.methods [meth] = module [item.data]
                    continue
                
                if item.att.has_key ('field'):
                    field = item.att ['field']
                    if module.has_key (item.data):
                        fmeth [field] = module [item.data]
                    continue

        self.format.meth = fmeth
        return
Esempio n. 9
0
            self.out.write ('<i>%s</i>' % text)
        elif style == 'emph':
            self.out.write ('<em>%s</em>' % text)
        else:
            self.out.write (text)

    def start_group (self, id, table = None):
        self.out.write ('<dl>\n')
        return
    
    def end_group (self):
        self.out.write ('</dl>\n')
        self.out.write ('<p align="right"><small>')
        self.out.write ('Generated by Pybliographer')
        self.out.write ('</small></p>\n')
        return

    def start (self, key, entry):
        if key is None: key = self.next_key ()
        
        self.out.write ('<dt>[%s]<dd>' % key)
        return

    def separator (self):
        self.out.write (" ")
        return

    
Autoload.register ('output', 'HTML', HTML)

Esempio n. 10
0
# adjust parameters to the chosen style
if spstyle == 'abbrvau':
    sep = '; '
    format = 'textau'

elif spstyle == 'abbrvnum':
    sep = ', '
    format = 'textnum'
else:
    sep = ', '
    format = 'text'


# get the specified output
output = Autoload.get_by_name ('output', format)

if output is None:
    error (_("unknown output format `%s'") % format)



reffile = outfile + '.ref'

if os.path.exists(outfile):
    error (_("File already exists: `%s'") % outfile)

if os.path.exists(reffile):
    error (_("A file with the same name already exists: `%s'") % reffile)

textfile = args [0]
Esempio n. 11
0
    def __init__(self, title = _("File"),
                 modal = True, has_auto = True, is_save = False,
                 directory = None, show_type=True):

        gtk.FileChooserDialog.__init__ (self)

        accelerator = gtk.AccelGroup ()
        self.add_accel_group (accelerator)

        b = self.add_button (gtk.STOCK_OK, gtk.RESPONSE_OK)
        b.add_accelerator ('clicked', accelerator, gtk.keysyms.Return, 0, 0)

        b = self.add_button (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT)
        b.add_accelerator ('clicked', accelerator, gtk.keysyms.Escape, 0, 0)

        if is_save:
            self.set_action(gtk.FILE_CHOOSER_ACTION_SAVE)

        self.set_local_only (False)

        self.set_title (title)
        
        if directory:
            self.set_current_folder (directory)
            
        elif self.defaultdir:
            self.set_current_folder (self.defaultdir)
        
            
        self.ret = None
	self.ftype = None
	
	if show_type:
	    # type selector
	    hbox = gtk.HBox ()
	    hbox.set_spacing (5)
	    hbox.set_border_width (5)
	    hbox.pack_start (gtk.Label (_("Bibliography type:")),
			     expand = False, fill = False)

	    self.menu = gtk.combo_box_new_text ()

	    hbox.pack_start (self.menu)

	    self.set_extra_widget (hbox)

	    # menu content

	    liste = Autoload.available ('format')
	    liste.sort ()

	    self.formats = []

	    if has_auto:
		self.menu.append_text (_(' - According to file suffix - '))
		self.ftype = None
                self.formats.append(None)
                
	    else:
		self.ftype = liste [0]

	    for avail in liste:
		self.menu.append_text (avail)

	    self.formats += liste

	    self.menu.set_active (0)
	    self.menu.connect ("changed", self.menu_select)

	    hbox.show_all ()
        return
Esempio n. 12
0
def _get_keytypes ():
    return Autoload.available ('key')
Esempio n. 13
0
if missing:
    # warn the user that some entries were not found
    print _("pybtex: warning: the following keys were not resolved").encode (charset)
    print '	' + string.join (missing, '\n	') + '\n'

if style is None:
    # If the LaTeX document declares no style...
    error (_("no style defined"))

# --------------------------------------------------
# generate the latex bibliography
# --------------------------------------------------

# Create a formatter that writes in the .bbl file
formatter = Autoload.get_by_name ('output', 'LaTeX').data

# Search style in local path and standard installation
url = None

if os.path.exists (style + '.xml'):
    url = Fields.URL (style + '.xml')
else:

    from Legacy import version
    full = os.path.join (version.pybdir, 'Styles', style)
    full = full + '.xml'
    if os.path.exists (full): url = Fields.URL (full)

if not url:
    error (_("can't find style `%s'") % style)
Esempio n. 14
0
    

def opener (url, check):

        base = None
        if (not check) or (url.url [2] [-4:] == '.isi'):
                base = Isifile (url)
        return base


def iterator (url, check):
        ''' This methods returns an iterator that will parse the
        database on the fly (useful for merging or to parse broken
        databases '''

        if check and url.url [2] [-4:] != '.isi': return
        
        return IsifileIterator (open (Open.url_to_local (url), 'r'))

Autoload.register ('format', 'Isifile', {'open': opener,
                                         'write': writer,
                                         'iter': iterator})



### Local Variables:
### Mode: python
### py-master-file : "ut_Isi.py"
### End:

Esempio n. 15
0
        continue
    
    if opt == '-F' or opt == '--footer':
        footer = value
        continue

    if opt == '-o' or opt == '--output':
        try:
            outfile = open (value, 'w')
        except IOError, err:
            error (_("can't open `%s': %s") % (value, str (err).decode (charset)))
        continue

    if opt == '-l' or opt == '--list':
        try:
            list = Autoload.available (value)
        except KeyError:
            error (_("unknown list `%s'") % value)
            
        if list:
            print (_("pybformat: available values for `%s':") % value).encode (charset)
            print "  " + string.join (list, ", ")
            sys.exit (0)
        else:
            warning (_("empty value list `%s'") % value)
            sys.exit (0)
            
    if opt == '-h' or opt == '--help':
        usage ()
        sys.exit (0)
        continue
Esempio n. 16
0
from Legacy import Fields, Autoload
from Legacy.Style import Utils
import sys

db = bibopen(sys.argv[2])
keys = db.keys()
keys.sort()
url = Fields.URL(sys.argv[3])

Utils.generate(url, Autoload.get_by_name("output", sys.argv[4]).data, db, keys, sys.stdout)
Esempio n. 17
0
 def generate_key(self, entry):
     # call a key generator
     keytype = Config.get('base/keyformat').data
     return Autoload.get_by_name('key', keytype).data(entry, self)
Esempio n. 18
0
    
    if table.has_key (key):
	suff = ord ('a')
	
        while table.has_key (key):
            suff = suff + 1
            
            if suff > ord ('z'):
                suff = ord ('a')
                base = base + 'a'

            key  = Key.Key (table, base + chr (suff))
            
    return Key.Key (table, key)

Autoload.register ('key', 'Default', generate_key)


class StringStream:
    ''' This class simulates a stream and stores it into a simple
    string. '''

    def __init__ (self):
        self.text = ''
        return

    def write (self, text):
        self.text = self.text + text
        return

    
Esempio n. 19
0
        pass

    def end_group (self):
        self.out.write ("\n")
        pass

    def start (self, key, entry):
        if key is None: key = self.next_key ()

        text = ('[%s] ' % key)
        self.write (text)
        extra = 16 - len (text)
        if extra > 0:
            self.write (' ' * extra)
        return
    
    def write (self, text, style = None):
        self.out.write (text)
        return

    def separator (self):
        self.write (" ")
        return
    
    def end (self):
        self.write ("\n")
        return
    

Autoload.register ('output', 'raw', TextFormat)
Esempio n. 20
0
    return author_desc(entry, coding, 0, 0)


def initials_authors(entry, coding):
    return author_desc(entry, coding, 1, 0)


def first_last_initials_authors(entry, coding):
    return author_desc(entry, coding, 1, -1)


def last_first_initials_authors(entry, coding):
    return author_desc(entry, coding, 1, 1)


Autoload.register(
    "style",
    "Generic",
    {
        "first_last_full_authors": first_last_full_authors,
        "last_first_full_authors": last_first_full_authors,
        "full_authors": full_authors,
        "first_last_initials_authors": first_last_initials_authors,
        "last_first_initials_authors": last_first_initials_authors,
        "initials_authors": initials_authors,
        "string_keys": create_string_key,
        "numeric_keys": create_numeric_key,
        "european_date": standard_date,
    },
)
Esempio n. 21
0
    def end_group (self):
        self.out.write ("\n")
        pass

    def start (self, key, entry):
        if key is None: key = self.next_key ()
        
        self.data = ""
        self.key  = '[%s] ' % key
	self.key = self.key + "\n" + ' ' * self.length
        return
    
    def write (self, text, style = None):
        self.data = self.data + text
        return

    def separator (self):
        self.write (" ")
        return
    
    def end (self):
        self.data = string.strip (self.data)
        
        text = Utils.format (self.data, 79, self.length, self.length)
        self.out.write (self.key + text [self.length:] + '\n\n')
        return
    

Autoload.register ('output', 'textau', TextFormat)
Esempio n. 22
0
    return base


def iterator (url, check):
    ''' This methods returns an iterator that will parse the
    database on the fly (useful for merging or to parse broken
    databases '''

    if check and url.url [2] [-4:] != '.bib': return None

    # Ouvrir le fichier associe
    parser = _bibtex.open_file (Open.url_to_local (url),
				Config.get ('bibtex/strict').data)

    # create a database to generate correct keys
    db = Base.DataBase (url)

    return BibtexIterator (db, parser)


Autoload.register ('format', 'BibTeX', {'open'  : opener,
					'write' : writer,
					'iter'  : iterator})


### Local Variables:
### Mode: python
### py-master-file : "ut_bibtex.py"
### End:

Esempio n. 23
0
def initials_authors(entry, coding):
    return author_desc(entry, coding, 1, 0)


def first_last_initials_authors(entry, coding):
    return author_desc(entry, coding, 1, -1)


def last_first_initials_authors(entry, coding):
    return author_desc(entry, coding, 1, 1)


Autoload.register(
    "style",
    "abbrv",
    {
        "first_last_full_authors": first_last_full_authors,
        "last_first_full_authors": last_first_full_authors,
        "full_authors": full_authors,
        "first_last_initials_authors": first_last_initials_authors,
        "last_first_initials_authors": last_first_initials_authors,
        "initials_authors": initials_authors,
        "string_keys": create_string_key,
        "bibdb_keys": create_bibdb_key,
        "authoryear_keys": create_authoryear_key,
        "unsrtnum_keys": create_unsrtnum_key,
        "european_date": standard_date,
    },
)
Esempio n. 24
0
# Site configuration

from Legacy import Autoload, Config, version

from Legacy.TextUI import *

# ==================================================

import string, os

# define autoloaded formats

Autoload.preregister ('format', 'BibTeX',  'Legacy.Format.BibTeX',  '.*\.bib')
Autoload.preregister ('format', 'Ovid',    'Legacy.Format.Ovid',    '.*\.ovid')
Autoload.preregister ('format', 'Medline', 'Legacy.Format.Medline', '.*\.med')
Autoload.preregister ('format', 'Refer',   'Legacy.Format.Refer',   '.*\.refer')
Autoload.preregister ('format', 'ISIFile', 'Legacy.Format.isifile', '.*\.isi')


# define styles and outputs

Autoload.preregister ('style', 'Generic', 'Legacy.Style.Generic')
Autoload.preregister ('style', 'apa4e',   'Legacy.Style.apa4e')
Autoload.preregister ('style', 'abbrv',   'Legacy.Style.abbrv')

Autoload.preregister ('output', 'Text',    'Legacy.Output.text')
Autoload.preregister ('output', 'Raw',     'Legacy.Output.raw')
Autoload.preregister ('output', 'HTML',    'Legacy.Output.html')
Autoload.preregister ('output', 'LaTeX',   'Legacy.Output.LaTeX')
Autoload.preregister ('output', 'Textnum', 'Legacy.Output.textnum')
Autoload.preregister ('output', 'Textau',  'Legacy.Output.textau')
Esempio n. 25
0
    return author_desc (entry, coding, 0, 1)

def first_last_full_authors (entry, coding):
    return author_desc (entry, coding, 0, -1)

def full_authors (entry, coding):
    return author_desc (entry, coding, 0, 0)


def initials_authors (entry, coding):
    return author_desc (entry, coding, 1, 0)

def first_last_initials_authors (entry, coding):
    return author_desc (entry, coding, 1, -1)

def last_first_initials_authors (entry, coding):
    return author_desc (entry, coding, 1, 1)

# Line below changed
Autoload.register ('style', 'apa4e', {
    'first_last_full_authors'     : first_last_full_authors,
    'last_first_full_authors'     : last_first_full_authors,
    'full_authors'     : full_authors,
    'first_last_initials_authors' : first_last_initials_authors,
    'last_first_initials_authors' : last_first_initials_authors,
    'initials_authors' : initials_authors,
    'string_keys'      : create_string_key,
    'numeric_keys'     : create_numeric_key,
    'european_date'    : standard_date,
    })
Esempio n. 26
0
                    else:
                        w = w + 1
                        
                if w > l:
                    id = k
                    l  = w
                    
        else:
            id = 'KEY99'
            
        self.out.write ('\\begin{thebibliography}{%s}\n' % id)
        return

    def separator (self):
        self.out.write ('\n\\newblock ')
        return
    
    def end_group (self):
        self.out.write ('\\end{thebibliography}\n')
        return

    def start (self, key, entry):
        if key is None: key = self.next_key ()
        
        self.out.write ('\\bibitem[%s]{%s}\n' % (key, entry.key.key))
        return

    
Autoload.register ('output', 'LaTeX', LaTeX)