for job_vgrid_name in job_vgrids: # Update the statistics and cache # from the job details job_vgrid_name = job_vgrid_name.upper() self.__update_statistics_from_job(name, job_vgrid_name, buildcache_dict, job_dict) # Flush cache and unlock files try: file_handle.seek(0, 0) py_pickle.dump(buildcache_dict, file_handle, 0) self.__flush() fcntl.flock(file_handle.fileno(), fcntl.LOCK_UN) file_handle.close() except Exception, err: self.__gridstat_dict = {} msg = 'gridstat::update(): %s could not be pickled! %s'\ % (buildcache_file, err) self.__logger.error(msg) return False return True if __name__ == '__main__': import sys import fnmatch
path = raw_input("Path to open: ") pickle_fd = open(path, 'rb+') obj = pickle.load(pickle_fd) elif command in ['h', 'help']: print "Valid commands include:" print "(d)isplay to display the opened pickled object" print "(e)dit to edit the opened pickled object" print "(o)pen to open a new pickle file" print "(c)lose to close the opened pickled object" print "(q)uit to quit pickle editor" elif command in ['d', 'display']: print obj elif command in ['e', 'edit']: edit = raw_input("Edit command: ") # eval(edit) eval(compile(edit, 'command-line', 'single')) dirty = True elif command in ['c', 'close', 'q', 'quit']: if dirty: flush = raw_input("Modified object not saved - save now?: ") if flush.lower() in ('y', 'yes'): pickle_fd.seek(0) pickle.dump(obj, pickle_fd) pickle_fd.close() obj = None if command in ('q', 'quit'): print "Closing" break else: print "unknown command '%s'" % command
job_dict) for job_vgrid_name in job_vgrids: # Update the statistics and cache # from the job details job_vgrid_name = job_vgrid_name.upper() self.__update_statistics_from_job( name, job_vgrid_name, buildcache_dict, job_dict) # Flush cache and unlock files try: file_handle.seek(0, 0) py_pickle.dump(buildcache_dict, file_handle, 0) self.__flush() fcntl.flock(file_handle.fileno(), fcntl.LOCK_UN) file_handle.close() except Exception, err: self.__gridstat_dict = {} msg = 'gridstat::update(): %s could not be pickled! %s'\ % (buildcache_file, err) self.__logger.error(msg) return False return True if __name__ == '__main__': import sys
path = raw_input("Path to open: ") pickle_fd = open(path, 'rb+') obj = pickle.load(pickle_fd) elif command in ['h', 'help']: print "Valid commands include:" print "(d)isplay to display the opened pickled object" print "(e)dit to edit the opened pickled object" print "(o)pen to open a new pickle file" print "(c)lose to close the opened pickled object" print "(q)uit to quit pickle editor" elif command in ['d', 'display']: print obj elif command in ['e', 'edit']: edit = raw_input("Edit command: ") #eval(edit) eval(compile(edit, 'command-line', 'single')) dirty = True elif command in ['c', 'close', 'q', 'quit']: if dirty: flush = raw_input("Modified object not saved - save now?: ") if flush.lower() in ('y', 'yes'): pickle_fd.seek(0) pickle.dump(obj, pickle_fd) pickle_fd.close() obj = None if command in ('q', 'quit'): print "Closing" break else: print "unknown command '%s'" % command