Ejemplo n.º 1
0
    def open_document (self, url, how = None, no_name = False):

        Utils.set_cursor (self.w, 'clock')

        orig_url = Fields.URL (url)
        url = orig_url.get_url ()

        restore = False

        if orig_url.url [0] == 'file':

            name = orig_url.url [2]
            auto_save = os.path.join (os.path.dirname (name),
                            'x-pyblio-save-' + os.path.basename (name))

            if os.path.exists (auto_save):
                mod_date = os.stat (name) [stat.ST_MTIME]
                mod_date_auto = os.stat (auto_save) [stat.ST_MTIME]
                if mod_date < mod_date_auto:
                    restore = Utils.Callback (_("An autosave file was found which is newer than the original file.\nDo you want to restore it?"), self.w).answer ()

                    if restore: url = auto_save


        try:
            data = Open.bibopen (url, how = how)
            
        except (Exceptions.ParserError,
                Exceptions.FormatError,
                Exceptions.FileError), error:
            
            Utils.set_cursor (self.w, 'normal')
            Utils.error_dialog (_("Open error"), error,
                                parent = self.w)
            return
Ejemplo n.º 2
0
def find_entries (auxfile, bibtex):
    """ Parse an auxiliary file and extract the entries from the given BibTeX databases """
    
    entries, data, style = list_entries (auxfile)

    if not bibtex:
        bibtex = data

    # we have to create a Reference database to hold the entries contained in the
    # current database.
    r    = Base.DataBase (None)
    keys = copy.copy (entries)
    
    # is there something to do ?
    if len (entries) == 0: return r, style, entries
	
    # use the bibliographic databases in order of declaration
    # to solve the references
	
    for bib in bibtex:
        (root, ext) = os.path.splitext (bib)
        if not ext: ext = '.bib'
        
        # open the database
        db = Open.bibopen (root + ext)

        # as we are modifying the list of entries in this loop, we make a copy
        # of it in order to avoir strange behaviors
        orig = copy.copy (entries)
	
        # loop over the expected entries
        for e in orig:
	
            # create a key in the current database
            key = Key.Key (db, e)
            
            # does the database provide the key ?
            if db.has_key (key):
	            
                # yes, add it to the reference
                r [Key.Key (None, e)] = db [key]
                
                # and remove it from the list
                entries.remove (e)
	
        # is it finished ?
        if len (entries) == 0: break

    # return the reference on all the entries, plus the missing ones
    keys = filter (lambda x, entries = entries: not entries.count (x), keys)
    keys = map (lambda x, r = r: Key.Key (r, x), keys)

    return r, keys, style, entries
Ejemplo n.º 3
0
            if self.data.key.url [0] == 'file':
                old_file = self.data.key.url [2]
                old_auto_save = os.path.join (os.path.dirname (old_file),
                                'x-pyblio-save-' + os.path.basename (old_file))

                if os.path.exists (old_auto_save):
                    try:
                        os.remove (old_auto_save)
                    except (OSError, IOError), error:
                        Utils.set_cursor (self.w, 'normal')
                        self.w.error (_("Unable to remove autosave file `%s':\n%s") % (str (old_auto_save), str (error)))
                        return

        
        try:
            self.data = Open.bibopen (url, how = how)
                
        except (Exceptions.ParserError,
                Exceptions.FormatError,
                Exceptions.FileError), error:
                    
            Utils.set_cursor (self.w, 'normal')
            Utils.error_dialog (_("Reopen error"), error,
                                parent = self.w)
            return
            
        self.redisplay_index ()
        self._title_set ()

        self.issue ('open-document', self)
            
Ejemplo n.º 4
0
import locale
charset = locale.getlocale () [1] or 'ascii'

if len (sys.argv) < 4 or len (sys.argv) > 5:
    print _("usage: pybconvert <source>..<target> <input> [output]").encode (charset)
    sys.exit (1)


format = sys.argv [2]

try:
    source, target = string.split (format, '..')
except:
    print _("pybconvert: error: bad conversion format").encode (charset)
    sys.exit (1)


from Legacy import Open

f_in = sys.argv [3]

if len (sys.argv) == 4:
    f_out = sys.stdout
else:
    f_out = open (sys.argv [4], 'w')

database = Open.bibopen (f_in, source)
Open.bibwrite (database.iterator (), how = target, out = f_out)