import cPickle import shelve import conf import last class Data: """Data file management.""" def load(self): """Load from data file. Last books list, show_license, version; store in local vars. """ sh = shelve.open(conf.datafile) try: self.version = sh["version"] self.show_license = sh["show_license"] self.last_list = sh["last"] except KeyError: self.version = conf.__version__ self.show_license = 1 self.last_list = [] if self.version != conf.__version__: print """ Datafile %s is from an older version of PyBook; if you get strange errors, delete it and run PyBook again. """ % conf.datafile self.booklist = cPickle.load(open(conf.booklist)) def save(self): """Write data file: version, show_license, last booklist booklist.""" sh = shelve.open(conf.datafile) sh["version"] = conf.__version__ sh["show_license"] = self.show_license sh["last"] = last.lst sh.close() # vim: sts=4:ts=8:et:sw=4