]> thyrsus.com Git - coverity-submit.git/commitdiff
Deduce defaults for name and userid.
authorEric S. Raymond <esr@thyrsus.com>
Wed, 25 Sep 2013 16:46:42 +0000 (12:46 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Wed, 25 Sep 2013 16:46:42 +0000 (12:46 -0400)
NEWS
coverity-submit
coverity-submit.xml

diff --git a/NEWS b/NEWS
index 0a871a8ae131ea6c528eec7676734ccd7ce5833e..c98a8fa108991bfc0c6951bc5a9b79ae2f95ae50 100644 (file)
--- 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`.
index 19aa6b06e91ad9a865d0df00e53390176ece02c0..56c3ffe7cd01573a7d866747a9e458770d9c6efc 100755 (executable)
@@ -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"):
index 6ede095c3b1c182c403f7451c0cec9858f611ec1..3813f2b95a1d1aada6ce4a8f7549aa4b29c070be 100644 (file)
@@ -72,8 +72,11 @@ postbuild:
 
 </programlisting>
 
-<para>Begin with an [ALL] section giving your name and userid on the
-Coverity server. You may specify the email address to which success
+<para>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.</para>
+
+<para>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.</para>