def cb_end(args): request = args["request"] config = request.getConfiguration() datadir = config["datadir"] data = request.getData() f = data["viewcount_fp"] p = data["viewcount_picklefile"] if f: pickle.dump(p, f, 1) tools.unlock(f) f.close()
def cb_prepare(args): """ Callback registered with prepareChain. This does all the work @param args: args dict containing the request @type args: dict """ request = args["request"] config = request.getConfiguration() data = request.getData() httpData = request.getHttp() datadir = config["datadir"] try: f = open(datadir + "/logfile.dat", "r+") tools.lock(f, tools.LOCK_EX) stats = pickle.load(f) f.seek(0, 0) except: f = open(datadir + "/logfile.dat", "w") tools.lock(f, tools.LOCK_EX) stats = PyblStats(config) stats._request = request stats._config = config stats._referrer_length = int(config.get('referrer_length', 15)) stats._num_referrers = int(config.get('num_referrers', 15)) stats.addReferer(httpData.get('HTTP_REFERER', '-')) stats.addDestination(httpData.get('REQUEST_URI', '-')) stats.addVisitor(httpData.get('REMOTE_ADDR', '-')) data["referrers"] = stats.genReferrers() # next 2 lines null out modules vars for pickling stats._request = None stats._config = None pickle.dump(stats, f) tools.unlock(f) f.close()