# # This file is part of Documancer (http://documancer.sf.net) # # Copyright (C) 2004 Vaclav Slavik # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # $Id: compatibility.py,v 1.4 2005/01/30 19:46:30 vaclavslavik Exp $ # # Handles upgrades to newer version # import sys, os, os.path import utils, book # ------------------------------------------------------------------------- # 0.2.3 -> 0.2.4 # ------------------------------------------------------------------------- def upgradeFrom023_win32_datadir(): olddir = os.path.expanduser('~/.documancer/') if not os.path.isdir(olddir): return newdir = utils.getConfigDir() if os.path.isdir(newdir): return print 'moving %s to %s...' % (olddir, newdir) import shutil shutil.move(olddir, newdir) def upgradeFrom023_bookfiles(): from gettext import gettext from providers import providersNameToId cfg = utils.config() cfg.SetPath('/Books') allBooks = cfg.Read('/Books/list') if allBooks == '': return allBooks = allBooks.split(':') def loadBook(cfg): title = cfg.Read('title') provider = providersNameToId[gettext(cfg.Read('provider'))] attr = {} bookmarks = {} cfg.SetPath('attr') cont, name, index = cfg.GetFirstEntry() while cont: attr[name] = cfg.Read(name) cont, name, index = cfg.GetNextEntry(index) bk = book.Book(book.BookData(title, provider, attr)) cfg.SetPath('../bookmarks') cont, name, index = cfg.GetFirstGroup() while cont: bk.bookmarks[cfg.Read('%s/title' % name)] = cfg.Read('%s/url' % name) cont, name, index = cfg.GetNextGroup(index) return bk print 'converting book definitions from 0.2.3 to 0.2.4 format...' book.books = {} for name in allBooks: if name == '': continue cfg.SetPath('/Books/%s' % name) bk = loadBook(cfg) book.books[bk.title] = bk book.saveBooks() cfg.SetPath('/') cfg.DeleteGroup('Books') def upgradeFrom023_indexes(): print 'deleting old cache files in 0.2.3 format...' cdir = utils.getConfigDir() + 'indexes/' if not os.path.isdir(cdir): return import shutil shutil.rmtree(cdir) def upgradeFrom023(): if sys.platform == 'win32': upgradeFrom023_win32_datadir() upgradeFrom023_bookfiles() upgradeFrom023_indexes() # ------------------------------------------------------------------------- # Upgrades handling # ------------------------------------------------------------------------- CURRENT_VERSION = '0.2.4' def upgrade(): """Upgrade as needed.""" modified = 0 cfg = utils.config() lastVersion = cfg.Read('/Backend/cfg_version', '0.2.3') if lastVersion == '0.2.3': upgradeFrom023() modified = 1 if modified: cfg.Write('/Backend/cfg_version', CURRENT_VERSION) cfg.Flush()