On 09/29/2011 07:41 AM, seth vidal wrote: > http://skvidal.fedorapeople.org/misc/nag-once.py
Looks like something that would work fine for me, thanks. Attached is a patch with some improvements: - Get rid of dependency on hashlib - Make dir names less likely to clash, add nag-once prefix - Don't wait for input on tty stdin on error (e.g. usage)
--- nag-once.py~ 2011-09-29 07:40:16.000000000 +0300 +++ nag-once.py 2011-09-29 20:39:25.453927468 +0300 @@ -13,7 +13,6 @@ import time import os import stat -import hashlib import glob @@ -33,7 +32,7 @@ def get_cmdid_dir(cmdid): """return a path to a valid and safe cachedir""" tmpdir="/var/tmp" - prefix = cmdid + prefix = "nag-once:" + cmdid + "#" dirpath = '%s/%s*' % (tmpdir, prefix) cachedirs = sorted(glob.glob(dirpath)) for thisdir in cachedirs: @@ -72,10 +71,10 @@ # make up or find our tempdir mydir = get_cmdid_dir(cmdid) - old_csum = "haha, no" + old_output = None old_date = 0 if os.path.exists(mydir + '/output'): - old_csum = hashlib.md5(open(mydir + '/output').read()).hexdigest() + old_output = open(mydir + '/output').read() old_date = os.lstat(mydir + '/output')[stat.ST_MTIME] # take from stdin @@ -84,9 +83,8 @@ try: # at this point we have to handle any outputs more ourself b/c we've just read # out of sys.stdin :( - new_csum = hashlib.md5(theinput).hexdigest() - if new_csum != old_csum or (tti and now - old_date > tti): + if theinput != old_output or (tti and now - old_date > tti): print theinput fo = open(mydir + '/output', 'w') fo.write(theinput) @@ -103,6 +101,7 @@ main() except Exception, e: print >> sys.stderr, e - print >> sys.stderr, sys.stdin.read() + if not sys.stdin.isatty(): + print >> sys.stderr, sys.stdin.read()
_______________________________________________ Yum-devel mailing list Yum-devel@lists.baseurl.org http://lists.baseurl.org/mailman/listinfo/yum-devel