From ac0c55c36eaa387888ca0d2aef5ab588fe0ccd94 Mon Sep 17 00:00:00 2001 From: Faiyaz Ahmed Date: Tue, 19 Feb 2008 22:54:43 +0000 Subject: [PATCH] Made DATAFILE global. Same for VERSION. --- swapmon.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/swapmon.py b/swapmon.py index da8f3a0..b0c3bb3 100755 --- a/swapmon.py +++ b/swapmon.py @@ -35,8 +35,8 @@ from pl_mom import * # Defaults debug = False verbose = 0 -datafile = "/var/lib/misc/swapmon.dat" - +DATAFILE = "/var/lib/misc/swapmon.dat" +VERSION = "$Id$" # Seconds between process analysis period = 30 @@ -263,7 +263,7 @@ Options: --system-slice=SLICE System slice that should not be reset --status Print memory usage statistics and exit -h, --help This message -""".lstrip() % (sys.argv[0], debug, verbose, datafile, format_period(period)) +""".lstrip() % (sys.argv[0], debug, verbose, DATAFILE, format_period(period)) def slicestat(names = None): """ @@ -465,14 +465,14 @@ def readdat(): pl_mom@pl. ''' try: - f = open(datafile, "r+") + f = open(DATAFILE, "r+") if verbose: - print "Loading %s" % datafile - (version, slices) = pickle.load(f) + print "Loading %s" % DATAFILE + (v, slices) = pickle.load(f) f.close() # Check version of data file - if version != "$Id$": - print "Not using old version '%s' data file %s" % (version, datafile) + if v != VERSION: + print "Not using old version '%s' data file %s" % (v, DATAFILE) raise Exception params = {'hostname': socket.gethostname(), @@ -485,9 +485,8 @@ def readdat(): slicemail(None, rebooted_subject % params, rebooted_body % params) # Delete data file - os.unlink(datafile) + os.unlink(DATAFILE) except Exception: - version = "$Id$" slices = slicestat() return slices @@ -497,15 +496,15 @@ def writedat(slices): """ Write (slices) to pickled datfile. """ - if verbose: print "Saving %s" % datafile - f = open(datafile, "w") - pickle.dump((version, slices), f) + if verbose: print "Saving %s" % DATAFILE + f = open(DATAFILE, "w") + pickle.dump((VERSION, slices), f) f.close() def main(): # Defaults - global debug, verbose, datafile + global debug, verbose, DATAFILE, VERSION global period, change_thresh, reset_thresh, reboot_thresh, rss_min, system_slices # All slices names = [] @@ -525,7 +524,7 @@ def main(): elif opt == "-v" or opt == "--verbose": verbose += 1 elif opt == "-f" or opt == "--file": - datafile = optval + DATAFILE = optval elif opt == "-s" or opt == "--slice": names.append(optval) elif opt == "-p" or opt == "--period": -- 2.43.0