-#!/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: