Beispiel #1
0
    def update(self, sorting=None):
	''' Updates the Entries stored in the database '''
	if self.key.url [0] != 'file':
	    raise IOError, "can't update the remote database `%s'" % self.key

	name = self.key.url[2]
        if Config.get('base/directsave').data:
            if Config.get('base/backup').data:
                copyfile(name, name + '.bak')
            namefile = open(name, 'w')
            iterator = Selection.Selection(sort=sorting).iterator(self.iterator())
	    Open.bibwrite(iterator, out=namefile, how=self.id, database=self)
            namefile.close ()
        else:
            # create a temporary file for the new version
            tmp = os.path.join(os.path.dirname(name),
                               '.#' + os.path.basename(name))
            tmpfile = open(tmp, 'w')

            iterator = Selection.Selection(sort=sorting).iterator(self.iterator())
	    Open.bibwrite(iterator, out=tmpfile, how=self.id, database=self)
	    tmpfile.close()

	    # if we succeeded, and backup is set, backup file
            if Config.get('base/backup').data:
                os.rename(name, name + '.bak')
	    # ...and bring new version online
            os.rename(tmp, name)
        return
Beispiel #2
0
    def setUp(self):

        Config.parse_directory(os.path.abspath("../ConfDir"))
        Config.load_user()
        self.db = DataBase("//localhost/Internal")
        self.output = cStringIO.StringIO()
        self.mapping = Config.get("ovid/mapping").data
Beispiel #3
0
    def __parsefile__(self):
	self.dict = {}
	# Ouvrir le fichier associe
	self.parser = _bibtex.open_file(Open.url_to_local(self.key),
                                        Config.get ('bibtex/strict').data)
	# Incorporer les definitions de l'utilisateur
	if not Config.get('bibtex+/override').data:
	    user = Config.get('bibtex/macros').data
	    valid = re.compile('^\w+$')
	    for k in user.keys():
		if not valid.match(k):
		    raise TypeError, _("key `%s' is malformed") % k
		_bibtex.set_string(self.parser, k,
                                   _bibtex.reverse(_base_fieldtype[Text],
                                                   Config.get('bibtex+/braces').data,
                                                   user [k][0]))
	finished = 0
	errors = []

	# Creer la base de cles
	iter = BibtexIterator(self, self.parser)
        try:
            entry = iter.first()
            if entry is not None:
                if entry.key is None:
                    self.add(entry)
                else:
                    if self.dict.has_key(entry.key):
                        errors.append(_("%s:%d: key `%s' already defined") % (
                            str(self.key), entry.line, entry.key.key))
                    else:
                        self.dict [entry.key] = entry
        except Exceptions.ParserError, err:
            errors.append (str (err))
Beispiel #4
0
 def page3_add (self, *args):
     m, iter = self.s3a.get_selected()
     if iter:
         p = self.sfm.convert_iter_to_child_iter(None, iter)
         field = self.fm[p] [3]
         self.current_entry.optional.append(field)
         self.sm.append ((field.name, False, field.name, field))
         Config.set_and_save('base/entries', self.entries)
     self.check()
Beispiel #5
0
 def page2_rm (self, *args):
     self.check()
     m, iter = self.s2.get_selected()
     if iter:
         p = self.sem.convert_iter_to_child_iter(None, iter)
         del self.entries [self.em[p] [2]]
         self.em.remove(p)
         Config.set_and_save('base/entries', self.entries)
         self.check()
Beispiel #6
0
 def page1_rm (self, *args):
     m, iter = self.s1.get_selected()
     if iter:
         p = self.sfm.convert_iter_to_child_iter(None, iter)
         #print 'SELF:FM[P][2]:', self.fm[p] [2]
         try: del self.fields [self.fm[p][2]]
         except KeyError: pass
         self.fm.remove(p)
         Config.set_and_save('base/fields', self.fields)
         self.check()
Beispiel #7
0
def width (field):
    ''' return the graphical width of a field given its name '''
    
    ht = Config.get ('base/fields').data

    field = string.lower (field)
    
    if ht.has_key (field) and hasattr (ht [field], 'width'):
        return ht [field].width
    else:
        return Config.get ('gnomeui/default').data [0]
Beispiel #8
0
    def apply (self, * arg):
        if not self.changed: return
        
        result = self.get ()
        
        Config.set_and_save ('base/fields', result)

        if self.parent:
            self.parent.warning (_("Some changes require to restart Pybliographic\n"
                                   "to be correctly taken into account"))
        return
Beispiel #9
0
 def update (self, force=False, *args):
     """Call this with an additional parameter
     force=True if the widget does nor use changed()."""
     #print 'UPDATE:', self.key, self.get(), force
     if not (force or self.state ()): return 0
     if self.key:
         Config.set_and_save (self.key, self.get ())
         self.prop.changed()
     else:
         self.parent.update(force = force)
     return False
Beispiel #10
0
def _check_default (item, value, user):
    """ If the entries are updated, update the default type with the new entry """
    
    dfl = Config.get ('base/defaulttype').data
    if dfl is None: return 1

    value = value [string.lower (dfl.name)]
    
    if dfl == value:
        Config.set ('base/defaulttype', value)
        
    return 1
Beispiel #11
0
 def page3_rm (self, *args):
     m, iter = self.s3b.get_selected()
     if iter:
         p = self.ssm.convert_iter_to_child_iter (None, iter)
         field = self.sm[p] [3]
         if self.sm[p] [1]:
             self.current_entry.mandatory.remove(field)
         else:
             self.current_entry.optional.remove(field)
         del self.sm [p]
         Config.set_and_save('base/entries', self.entries)
     self.check()
Beispiel #12
0
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] [-5:] != '.ovid': return

    file = open (Open.url_to_local (url))

    return  OvidLike.OvidLike (
        file,
        Config.get ('ovid/mapping').data,
        Config.get ('ovid/deftype').data
        )
Beispiel #13
0
 def toggle_mandatory (self, rend, path):
     p = self.ssm.convert_path_to_child_path(path)
     iter = self.sm.get_iter(p)
     field = self.sm[iter][3]
     x = self.sm.get_value (iter, 1)
     self.sm.set_value(iter, 1, not x)
     if x:
         self.current_entry.mandatory.remove(field)
         self.current_entry.optional.append(field)
     else:
         self.current_entry.optional.remove(field)
         self.current_entry.mandatory.append(field)
     self.entries [self.current_entry.name.lower()] = self.current_entry
     Config.set_and_save ('base/entries', self.entries)
     self.check()
Beispiel #14
0
 def on_name2_changed (self, *args):
     sel = self.entries2.get_selection()
     m, iter = sel.get_selected()
     if iter:
         p = self.sem.convert_iter_to_child_iter(None, iter)
         newname = self.name2.get_text()
         try: del self.entries [self.em[p][2]]
         except KeyError: print 'Keyerror', self.em[
             p] [2], self.entries.keys()
         self.em[p][1].name = newname
         self.em[p][0] = newname
         self.em[p][2] = newname.lower()
         self.entries[newname.lower()] = self.em[p][1]
         Config.set_and_save ('base/entries', self.entries)
     self.check()
Beispiel #15
0
    def __init__ (self, dtype, props, key=None, parent=None,  help_text=''):
        BaseConfig.__init__ (self, dtype, props, key, parent)
        self.w = gtk.VBox (spacing = 6)
        self.sub = []

        self.resize = False

        for sub in dtype.subtypes:
            w = sub.w (sub, props, parent=self)
            self.sub.append (w)
            
            if w.resize:
                self.resize = True

        for w in self.sub:
            self.w.pack_start (w.w,
                               expand = w.resize,
                               fill   = w.resize)
        
        if key:
            data = Config.get (key).data
            i = 0
            for item in data:
                self.sub [i].set (item)
                i = i + 1
        self.w.show_all ()
        return
Beispiel #16
0
    def __init__ (self, dtype, props, key=None, parent=None,  help_text=''):
        BaseConfig.__init__ (self, dtype, props, key, parent)

        if key:
            data = str(Config.get (key).data)
        else: data = ''

        self.m = gtk.combo_box_new_text ()
        self.items = dtype.get ()

        ix = 0
        select = -1
        for i in self.items:
            self.m.append_text (str (i))
            if data == str(i):
                select = ix
            ix += 1
        
        self.m.set_active (select)
        self.m.connect ('changed', self.update, True)
        
        self.w = gtk.HBox(spacing = 12)
        self.w.pack_start(self.m, True, True, padding=12)
        self.w.show_all ()
        return
Beispiel #17
0
def get_viewables (item, priority=[]):
    """Return a list of possible viewable resources for an item"""
    R = userexit.resource_viewer_select (Director, item)
    if R: return R
    viewables = Config.get (config_fields).data 
    return [ (key, item[key], item [key].get_url ()) for key
	     in priority + viewables if item.has_key (key)]
Beispiel #18
0
def bibwrite (iter, out = None, how = None, database=None):
    ''' writes a descriptions of a list of entries '''

    if database and Config.get ('bibtex/keep-preamble').data:
	preamble = database.get_metadata ('bibtex-preamble', [])
    else:
	preamble = []
	
    # default output
    out = out or sys.stdout

    if how == None:
	entry = iter.first ()
	while entry:
	    out.write (str (entry) + "\n")
	    entry = iter.next ()

	return

    writer = get_by_name (how, 'write')

    if writer is None:
	raise IOError, "type `%s' does not specify write method" % how
    writer (iter, out, preamble=preamble)
    return
Beispiel #19
0
 def init_page_1 (self):
     
     self.fields1 = self.xml.get_widget('f_list_1')
     rend = gtk.CellRendererText()
     col = gtk.TreeViewColumn(_('Name'), rend, text = 0)
     self.fields1.append_column(col)
     rend = gtk.CellRendererText()
     col = gtk.TreeViewColumn(_('Type'), rend, text = 1)
     self.fields1.append_column(col)
     
     self.fm = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING,
                             gobject.TYPE_STRING, gobject.TYPE_PYOBJECT)
     self.sfm = gtk.TreeModelSort(self.fm)
     self.sfm.set_sort_column_id(2, gtk.SORT_ASCENDING)
     self.fields1.set_model(self.sfm)
     self.s1 = self.fields1.get_selection()
     self.s1.connect ('changed', self.list_1_select)
     self.fields = copy.copy (Config.get ('base/fields').data)
     for key, item in  self.fields.iteritems():
         self.fm.append((item.name,
                         _typename [item.type], key, item)) 
     
     self.name1 = self.xml.get_widget('name1')
     self.menu1 = self.xml.get_widget('type1')
     menu = gtk.Menu ()
     self.menu1.set_menu (menu)
     self.menu_items = _typename.keys ()
     for item in self.menu_items:
         Utils.popup_add (menu, _typename [item], self.select_menu, item)
     self.menu1.set_history (0)
     self.current_menu = self.menu_items [0]
     self.check()
Beispiel #20
0
def _set_entries (entries):
    desc = Config.get ('base/fields').data
    ent  = {}
    
    for e in entries.keys ():
        d = Types.EntryDescription (e)

        d.mandatory = \
                    map (lambda x, desc=desc: desc [x], entries [e] [0])
        d.optional  = \
                   map (lambda x, desc=desc: desc [x], entries [e] [1])

        ent [string.lower (e)] = d

    Config.set ('base/entries', ent)
    return
Beispiel #21
0
def justification (field):
    ''' returns the representative widget of a field '''
    
    ht = Config.get ('base/fields').data

    field = string.lower (field)
    
    if not ht.has_key (field):
        return Config.get ('gnomeui/default').data [1]
    
    if hasattr (ht [field], 'justification'):
        return ht [field].justification
    
    if hasattr (ht [field].type, 'justification'):
        return ht [field].type.justification

    return Config.get ('gnomeui/default').data [1]
Beispiel #22
0
def _text_get ():

    v = Config.get ('base/fields').data

    fields = [ x.name.lower() for x in v.values() if
               x.type is Fields.Text or x.type is Fields.LongText ]
    fields.sort ()

    return fields
Beispiel #23
0
def get_field (field):
    ''' return a field description given its name '''
    
    fields = Config.get ("base/fields").data

    if fields.has_key (field):
        return fields [field]

    return FieldDescription (field)
Beispiel #24
0
    def __init__(self, key, fieldtype, content, parser, line):
	Base.Entry.__init__(self, key, fieldtype, content)

	self.__text = {}
	self.parser = parser
        self.line   = line
        
	# Check for date fields
	datefields = Config.get ('bibtex/datefield').data
	convert    = Config.get ('bibtex/months').data
	for field in datefields.keys():
	    (yearfield, monthfield) = datefields[field]
	    
	    # check if this entry provides a date field
	    if not self.has_key (yearfield):
                continue

            day   = None
	    month = None
            try:
                year = int(self[yearfield].text)
            except ValueError:
                break
            
	    del self[yearfield]

	    if self.has_key(monthfield):
		mt = _bibtex.get_native(self.dict[monthfield])
		if convert.has_key(mt):
		    month = convert[mt]
		    del self[monthfield]
                else:
                    df = extended_date.match(mt)
                    if df:
                        (gd, gm) = (df.group(1), df.group(2))
                        if convert.has_key(gm):
                            month = convert[gm]
                            try:
                                day = int(gd)
                            except ValueError:
                                pass
                            del self[monthfield]
	    self[field] = Date((year, month, day))
	return
Beispiel #25
0
def widget (field):
    ''' returns the representative widget of a field '''

    default = Config.get ('gnomeui/default').data [2]
    
    ht = Config.get ('base/fields').data
    
    field = string.lower (field)

    if not ht.has_key (field):
        return default
    
    if hasattr (ht [field], 'widget'):
        return ht [field].widget
    
    if hasattr (ht [field].type, 'widget'):
        return ht [field].type.widget

    return default
Beispiel #26
0
    def __init__ (self):
        self.pin = None
        self.pout = None
        
        base = Config.get ('base/lyxpipe').data

        pin = os.path.expanduser (base + '.in')
        try:
            ans = os.stat (pin)
        except OSError, msg:
            raise IOError (_("no input pipe `%s'") % pin)
Beispiel #27
0
    def create_native(self, value):
	'''Parse text in native format.'''
	parser = _bibtex.open_string("<set_native string>", value,
                                     Config.get ('bibtex/strict').data)
	iter  = BibtexIterator(self, parser)
	entry = iter.first()
	if entry:
	    # set the entry parser to the current one, so
	    # that we keep the current string definitions
	    entry.parser = self.parser
	return entry
Beispiel #28
0
def get_entry (entry, has_default = 1):
    ''' Returns an entry description given its name '''

    entries = Config.get ("base/entries").data

    if entries.has_key (entry):
	return entries [entry]

    if has_default:
	return EntryDescription (entry)

    return None
Beispiel #29
0
    def __setitem__(self, key, value):
	# First, set the cache for free
	self.__text[key] = (value, 0)
        if isinstance(value, Date):
            return
        # then, convert as bibtex.
        if isinstance(value, Reference):
            value = string.join(map(lambda item: item.key, value.list), ', ')
	self.dict[key] = _bibtex.reverse(_fieldtype(Types.get_field(key)),
                                         Config.get('bibtex+/braces').data,
                                         value)
	return
Beispiel #30
0
def _on_multiline_select (item, multi, user):

    h = Config.get ('base/fields').data

    for k, v in multi.items ():

        if not h.has_key (k): continue
        
        if v: h [k].widget = Editor.Text
        else: h [k].widget = Editor.Entry
        
    return True