[Lsb-messages] /var/www/bzr/lsb/devel/misc-test r2447: refactor cmdchk.py a bit and fix extras-report
Mats Wichmann
mats at linuxfoundation.org
Tue Apr 25 20:00:59 UTC 2017
------------------------------------------------------------
revno: 2447
committer: Mats Wichmann <mats at linuxfoundation.org>
branch nick: misc-test
timestamp: Tue 2017-04-25 14:00:59 -0600
message:
refactor cmdchk.py a bit and fix extras-report
modified:
cmdchk/cmdchk.py
cmdchk/cmdchk.py.sed
-------------- next part --------------
=== modified file 'cmdchk/cmdchk.py'
--- a/cmdchk/cmdchk.py 2017-04-25 18:18:20 +0000
+++ b/cmdchk/cmdchk.py 2017-04-25 20:00:59 +0000
@@ -29,35 +29,17 @@
LSB_DEFAULT_VERSION = '5.1'
-class Path:
- """class describing valid paths"""
-
- def __init__(self, name):
- self.name = name
- self.cmds = []
-
- def dump(self, tag):
- """emit found paths"""
- sys.stderr.write('%s from %s:\n' % (tag, self.name))
- for cmd in self.cmds:
- sys.stderr.write(' %s\n' % cmd)
-
- def addcmd(self, name, path):
- """store found path"""
- self.cmds.append([name, path])
-
-
def check_cmd(jnl, command):
"""check if a command name is found in any of the binpaths"""
(cmdname, cmdpath) = command
jnl.testcase_start(cmdname)
- # Check each of the directories in binpaths for the command
- # if cmdpath is set is set, use it in preference to searching for
- # the cmdname name in binpaths
-
- if cmdpath == 'None':
+ #
+ # Check each of the directories in binpaths for the command.
+ # if cmdpath is set, check for it and don't loop through binpaths.
+ #
+ if not cmdpath:
jnl.purpose_start('Looking for command %s' % cmdname)
for path in binpaths:
if opts.prefix:
@@ -72,15 +54,11 @@
jnl.result_pass()
break
else:
-
- # fallthrough: not found at all
-
+ # we did not find in any of binpaths
sys.stderr.write("Couldn't find %s\n" % cmdname)
jnl.result_fail()
else:
-
- # check for the required absolute path */
-
+ # check for the required absolute path
jnl.purpose_start('Looking for command %s' % cmdpath)
if opts.prefix:
path = opts.prefix + cmdpath
@@ -103,35 +81,39 @@
ones in the command list from the LSB database. Report the extras."""
for path in binpaths:
+ basepath = path # save for later
if opts.prefix:
path = opts.prefix + path
- location = Path(path)
- location.cmds = os.listdir(path)
-
- # buggy: misses the fullpath ones, and doesn't work with prefix
-
- for command in location.cmds[:]: # examine a copy
- if command in database.cmds:
- location.cmds.remove(command) # so we can remove from orig
- if len(location.cmds):
- location.dump('Extra commands')
+ location = sorted(os.listdir(path))
+
+ for (cmdname, cmdpath) in database:
+ if cmdpath:
+ dir, cmd = os.path.split(cmdpath)
+ if dir == basepath and cmd in location:
+ location.remove(cmd)
+ else:
+ if cmdname in location:
+ location.remove(cmdname)
+
+ if len(location):
+ print('Extra commands from %s:\n' % path)
+ for cmd in location:
+ print(' %s\n' % cmd)
def parse_cmds(cmdfile):
"""pull in the required-command list generated from the LSB database"""
- database = Path('database')
+ database = []
for line in open(cmdfile).readlines():
if line[0] == '#':
continue
(cmdname, cmdpath, appearedin, withdrawnin) = line.split()
if lsbversion >= appearedin and (withdrawnin == 'NULL' or
withdrawnin > lsbversion):
- database.addcmd(cmdname, cmdpath)
- # else: # turn on for debugging (it's not a "real" assert)
- # print "%s: assert fail (%s >= %s and (%s == 'NULL' or %s < %s)"
- # % (cmdname, lsbversion, appearedin, withdrawnin,
- # withdrawnin, lsbversion)
+ if cmdpath in ['None']:
+ cmdpath = None
+ database.append((cmdname, cmdpath))
return database
@@ -187,8 +169,8 @@
if opts.lsbversion:
lsbversion = opts.lsbversion
if lsbversion not in LSB_VERSIONS:
- print 'Unsupported LSB version:', lsbversion
- exit(1)
+ sys.stderr.write('Unsupported LSB version: ' + lsbversion)
+ sys.exit(1)
if opts.version:
print 'lsbcmdchk.py %s for LSB Specification %s' \
@@ -216,11 +198,11 @@
binpaths = os.confstr('CS_PATH').split(os.pathsep)
binpaths += ['/sbin', '/usr/sbin']
- db = parse_cmds('cmdlist')
- journal.scenario_info('"total tests in cmdchk %d"' % len(db.cmds))
- for cmd in db.cmds:
+ dbcmds = parse_cmds('cmdlist')
+ journal.scenario_info('"total tests in cmdchk %d"' % len(dbcmds))
+ for cmd in dbcmds:
check_cmd(journal, cmd)
if opts.extras:
- check_extras(db)
+ check_extras(dbcmds)
journal.close()
sys.exit(0)
=== modified file 'cmdchk/cmdchk.py.sed'
--- a/cmdchk/cmdchk.py.sed 2017-04-25 18:18:20 +0000
+++ b/cmdchk/cmdchk.py.sed 2017-04-25 20:00:59 +0000
@@ -29,35 +29,17 @@
LSB_DEFAULT_VERSION = '@DEFAULT_VERSION@'
-class Path:
- """class describing valid paths"""
-
- def __init__(self, name):
- self.name = name
- self.cmds = []
-
- def dump(self, tag):
- """emit found paths"""
- sys.stderr.write('%s from %s:\n' % (tag, self.name))
- for cmd in self.cmds:
- sys.stderr.write(' %s\n' % cmd)
-
- def addcmd(self, name, path):
- """store found path"""
- self.cmds.append([name, path])
-
-
def check_cmd(jnl, command):
"""check if a command name is found in any of the binpaths"""
(cmdname, cmdpath) = command
jnl.testcase_start(cmdname)
- # Check each of the directories in binpaths for the command
- # if cmdpath is set is set, use it in preference to searching for
- # the cmdname name in binpaths
-
- if cmdpath == 'None':
+ #
+ # Check each of the directories in binpaths for the command.
+ # if cmdpath is set, check for it and don't loop through binpaths.
+ #
+ if not cmdpath:
jnl.purpose_start('Looking for command %s' % cmdname)
for path in binpaths:
if opts.prefix:
@@ -72,15 +54,11 @@
jnl.result_pass()
break
else:
-
- # fallthrough: not found at all
-
+ # we did not find in any of binpaths
sys.stderr.write("Couldn't find %s\n" % cmdname)
jnl.result_fail()
else:
-
- # check for the required absolute path */
-
+ # check for the required absolute path
jnl.purpose_start('Looking for command %s' % cmdpath)
if opts.prefix:
path = opts.prefix + cmdpath
@@ -103,35 +81,39 @@
ones in the command list from the LSB database. Report the extras."""
for path in binpaths:
+ basepath = path # save for later
if opts.prefix:
path = opts.prefix + path
- location = Path(path)
- location.cmds = os.listdir(path)
-
- # buggy: misses the fullpath ones, and doesn't work with prefix
-
- for command in location.cmds[:]: # examine a copy
- if command in database.cmds:
- location.cmds.remove(command) # so we can remove from orig
- if len(location.cmds):
- location.dump('Extra commands')
+ location = sorted(os.listdir(path))
+
+ for (cmdname, cmdpath) in database:
+ if cmdpath:
+ dir, cmd = os.path.split(cmdpath)
+ if dir == basepath and cmd in location:
+ location.remove(cmd)
+ else:
+ if cmdname in location:
+ location.remove(cmdname)
+
+ if len(location):
+ print('Extra commands from %s:\n' % path)
+ for cmd in location:
+ print(' %s\n' % cmd)
def parse_cmds(cmdfile):
"""pull in the required-command list generated from the LSB database"""
- database = Path('database')
+ database = []
for line in open(cmdfile).readlines():
if line[0] == '#':
continue
(cmdname, cmdpath, appearedin, withdrawnin) = line.split()
if lsbversion >= appearedin and (withdrawnin == 'NULL' or
withdrawnin > lsbversion):
- database.addcmd(cmdname, cmdpath)
- # else: # turn on for debugging (it's not a "real" assert)
- # print "%s: assert fail (%s >= %s and (%s == 'NULL' or %s < %s)"
- # % (cmdname, lsbversion, appearedin, withdrawnin,
- # withdrawnin, lsbversion)
+ if cmdpath in ['None']:
+ cmdpath = None
+ database.append((cmdname, cmdpath))
return database
@@ -187,8 +169,8 @@
if opts.lsbversion:
lsbversion = opts.lsbversion
if lsbversion not in LSB_VERSIONS:
- print 'Unsupported LSB version:', lsbversion
- exit(1)
+ sys.stderr.write('Unsupported LSB version: ' + lsbversion)
+ sys.exit(1)
if opts.version:
print 'lsbcmdchk.py %s for LSB Specification %s' \
@@ -216,11 +198,11 @@
binpaths = os.confstr('CS_PATH').split(os.pathsep)
binpaths += ['/sbin', '/usr/sbin']
- db = parse_cmds('cmdlist')
- journal.scenario_info('"total tests in cmdchk %d"' % len(db.cmds))
- for cmd in db.cmds:
+ dbcmds = parse_cmds('cmdlist')
+ journal.scenario_info('"total tests in cmdchk %d"' % len(dbcmds))
+ for cmd in dbcmds:
check_cmd(journal, cmd)
if opts.extras:
- check_extras(db)
+ check_extras(dbcmds)
journal.close()
sys.exit(0)
More information about the lsb-messages
mailing list