예제 #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:
                shutil.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
예제 #2
0
    def autosave (self, url, how):
        ''' autosave file as x-pyblio-save-filename '''

        if self.data.key.url [0] != 'file': return False

        name = self.data.key.url [2]

        # create an autosave file
        save = os.path.join (os.path.dirname (name),
                            'x-pyblio-save-' + os.path.basename (name))

        if self.changed:

            try:
                savefile = open (save, 'w')
            except (IOError, OSError), error:
                self.w.error (_("Error during autosaving:\n%s") % error [1])
                return False

            iterator = Selection.Selection (sort = self.selection.sort)
            Open.bibwrite (iterator.iterator (self.data.iterator ()),
                           out = savefile, how = how, database=self.data)

            savefile.close ()
예제 #3
0
    def autosave (self, url, how):
        ''' autosave file as x-pyblio-save-filename '''

        if self.data.key.url [0] != 'file': return False

        name = self.data.key.url [2]

        # create an autosave file
        save = os.path.join (os.path.dirname (name),
                            'x-pyblio-save-' + os.path.basename (name))

        if self.changed:

            try:
                savefile = open (save, 'w')
            except (IOError, OSError), error:
                Utils.error_dialog_s(_("Error during autosaving:\n%s") % error [1])
                return False

            iterator = Selection.Selection (sort = Sort.Sort([Sort.KeySort()]))
            Open.bibwrite (iterator.iterator (self.data.iterator ()),
                           out = savefile, how = how, database=self.data)

            savefile.close ()
예제 #4
0
from gettext import gettext as _

import locale
charset = locale.getlocale()[1] or 'ascii'

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

format = sys.argv[2]

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

from Pyblio 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)
예제 #5
0
        if os.path.exists (url):
            if not Utils.Callback (
		_("The file `%s' already exists.\nOverwrite it ?")
		% url, parent = self.w).answer ():
                return

        try:
            file = open (url, 'w')
        except IOError, error:
            self.w.error (_("During opening:\n%s") % error [1])
            return

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

        iterator = Selection.Selection (sort = self.selection.sort)
        Open.bibwrite (iterator.iterator (self.data.iterator ()),
                       out = file, how = how, database=self.data)
        file.close ()

        # remove the old autosave object
        if self.data.key is not None and self.source_id:
            gobject.source_remove (self.source_id)

        # remove old autosave file
        if self.data.key:
            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:
예제 #6
0
import locale
charset = locale.getlocale () [1] or 'ascii'

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


format = sys.argv [2]

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


from Pyblio 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)
    
예제 #7
0
        if os.path.exists (url):
            if not Utils.Callback (
		_(u"The file “%s” already exists.\nOverwrite it?")
		% url, parent = self.w).answer ():
                return

        try:
            file = open (url, 'w')
        except IOError, error:
            Utils.error_dialog_s(_("During opening:\n%s") % error [1])
            return

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

        iterator = Selection.Selection (sort = Sort.Sort([Sort.KeySort()]))
        Open.bibwrite (iterator.iterator (self.data.iterator ()),
                       out = file, how = how, database=self.data)
        file.close ()

        # remove the old autosave object
        if self.data.key is not None and self.source_id:
            gobject.source_remove (self.source_id)

        # remove old autosave file
        if self.data.key:
            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: