def save_level(self, levelname): """ Save a level to file. """ self.level.tiles = [] print "saving level:", self.levelname print "size:", self.size print "num tiles:", len(self.world.tiles) for tile in self.world.tiles: name = tile.image_name pos = tile.rect.center type = tile.collision_type if type > 1: pointlist = tile.pointlist angle = tile.angle_deg else: pointlist = None angle = None if tile != self.ball: self.level.tiles.append((name, pos, type, pointlist, angle)) self.level.ball = self.ball.rect.center ## self.level.size = self.world.size self.level.bg = self.bg self.level.size = self.size print "level saving:", self.level.size filename = os.path.join(level_dir, levelname) f = open(filename, 'wb') ## pickle.dump(self.level, f) cerealizer.dump(self.level, f)
def save_level(self): level = GameLevel() level.splines = [s.get_serialized() for s in self.splines] level.triggers = [t.get_serialized() for t in self.triggers] level.obstacles = [o.get_serialized() for o in self.obstacles] level.enemies = [e.get_serialized() for e in self.enemies] cerealizer.dump(level, open("data/%d_level.lvl" % self.level_number, "wb"))
def find_jars(self): ''' Because _find_jars is so expensive, we attempt to cache the results of running that here... See _find_jars for info on the actual logic. ''' cache_file = None if self.cache_dir and cerealizer: cache_file = os.path.join(self.cache_dir, 'chrome-map.cereal') if os.path.isfile(cache_file): f = open(cache_file, 'rb') jar_info = cerealizer.load(f) self.caboodle.chrome_map = jar_info['chrome_map'] self.caboodle.components = jar_info['components'] self.caboodle.modules = jar_info['modules'] self.caboodle.xpcom_idl_files = jar_info['xpcom_idl_files'] f.close() return self._find_jars() if cache_file: f = open(cache_file, 'wb') jar_info = {'chrome_map': self.caboodle.chrome_map, 'components': self.caboodle.components, 'modules': self.caboodle.modules, 'xpcom_idl_files': self.caboodle.xpcom_idl_files, } cerealizer.dump(jar_info, f) f.close()
def dump_shares_to_file(self, output_file): import cerealizer lperson = [] for idx_p in range(len(self.person)): lperson.append([int(x) for x in self.person[idx_p]]) cerealizer.dump(lperson, open(output_file, "wb")) print("Succesfully dumped shares to: " + str(output_file))
def getshowlist(self): try: with open(self.filename, 'rb') as readfile: showlist = cerealizer.load(readfile) except: with open(self.filename, 'wb') as newfile: cerealizer.dump([], newfile) newfile.flush() showlist = [] return showlist
def writeSettings(newsettings): """Stores the settings to a file serializing the settings dict""" dir = cacheDir if not os.path.exists(dir): os.makedirs(dir) cachefile = os.path.join(dir, 'settings') FILE = open(cachefile,'w') cerealizer.dump(newsettings, FILE) FILE.close() settings = newsettings
def export(test): filename = os.path.join(os.path.dirname(sys.argv[0]), test.lower() + ".dat") clsname = test + "_class" f = open(filename, "wb") try: cls = globals()[clsname] except KeyError: print "Test '%s' not defined." % (test) sys.exit(1) try: cerealizer.register(cls, classname=clsname) obj = cls() cerealizer.dump(obj, f) f.close() except Exception as e: print "Error exporting '%s': %s" % (test, e) sys.exit(1) print "Exported %s" % filename
def save(self, filename ): unsaved = self.neuter() try: from harmless7drl import Signature, Version f = gzip.GzipFile( filename, "wb" ) c.dump( Signature, f ) c.dump( Version, f ) c.dump( self, f ) f.close() finally: self.unneuter( unsaved )
def dumplist(self): with open(self.filename, 'wb') as outfile: cerealizer.dump(self.currentshowlist, outfile)
def saveObject( o, filename ): # overwrites without warning! f = gzip.GzipFile( filename, "wb" ) c.dump( o, f ) c.dump( o, f ) f.close()