Skip to content
Snippets Groups Projects
Commit 5f9f0441 authored by Kevin Lyda's avatar Kevin Lyda :speech_balloon:
Browse files

Code clean up.

Add pylint config file.  Clean up some pylint errors.  Clean up setup.py
and make it work with tox/pip.
parent 45cbb6a9
No related branches found
No related tags found
No related merge requests found
[MASTER]
profile=no
ignore=CVS
persistent=no
load-plugins=
[MESSAGES CONTROL]
[REPORTS]
output-format=colorized
include-ids=no
files-output=no
reports=no
evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
comment=no
[BASIC]
required-attributes=
bad-functions=map,filter,apply,input
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$
class-rgx=[A-Z_][a-zA-Z0-9]+$
function-rgx=[a-z_][a-z0-9_]{2,30}$
method-rgx=[a-z_][a-z0-9_]{2,30}$
attr-rgx=[a-z_][a-z0-9_]{2,30}$
argument-rgx=[a-z_][a-z0-9_]{2,30}$
# Regular expression which should only match correct variable names
# Note: s/2/1/ to allow two char var names.
variable-rgx=[a-z_][a-z0-9_]{1,30}$
inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
good-names=i,j,k,ex,f,fn,a,b,Run,_
bad-names=foo,bar,baz,toto,tutu,tata
no-docstring-rgx=__.*__
[FORMAT]
max-line-length=80
max-module-lines=5000
indent-string=' '
[MISCELLANEOUS]
notes=FIXME,XXX,TODO
[SIMILARITIES]
min-similarity-lines=4
ignore-comments=yes
ignore-docstrings=yes
[TYPECHECK]
ignore-mixin-members=yes
ignored-classes=SQLObject
zope=no
generated-members=REQUEST,acl_users,aq_parent
[VARIABLES]
init-import=no
dummy-variables-rgx=_|dummy
additional-builtins=
[CLASSES]
ignore-iface-methods=isImplementedBy,deferred,extends,names,namesAndDescriptions,queryDescriptionFor,getBases,getDescriptionFor,getDoc,getName,getTaggedValue,getTaggedValueTags,isEqualOrExtendedBy,setTaggedValue,isImplementedByInstancesOf,adaptWith,is_implemented_by
defining-attr-methods=__init__,__new__,setUp
valid-classmethod-first-arg=cls
[DESIGN]
max-args=5
ignored-argument-names=_.*
max-locals=15
max-returns=6
max-branchs=12
max-statements=50
max-parents=7
max-attributes=7
min-public-methods=2
max-public-methods=20
[IMPORTS]
deprecated-modules=regsub,string,TERMIOS,Bastion,rexec
import-graph=
ext-import-graph=
int-import-graph=
[EXCEPTIONS]
overgeneral-exceptions=Exception
......@@ -24,18 +24,18 @@ Basic usage:
__author__ = 'lyda@google.com (Kevin Lyda)'
import os
import sys
import chkcrontab_lib as check
def main(argv):
"""main program."""
if len(argv) != 2:
print 'ERROR: No crontab file was specified.'
sys.exit(1)
log = check.LogCounter()
print 'Checking correctness of %s' % argv[1]
return check.CheckCrontab(argv[1], log)
return check.check_crontab(argv[1], log)
if __name__ == '__main__':
main(sys.argv)
......@@ -994,7 +994,7 @@ class LogCounter(object):
return self._error_count
def CheckCrontab(crontab_file, log):
def check_crontab(crontab_file, log):
"""Check a crontab file.
Checks crontab_file for a variety of errors or potential errors. This only
......@@ -1039,15 +1039,3 @@ def CheckCrontab(crontab_file, log):
# Summarize the log messages if there were any.
return log.Summary()
def main():
log = LogCounter()
if len(sys.argv) != 2:
log.Error('Must provide a crontab file to check.')
print('Checking correctness of %s' % sys.argv[1])
return CheckCrontab(sys.argv[1], log)
if __name__ == '__main__':
sys.exit(main())
......@@ -68,7 +68,7 @@ class CleanCmd(Command):
dirs2del = [ './build', './dist' ]
dirs2ign = [ './.git' ]
# End config.
doomed = [ ]
doomed = set()
# Change to base dir.
os.chdir(BASE_DIR)
for root, dirs, files in os.walk('.'):
......@@ -76,18 +76,18 @@ class CleanCmd(Command):
if root in dirs2ign:
continue
if root in dirs2del:
doomed.append(root)
doomed.add(root)
# Handle files.
for f in files:
accused = os.path.join(root, f)
for suffix in suffixes2del:
if f.endswith(suffix):
doomed.append(accused)
doomed.add(accused)
break
if accused not in doomed:
for d2del in dirs2del:
if accused.startswith(d2del):
doomed.append(accused)
doomed.add(accused)
break
# Handle dirs.
for d in dirs:
......@@ -99,7 +99,7 @@ class CleanCmd(Command):
if d in dirs:
for d2del in dirs2del:
if accused.startswith(d2del):
doomed.append(accused)
doomed.add(accused)
break
# Probably not required, but just to be safe.
for accused in doomed:
......@@ -107,8 +107,7 @@ class CleanCmd(Command):
if accused.startswith(d2ign):
doomed.remove(accused)
break
doomed.sort(reverse=True)
for accused in doomed:
for accused in sorted(doomed, reverse=True):
log.info('removing "%s"', os.path.normpath(accused))
if not self.dry_run:
try:
......@@ -153,11 +152,15 @@ class InstallCmd(install):
os.path.join(manpage_dir, manpage_file),
dry_run=self.dry_run)
setup(
# Only override install if not being run by setuptools.
cmdclass = {'test': TestCmd,
'dist_clean': CleanCmd,
'install': InstallCmd,
},
}
if 'setuptools' not in dir():
cmdclass['install'] = InstallCmd
setup(
cmdclass=cmdclass,
name='chkcrontab',
version='1.2',
url='http://code.google.com/p/chkcrontab',
......@@ -178,6 +181,7 @@ setup(
'Programming Language :: Python :: 2.5',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Topic :: Utilities',
],
)
......@@ -311,7 +311,7 @@ class CheckCrontabUnitTest(unittest.TestCase):
log = check.LogCounter()
crontab_file = os.path.join(BASE_PATH, crontab)
(exp_warn, exp_fail, exp_rc) = self.GetExpWFRs(crontab_file)
self.assertEquals(check.CheckCrontab(crontab_file, log), exp_rc,
self.assertEquals(check.check_crontab(crontab_file, log), exp_rc,
'Failed to return %d for crontab errors.' % exp_rc)
self.assertEquals(log.warn_count, exp_warn,
'Found %d warns not %d.' % (log.warn_count, exp_warn))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment