From: Eric S. Raymond Date: Wed, 25 Sep 2013 16:46:42 +0000 (-0400) Subject: Deduce defaults for name and userid. X-Git-Tag: 1.11~9 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=7cea06f933024e8c83476fd3e7d3883b2d25e4ca;p=coverity-submit.git Deduce defaults for name and userid. --- diff --git a/NEWS b/NEWS index 0a871a8..c98a8fa 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,8 @@ NEWS file for coverty-submit +Repository head: + Sane defaults for name and userid (patch by Morgan Greywolf). + 1.10 @ 2013-09-25 The -t option now defaults to a build timestamp. In a git repo, the -b option now defaults to `git describe HEAD`. diff --git a/coverity-submit b/coverity-submit index 19aa6b0..56c3ffe 100755 --- a/coverity-submit +++ b/coverity-submit @@ -4,7 +4,7 @@ # # By Eric S. Raymond, May 2012. BSD terms apply. # -import os, sys, ConfigParser, getopt, tempfile, shutil, datetime, commands +import os, pwd, sys, ConfigParser, getopt, tempfile, shutil, datetime, commands version = "1.10" @@ -16,6 +16,24 @@ def commit_id(): return output return None +def deduce_name(): + if 'USERNAME' in os.environ: + p=pwd.getpwdnam(os.environ['USERNAME']) + elif 'LOGNAME' in os.environ: + p=pwd.getpwdnam(os.environ['LOGNAME']) + else: + return None + return p.pw_gecos.split(',')[0] + +def deduce_userid(): + if 'USERNAME' in os.environ: + p=pwd.getpwdnam(os.environ['USERNAME']) + elif 'LOGNAME' in os.environ: + p=pwd.getpwdnam(os.environ['LOGNAME']) + else: + return None + return p.pw_name + if __name__ == '__main__': name = email = project = token = url = None @@ -31,11 +49,11 @@ if __name__ == '__main__': # 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.") + config.add_section("ALL") + if not config.has_option("ALL", "name"): + config.set("ALL", "name") = deduce_name() + if not config.has_option("ALL", "userid"): + config.set("ALL", "userid") = deduce_userid() name = config.get("ALL", "name") userid = config.get("ALL", "userid") if config.has_option("ALL", "tools"): diff --git a/coverity-submit.xml b/coverity-submit.xml index 6ede095..3813f2b 100644 --- a/coverity-submit.xml +++ b/coverity-submit.xml @@ -72,8 +72,11 @@ postbuild: -Begin with an [ALL] section giving your name and userid on the -Coverity server. You may specify the email address to which success +You may begin with an [ALL] section giving your name and userid on the +Coverity server. If you don't specify these, the tool will use your local +usename and the first (comma-separated) portion of your GECOS field. + +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.