Created
March 28, 2012 12:49
-
-
Save yyuu/2225873 to your computer and use it in GitHub Desktop.
a mon plugin to monitor count of matching files by name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| import glob | |
| import optparse | |
| import os | |
| import re | |
| import sys | |
| import time | |
| def main(args): | |
| opt_parser = optparse.OptionParser("usage %prog [OPTIONS]", add_help_option=False) | |
| opt_parser.add_option( | |
| '-p', | |
| '--pattern', | |
| type='string', | |
| dest='pattern', | |
| help='pattern', | |
| default='*', | |
| ) | |
| opt_parser.add_option( # --equals | |
| '--equals', | |
| type='int', | |
| dest='eq', | |
| ) | |
| opt_parser.add_option( # --not-equals | |
| '--not-equals', | |
| type='int', | |
| dest='ne', | |
| ) | |
| opt_parser.add_option( # --less-than | |
| '--less-than', | |
| type='int', | |
| dest='lt', | |
| ) | |
| opt_parser.add_option( # --greater-than | |
| '--greater-than', | |
| type='int', | |
| dest='gt', | |
| ) | |
| opt_parser.add_option( # --less-or-equals | |
| '--less-or-equals', | |
| type='int', | |
| dest='le', | |
| ) | |
| opt_parser.add_option( # --greater-or-equals | |
| '--greater-or-equals', | |
| type='int', | |
| dest='ge', | |
| ) | |
| options, args = opt_parser.parse_args(args) | |
| c = len(glob.glob(options.pattern)) | |
| if options.ne is not None: | |
| x = options.ne | |
| ok = c != x | |
| elif options.eq is not None: | |
| x = options.eq | |
| ok = c == x | |
| elif options.le is not None: | |
| x = options.le | |
| ok = c <= x | |
| elif options.ge is not None: | |
| x = options.ge | |
| ok = c >= x | |
| elif options.lt is not None: | |
| x = options.lt | |
| ok = c < x | |
| elif options.gt is not None: | |
| x = options.gt | |
| ok = c > x | |
| if not ok: | |
| print >> sys.stderr, "got %d for %d" % (c, x) | |
| sys.exit(0 if ok else 1) | |
| if __name__ == "__main__": | |
| main(sys.argv) | |
| # vim:set ft=python : |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment