From 08d4be4d63e0effee5a16a89c30289c1d99788a6 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Wed, 16 May 2012 23:56:56 -0400 Subject: [PATCH] Drop back to Python 2. --- Makefile | 5 + coverity-submit | 249 ++++++++++++++++++++++---------------------- coverity-submit.xml | 36 ++++--- 3 files changed, 150 insertions(+), 140 deletions(-) diff --git a/Makefile b/Makefile index ecebfa6..65629a7 100644 --- a/Makefile +++ b/Makefile @@ -29,6 +29,11 @@ coverity-submit-$(VERS).tar.gz: $(SOURCES) coverity-submit.1 (cd ..; tar -czf coverity-submit/coverity-submit-$(VERS).tar.gz `cat coverity-submit/MANIFEST`) (cd ..; rm coverity-submit-$(VERS)) +pychecker: + @ln -f coverity-submit coverity-submit.py + @-pychecker --only --limit 50 coverity-submit.py + @rm -f coverity-submit.py + clean: rm -f *.pyc *.html coverity-submit.1 MANIFEST ChangeLog SHIPPER.* *~ diff --git a/coverity-submit b/coverity-submit index 8fc0595..28d0db4 100755 --- a/coverity-submit +++ b/coverity-submit @@ -1,135 +1,138 @@ -#!/usr/bin/env python3 +#!/usr/bin/env python # # coverity-submit - submit project to Coverity for scanning # # By Eric S. Raymond, May 2012. BSD terms apply. # -import os, sys, configparser, getopt +import os, sys, ConfigParser, getopt version="1.0" -config = configparser.RawConfigParser() -config.read(os.path.expanduser("~/.coverity-submit")) - -def die(complaint): - sys.stderr.write(complaint + "\n") - sys.exit(1) - -# Gather information that is not project-specific -if not config.defaults(): - die("A defaults section with 'name' and 'userid' options is required.") -elif not config.has_option("DEFAULT", "name"): - die("A 'name' option is required.") -elif not config.has_option("DEFAULT", "userid"): - die("A 'userid' option is required.") -name = config.get("DEFAULT", "name") -userid = config.get("DEFAULT", "userid") -if config.has_option("DEFAULT", "tools"): - tools = config.get("DEFAULT", "tools") - os.environ["PATH"] += ":"+tools - -# Deduce what project and directory to operate on (and go there). -noexec = False -(opts, args) = getopt.getopt(sys.argv[1:], "n") -for (opt, arg) in opts: - if opt == '-n': - noexec = True -where = os.path.basename(os.getcwd()) -if args: - project = args[0] -else: - project = where -if project not in config.sections(): - die("No such project as %s" % project) - -# Collect project-specific variables -if config.has_option(project, "password"): - password = config.get(project, "password") -else: - die("Every project requires a password option.") -if config.has_option(project, "email"): - email = config.get(project, "email") -elif config.has_option("DEFAULT", "email"): - upload = config.get("DEFAULT", "email") -else: - die("Every project requires an email option.") -if config.has_option(project, "upload"): - upload = config.get(project, "upload") -elif config.has_option("DEFAULT", "upload"): - upload = config.get("DEFAULT", "upload") -else: - die("Every project requires an upload option.") -if config.has_option(project, "advertise"): - advertise = config.get(project, "advertise") -elif config.has_option("DEFAULT", "advertise"): - upload = config.get("DEFAULT", "advertise") -else: - die("Every project requires an advertise option.") -if config.has_option(project, "prebuild"): - prebuild = config.get(project, "prebuild") -else: - prebuild = None -if config.has_option(project, "build"): - build = config.get(project, "build") -else: - die("Every project requires a build option.") -if config.has_option(project, "postbuild"): - postbuild = config.get(project, "postbuild") -else: - postbuild = None -if "%s" not in upload: - die("The upload option must contain a %s to plug a tarball name into.") -if "%s" not in advertise: - die("The advertise option must contain a %s to plug a tarball name into.") - -def do_or_die(cmd): - print(cmd) +if __name__ == '__main__': + name = email = project = password = url = None + + config = ConfigParser.RawConfigParser() + config.read(os.path.expanduser("~/.coverity-submit")) + + def die(complaint): + sys.stderr.write(complaint + "\n") + sys.exit(1) + + # Gather information that is not project-specific + if not "ALL" in config.sections(): + die("A defaults section with 'name' and 'userid' options is required.") + elif not config.has_option("ALL", "name"): + die("A 'name' option is required.") + elif not config.has_option("ALL", "userid"): + die("A 'userid' option is required.") + name = config.get("ALL", "name") + userid = config.get("ALL", "userid") + if config.has_option("ALL", "tools"): + tools = config.get("ALL", "tools") + os.environ["PATH"] += ":"+tools + + # Deduce what project and directory to operate on (and go there). + noexec = False + (opts, args) = getopt.getopt(sys.argv[1:], "n") + for (opt, arg) in opts: + if opt == '-n': + noexec = True + where = os.path.basename(os.getcwd()) + if args: + project = args[0] + else: + project = where + if project not in config.sections(): + die("No such project as %s" % project) + + # Collect project-specific variables + if config.has_option(project, "password"): + password = config.get(project, "password") + else: + die("Every project requires a password option.") + if config.has_option(project, "email"): + email = config.get(project, "email") + elif config.has_option("ALL", "email"): + upload = config.get("ALL", "email") + else: + die("Every project requires an email option.") + if config.has_option(project, "upload"): + upload = config.get(project, "upload") + elif config.has_option("ALL", "upload"): + upload = config.get("ALL", "upload") + else: + die("Every project requires an upload option.") + if config.has_option(project, "advertise"): + advertise = config.get(project, "advertise") + elif config.has_option("ALL", "advertise"): + advertise = config.get("ALL", "advertise") + else: + die("Every project requires an advertise option.") + if config.has_option(project, "prebuild"): + prebuild = config.get(project, "prebuild") + else: + prebuild = None + if config.has_option(project, "build"): + build = config.get(project, "build") + else: + die("Every project requires a build option.") + if config.has_option(project, "postbuild"): + postbuild = config.get(project, "postbuild") + else: + postbuild = None + if "%s" not in upload: + die("The upload option must contain a %s to plug a tarball name into.") + if "%s" not in advertise: + die("The advertise option must contain a %s to plug a tarball name into.") + + def do_or_die(cmd): + print(cmd) + if not noexec: + if os.system(cmd) != 0: + sys.stderr.write("Command failed.\n") + sys.exit(1) + + # Announce self + print("coverity-submit version %s..." % version) + + # Work around a known bug in environment restoration under cove-build. + # Without this, xmlto won't run. + os.environ["XML_CATALOG_FILES"] = '/etc/xml/catalog' + + # Build local stuff + print("Rebuilding and scanning...") + if prebuild: + do_or_die(prebuild) + do_or_die("rm -fr cov-int && cov-build --dir cov-int " + build) + if postbuild: + do_or_die(postbuild) + + # Create the tarball + print("Bundling up required metadata...") + readme = """\ + Name: %(name)s + Email: %(email)s + Project: %(project)s + Submitted-by: coverity-submit + """ % globals() + sys.stdout.write(readme) if not noexec: - if os.system(cmd) != 0: - sys.stderr.write("Command failed.\n") - sys.exit(1) - -# Announce self -print("coverity-submit version %s..." % version) - -# Work around a known bug in environment restoration under cove-build. -# Without this, xmlto won't run. -os.environ["XML_CATALOG_FILES"] = '/etc/xml/catalog' - -# Build local stuff -print("Rebuilding and scanning...") -if prebuild: - do_or_die(prebuild) -do_or_die("rm -fr cov-int && cov-build --dir cov-int " + build) -if postbuild: - do_or_die(postbuild) - -# Create the tarball -print("Bundling up required metadata...") -readme = """\ -Name: %(name)s -Email: %(email)s -Project: %(project)s -Submitted-by: coverity-submit -""" % locals() -sys.stdout.write(readme) -if not noexec: - with open("/tmp/README", "w") as wfp: - wfp.write(readme) -tarball = "%s-scan.tgz" % project -do_or_die("mv cov-int /tmp; (cd /tmp; tar -czf %s README cov-int; rm -fr cov-int)" % tarball) - -print("Uploading to where it's publicly visible...") -do_or_die(upload % ("/tmp/" + tarball)) -url = (advertise % tarball) - -print("Posting the analysis request...") -do_or_die('''curl --data \ - "project=%(project)s&password=%(password)s&email=%(email)s&url=%(url)s" \ - http://scan5.coverity.com/cgi-bin/submit_build.py -''' % locals()) - -print("Done. You'll get mail at %s." % email) + with open("/tmp/README", "w") as wfp: + wfp.write(readme) + tarball = "%s-scan.tgz" % project + do_or_die("mv cov-int /tmp; (cd /tmp; tar -czf %s README cov-int; rm -fr cov-int)" % tarball) + + print("Uploading to where it's publicly visible...") + do_or_die(upload % ("/tmp/" + tarball)) + url = (advertise % tarball) + + print("Posting the analysis request...") + do_or_die('''curl --data \ + "project=%(project)s&password=%(password)s&email=%(email)s&url=%(url)s" \ + http://scan5.coverity.com/cgi-bin/submit_build.py + ''' % globals()) + + print("Done. You'll get mail at %s." % email) # The following sets edit modes for GNU EMACS # Local Variables: diff --git a/coverity-submit.xml b/coverity-submit.xml index a13a740..d1c6276 100644 --- a/coverity-submit.xml +++ b/coverity-submit.xml @@ -44,26 +44,28 @@ request status. configuration file is best explained by example. -[DEFAULT] - name=Eric S. Raymond - userid=esr - email=esr@thyrsus.com - tools=/usr/local/coverity/bin - upload=scp %s esr@login.ibiblio.org:/public/html/catb/esr - advertise=http://catb.org/~esr/%s +[ALL] +name: Eric S. Raymond +userid: esr +email: esr@thyrsus.com +tools: /usr/local/coverity/bin +upload: scp %s esr@login.ibiblio.org:/public/html/catb/esr +advertise: http://catb.org/~esr/%s + [gpsd] - password=XXXXXX - prebuild=scons -c - build=scons - postbuild= +password: XXXXXX +prebuild: scons -c +build: scons +postbuild: + [giflib] - password=YYYYYYY - prebuild=autogen.sh && make clean - build=make -k - postbuild= +password: YYYYYYY +prebuild: autogen.sh && make clean +build: make -k +postbuild: -Begin with a [DEFAULT] section giving your name and userid on the +Begin with an [ALL] section giving your name and userid on the Coverity server. You may specify the email address to which success or failure notifications should be mailed for all other projects here, or specify different addresses per-project. @@ -118,7 +120,7 @@ server's HTML response. PREREQUISITES -Requires Python 3, curl, and cov-build. +Requires Python, curl, and cov-build. AUTHOR -- 2.43.0