Re: Changing default key

david.evans-I9fZos/[email protected]
Newsgroups gmane.comp.gnome.apps.pybliographer
Message-ID <[email protected]>
Hello,

My last post was sent before receiving this one. Thank you for the
pre-emptive reply :-)
I've just tested my key-generating routine by putting it in .pybrc.py
instead of Utils.py, and it seems to work perfectly. Python is a
wonderful thing :-) I'd ignore my previous suggestions to modify
Utils.py, unless you really want to change the configuration for the
whole system.

my new .pybrc.py is attached, and generates keys of format
AuthorBCDYY, where Author is the surname of the first author, B,C etc
the first letters of the surnames of subsequent authors, and YY the
last two digits of the year.

Thanks again

Dave


---- Message from Frederic Gobry <[email protected]> at 2004-11-18
12:02:43 ------
>> Some other people had already answered some topics, but as I don't
know 
>> anything about the python language, I have some doubts regarding
the 
>> changed that are requested to create a new type of key.
>
>Well, a good thing would be to collect existing functions for their
>inclusion in the official distribution. 
>
>So if you've written a function, please consider sending it along
with a
>description of how it formats the key :-)
>
>> 1. We define a new type of entry code in 
>> /usr/share/pybliographer/Pyblio/Utils.py including the statement 
>> Autoload.register ("key", "MyKey", generate_my_key)
>
>Alternatively, you can write this function in ~/.pybrc.py, which has
the
>advantage of not being overwritten when you install a new version of
>pyblio.
>
>> 2. After this, we need to run pybliographic in order to change the 
>> desired new key under the preference menu.
>
>Right.
>
>> As I know, python is a scripting language (please correct me if I
am 
>> wrong) but I saw some .py.c and .py.o files. It is necessary to
perform 
>> some kind of compilation onder Utils.py after changes?
>
>These files are automatically generated by pyblio when needed. They
are
>here to improve the startup time, but you can safely ignore them and
>consider python as a scripting language.
>
>Frédéric
>
.pybrc.py (application/octet-stream, 1.5 KB)
# DAE new type of key format AuthorBCDEYY

from string import *

from Pyblio import Key, Autoload, recode

_flat = recode.recode ('latin1..flat')

def generate_key_new (entry, table):

    if   entry.has_key ('author'): aut = entry ['author']
    elif entry.has_key ('editor'): aut = entry ['editor']
    else:                          aut = ()

    if len (aut) == 0:
        global __entry
        key = 'entry-%d' % __entry
        __entry = __entry + 1
    else:
        honorific, first, last, lineage = aut [0].format ()
        key = join (split (last, ' '), '')
        nextkey = ''
        if len (aut) > 1:
            for a in aut:
                honorific, first, last, lineage = a.format ()
                nextkey = nextkey + join (map (lambda x:
                                       x [0], split (last, ' ')), '')
	nextkey = str (nextkey) [1:]
        key = key + join (nextkey, '')
        
        if entry.has_key ('date'):
            year = entry ['date'].year
            
            if year: key = key + str (year) [2:]


    base = _flat (key)
    key  = Key.Key (table, base)
    
    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', 'New', generate_key_new)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.