def fix_pickle_encoding(self, old_encoding): """Do the equivalent of master/contrib/fix_pickle_encoding.py""" changes_file = os.path.join(self.basedir, "changes.pck") with open(changes_file) as fp: changemgr = pickle.load(fp) changemgr.recode_changes(old_encoding, quiet=True) with open(changes_file, "w") as fp: pickle.dump(changemgr, fp)
def make_pickle(self, *changes, **kwargs): recode_fn = kwargs.pop('recode_fn', None) # this uses the now-defunct ChangeMaster, which exists only in the # buildbot.util.pickle module cm = pickle.ChangeMaster() cm.changes = changes if recode_fn: recode_fn(cm) with open(self.changes_pickle, "wb") as f: pickle.dump(cm, f)
def saveYourself(self): for b in self.currentBuilds: if not b.isFinished: # interrupted build, need to save it anyway. # BuildStatus.saveYourself will mark it as interrupted. b.saveYourself() filename = os.path.join(self.basedir, "builder") tmpfilename = filename + ".tmp" try: with open(tmpfilename, "wb") as f: pickle.dump(self, f, -1) if runtime.platformType == 'win32': # windows cannot rename a file on top of an existing one if os.path.exists(filename): os.unlink(filename) os.rename(tmpfilename, filename) except Exception: log.msg("unable to save builder %s" % self.name) log.err()
def saveYourself(self): filename = os.path.join(self.builder.basedir, "%d" % self.number) if os.path.isdir(filename): # leftover from 0.5.0, which stored builds in directories shutil.rmtree(filename, ignore_errors=True) tmpfilename = filename + ".tmp" try: with open(tmpfilename, "wb") as f: pickle.dump(self, f, -1) if runtime.platformType == 'win32': # windows cannot rename a file on top of an existing one, so # fall back to delete-first. There are ways this can fail and # lose the builder's history, so we avoid using it in the # general (non-windows) case if os.path.exists(filename): os.unlink(filename) os.rename(tmpfilename, filename) except Exception: log.msg("unable to save build %s-#%d" % (self.builder.name, self.number)) log.err()
if len(args) == 2: changes_file = args[0] old_encoding = args[1] elif len(args) == 1: changes_file = "changes.pck" old_encoding = args[0] else: parser.error("Need at least one argument") print "opening %s" % (changes_file,) try: fp = open(changes_file) except IOError, e: parser.error("Couldn't open %s: %s" % (changes_file, str(e))) changemgr = load(fp) fp.close() print "decoding bytestrings in %s using %s" % (changes_file, old_encoding) changemgr.recode_changes(old_encoding) changes_backup = changes_file + ".old" i = 0 while os.path.exists(changes_backup): i += 1 changes_backup = changes_file + ".old.%i" % i print "backing up %s to %s" % (changes_file, changes_backup) os.rename(changes_file, changes_backup) dump(changemgr, open(changes_file, "w"))
if len(args) == 2: changes_file = args[0] old_encoding = args[1] elif len(args) == 1: changes_file = "changes.pck" old_encoding = args[0] else: parser.error("Need at least one argument") print "opening %s" % (changes_file, ) try: fp = open(changes_file) except IOError, e: parser.error("Couldn't open %s: %s" % (changes_file, str(e))) changemgr = load(fp) fp.close() print "decoding bytestrings in %s using %s" % (changes_file, old_encoding) changemgr.recode_changes(old_encoding) changes_backup = changes_file + ".old" i = 0 while os.path.exists(changes_backup): i += 1 changes_backup = changes_file + ".old.%i" % i print "backing up %s to %s" % (changes_file, changes_backup) os.rename(changes_file, changes_backup) dump(changemgr, open(changes_file, "w"))