diff options
author | Alec Warner <antarus@gentoo.org> | 2008-07-20 05:21:33 +0000 |
---|---|---|
committer | Alec Warner <antarus@gentoo.org> | 2008-07-20 05:21:33 +0000 |
commit | 10721414a2d5490ea57af703422cda80596258f4 (patch) | |
tree | 57bb9c5736c46f03c7988b1fc8857708ece7da12 /users | |
parent | Integrate robin's changes; move shortcut out of StringToEpoch and into option... (diff) | |
download | gentoo-10721414a2d5490ea57af703422cda80596258f4.tar.gz gentoo-10721414a2d5490ea57af703422cda80596258f4.tar.bz2 gentoo-10721414a2d5490ea57af703422cda80596258f4.zip |
Make improvements such that pylint complains a lot less.
Diffstat (limited to 'users')
-rw-r--r-- | users/antarus/projects/infra/process_timer | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/users/antarus/projects/infra/process_timer b/users/antarus/projects/infra/process_timer index 34aa40885c..4a58cd630f 100644 --- a/users/antarus/projects/infra/process_timer +++ b/users/antarus/projects/infra/process_timer @@ -1,5 +1,5 @@ #!/usr/bin/python -# $Header: /var/cvsroot/gentoo/users/antarus/projects/infra/process_timer,v 1.11 2008/07/20 05:11:35 antarus Exp $ +# $Header: /var/cvsroot/gentoo/users/antarus/projects/infra/process_timer,v 1.12 2008/07/20 05:21:33 antarus Exp $ # Copyright Alec Warner 2008 # Released in the public domain. @@ -22,21 +22,23 @@ import os import re import sys -PROC_PATH='/proc' +PROC_PATH = '/proc' -TIME_KEYS = ['walltime', 'utime', 'stime', 'cutime', 'cstime', 'starttime', 'cpu', 'ccpu'] +TIME_KEYS = ['walltime', 'utime', 'stime', 'cutime', 'cstime', 'starttime', + 'cpu', 'ccpu'] def GetOpts(): """Parse the options.""" parser = optparse.OptionParser() parser.add_option('-p', '--prog', help='program to search for') - parser.add_option('-t', '--time', help='max time prog can run (in format: 3h30m10s)', - default='10s') + parser.add_option('-t', '--time', help='max time prog can run' + '(in format: 3h30m10s)', default='10s') parser.add_option('-m', '--match', type='choice', default='walltime', choices=TIME_KEYS, help='match time against a given choice') - parser.add_option('-v', '--verbose', help='increase loglevel', action='store_true') + parser.add_option('-v', '--verbose', help='increase loglevel', + action='store_true') opts, args = parser.parse_args() # Support the case where opts.time is already in unmarked seconds @@ -62,14 +64,14 @@ def GetOpts(): return opts, args -time_atom_re = re.compile(r'(\d)+(\w)') +TIME_ATOM_RE = re.compile(r'(\d)+(\w)') def StringToEpochTime(str_time): """Return time in Epoch time given a string identifier. To support strings such as '3h30m' this function recursively calls itself - with substrings as a argument (first call parses '3h', second call parses '30m' - results are summed.) + with substrings as a argument (first call parses '3h', second call parses + '30m' results are summed.) Args: str_time: a string representing a time interval, eg. '3h5m' or '52w' @@ -79,9 +81,10 @@ def StringToEpochTime(str_time): """ result = 0 - match = time_atom_re.match(str_time) + match = TIME_ATOM_RE.match(str_time) if not match: - raise ValueError('argument not in valid format ((\d)+(\w))+: %s' % str_time) + raise ValueError('argument not in valid format ((\d)+(\w))+: %s' % ( + str_time,)) else: value, identifier = match.groups() value = int(value) @@ -128,8 +131,8 @@ def FindPids(search_str): logging.debug('pids avaialble: %s' % files) for pid in files: - PID_DIR_PATH = os.path.join(PROC_PATH, pid) - CMDLINE_FILE = os.path.join(PID_DIR_PATH, 'cmdline') + pid_dir_path = os.path.join(PROC_PATH, pid) + CMDLINE_FILE = os.path.join(pid_dir_path, 'cmdline') try: cmdline = open(CMDLINE_FILE).read().split('\0') logging.debug('cmdline: %s' % cmdline) @@ -138,7 +141,7 @@ def FindPids(search_str): logging.debug('matched %s' % pid) matches.add((pid, str(cmdline))) except IOError, OSError: - continue + continue logging.info('pids matched: %s' % matches) @@ -162,10 +165,10 @@ def CalculateTime(pid): # partial results here. utime = stime = cutime = cstime = wall = starttime = 0 - PID_DIR_PATH = os.path.join(PROC_PATH, pid) + pid_dir_path = os.path.join(PROC_PATH, pid) try: - data = open(os.path.join(PID_DIR_PATH, 'stat')).read().split(' ') + data = open(os.path.join(pid_dir_path, 'stat')).read().split(' ') utime, stime, cutime, cstime = map(int, data[13:17]) starttime = int(data[21]) except IOError, OSError: @@ -196,7 +199,7 @@ def CalculateTime(pid): def Main(): """Main Driver function.""" - opts, args = GetOpts() + opts, unused_args = GetOpts() pids = FindPids(opts.prog) for pid in pids: times = CalculateTime(pid[0]) |