diff options
author | Christian Heimes <cheimes@redhat.com> | 2015-08-11 19:51:43 +0200 |
---|---|---|
committer | Christian Heimes <cheimes@redhat.com> | 2015-08-14 12:09:11 +0200 |
commit | d63ade55f5cc2a9ecf21ea2b43cfac80149c4c29 (patch) | |
tree | 2faa02bb4d45e04ea2fc957e649e6b344ec10c93 /pylint-build-scan.py | |
parent | f60846e025ff5492e8c05ccf525fe8df1b59bba6 (diff) | |
download | pki-d63ade55f5cc2a9ecf21ea2b43cfac80149c4c29.tar.gz pki-d63ade55f5cc2a9ecf21ea2b43cfac80149c4c29.tar.xz pki-d63ade55f5cc2a9ecf21ea2b43cfac80149c4c29.zip |
Move pylint-build-scan.py to scripts directory
Move internal helper and its configuration out of the project's root
directory into scripts/. Also use re instead of fnmatch to find the
upgrade scriptlets.
Diffstat (limited to 'pylint-build-scan.py')
-rwxr-xr-x | pylint-build-scan.py | 130 |
1 files changed, 0 insertions, 130 deletions
diff --git a/pylint-build-scan.py b/pylint-build-scan.py deleted file mode 100755 index 9cd8a98c4..000000000 --- a/pylint-build-scan.py +++ /dev/null @@ -1,130 +0,0 @@ -#!/usr/bin/python - -# Authors: -# Christian Heimes <cheimes@redhat.com> -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; version 2 of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -# -# Copyright (C) 2015 Red Hat, Inc. -# All rights reserved. - -from __future__ import print_function, unicode_literals - -import argparse -import os -import fnmatch -import pprint -import subprocess -import sys - -from distutils.sysconfig import get_python_lib # pylint: disable=F0401 - -SCRIPTPATH = os.path.dirname(os.path.abspath(__file__)) -FILENAMES = [ - '{scriptpath}/pylint-build-scan.py', - '{sitepackages}/pki', - '{bin}/pki', - '{sbin}/pkispawn', - '{sbin}/pkidestroy', - '{sbin}/pki-upgrade', - '{sbin}/pki-server', - '{sbin}/pki-server-upgrade', -] - - -def tox_env(args): - """Paths for tox environment""" - prefix = args.prefix - env = { - 'scriptpath': SCRIPTPATH, - 'bin': os.path.join(prefix, 'bin'), - 'sbin': os.path.join(prefix, 'bin'), - 'sharepki': os.path.join(prefix, 'share', 'pki'), - 'sitepackages': get_python_lib() - } - return env - - -def rpm_env(args): - """Paths for RPM build environment""" - prefix = args.prefix - relative = get_python_lib().lstrip(os.sep) - env = { - 'scriptpath': SCRIPTPATH, - 'bin': os.path.join(prefix, 'usr', 'bin'), - 'sbin': os.path.join(prefix, 'usr', 'sbin'), - 'sharepki': os.path.join(prefix, 'usr', 'share', 'pki'), - 'sitepackages': os.path.join(prefix, relative), - } - return env - - -def find_upgrades(root): - """Find upgrade scripts""" - for dirpath, _, filenames in os.walk(root): - for filename in filenames: - if fnmatch.fnmatch(filename, '[0-9][0-9]-*'): - yield os.path.join(dirpath, filename) - - -def main(): - """Dogtag pylint script""" - parser = argparse.ArgumentParser( - description=main.__doc__, - epilog="Additional arguments can be passed to pylint with: " - "'-- --arg1 --arg2 ...'", - ) - parser.add_argument('--verbose', action='store_true') - subparsers = parser.add_subparsers(dest='command') - subparsers.required = True - - toxparser = subparsers.add_parser('tox', help='tox in-tree tests') - toxparser.add_argument('--prefix', dest='prefix', default=sys.prefix) - toxparser.add_argument('pylint_args', nargs=argparse.REMAINDER) - toxparser.set_defaults(get_env=tox_env) - - rpmparser = subparsers.add_parser('rpm', help='RPM source tree tests') - rpmparser.add_argument('--prefix', dest='prefix', required=True) - rpmparser.add_argument('pylint_args', nargs=argparse.REMAINDER) - rpmparser.set_defaults(get_env=rpm_env) - - args = parser.parse_args() - env = args.get_env(args) - if args.verbose: - pprint.pprint(env) - # sanity check - for key, path in env.items(): - if not os.path.exists(path): - raise RuntimeError('{} ({}) does not exist'.format(key, path)) - - if args.pylint_args and args.pylint_args[0] == '--': - extra_args = args.pylint_args[1:] - else: - extra_args = args.pylint_args - - pylint = [ - 'pylint', - '--rcfile={scriptpath}/dogtag.pylintrc'.format(**env) - ] - pylint.extend(extra_args) - pylint.extend(filename.format(**env) for filename in FILENAMES) - pylint.extend(find_upgrades('{sharepki}/upgrade'.format(**env))) - pylint.extend(find_upgrades('{sharepki}/server/upgrade'.format(**env))) - if args.verbose: - pprint.pprint(pylint) - - return subprocess.call(pylint, cwd=env['sitepackages']) - -if __name__ == '__main__': - sys.exit(main()) |