Return-Path: X-Original-To: apmail-yetus-commits-archive@minotaur.apache.org Delivered-To: apmail-yetus-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 97DD5184C8 for ; Mon, 14 Dec 2015 15:50:15 +0000 (UTC) Received: (qmail 75668 invoked by uid 500); 14 Dec 2015 15:50:15 -0000 Delivered-To: apmail-yetus-commits-archive@yetus.apache.org Received: (qmail 75650 invoked by uid 500); 14 Dec 2015 15:50:15 -0000 Mailing-List: contact commits-help@yetus.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@yetus.apache.org Delivered-To: mailing list commits@yetus.apache.org Received: (qmail 75639 invoked by uid 99); 14 Dec 2015 15:50:15 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Dec 2015 15:50:15 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 634D3E07F6; Mon, 14 Dec 2015 15:50:15 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sekikn@apache.org To: commits@yetus.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: yetus git commit: YETUS-204. shelldocs lint mode Date: Mon, 14 Dec 2015 15:50:15 +0000 (UTC) Repository: yetus Updated Branches: refs/heads/master 951e61642 -> 594336042 YETUS-204. shelldocs lint mode Signed-off-by: Sean Busbey Project: http://git-wip-us.apache.org/repos/asf/yetus/repo Commit: http://git-wip-us.apache.org/repos/asf/yetus/commit/59433604 Tree: http://git-wip-us.apache.org/repos/asf/yetus/tree/59433604 Diff: http://git-wip-us.apache.org/repos/asf/yetus/diff/59433604 Branch: refs/heads/master Commit: 594336042f42977f37fda69e0e68048b8dafe33a Parents: 951e616 Author: Kengo Seki Authored: Mon Dec 14 13:18:46 2015 +0900 Committer: Kengo Seki Committed: Tue Dec 15 00:49:18 2015 +0900 ---------------------------------------------------------------------- shelldocs/shelldocs.py | 128 ++++++++++++++++++++++++++++---------------- 1 file changed, 83 insertions(+), 45 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/yetus/blob/59433604/shelldocs/shelldocs.py ---------------------------------------------------------------------- diff --git a/shelldocs/shelldocs.py b/shelldocs/shelldocs.py index f8f507b..6b0b94f 100755 --- a/shelldocs/shelldocs.py +++ b/shelldocs/shelldocs.py @@ -204,6 +204,28 @@ class ShellFunction: self.getreplace()) return line + def lint(self): + getfuncs = { + "audience" : self.getaudience, + "stability" : self.getstability, + "replaceable" : self.getreplace, + } + validvalues = { + "audience" : ("Public", "Private"), + "stability" : ("Stable", "Evolving"), + "replaceable" : ("Yes", "No"), + } + messages = [] + for attr in ("audience", "stability", "replaceable"): + value = getfuncs[attr]() + if value == "None": + messages.append("ERROR: function %s has no @%s" % (self.getname(), attr.lower())) + elif value not in validvalues[attr]: + validvalue = "|".join(v.lower() for v in validvalues[attr]) + messages.append("ERROR: function %s has invalid value (%s) for @%s (%s)" % + (self.getname(), value.lower(), attr.lower(), validvalue)) + return "\n".join(messages) + def __str__(self): line="{%s %s %s %s}" \ % (self.getname(), @@ -213,7 +235,7 @@ class ShellFunction: return line def main(): - parser=OptionParser(usage="usage: %prog --skipprnorep --output OUTFILE --input INFILE [--input INFILE ...]") + parser=OptionParser(usage="usage: %prog [--skipprnorep] --output OUTFILE --input INFILE [--input INFILE ...]") parser.add_option("-o","--output", dest="outfile", action="store", type="string", help="file to create", metavar="OUTFILE") @@ -222,6 +244,8 @@ def main(): help="file to read", metavar="INFILE") parser.add_option("--skipprnorep", dest="skipprnorep", action="store_true", help="Skip Private & Not Replaceable") + parser.add_option("--lint", dest="lint", + action="store_true", help="Enable lint mode") parser.add_option("-V", "--version", dest="release_version", action="store_true", default=False, help="display version information for shelldocs and exit.") @@ -232,50 +256,64 @@ def main(): print ver_file.read() sys.exit(0) - allfuncs=[] - for filename in options.infile: - with open(filename,"r") as shellcode: - funcdef=ShellFunction() - for line in shellcode: - if line.startswith('## @description'): - funcdef.adddesc(line) - elif line.startswith('## @audience'): - funcdef.setaudience(line) - elif line.startswith('## @stability'): - funcdef.setstability(line) - elif line.startswith('## @replaceable'): - funcdef.setreplace(line) - elif line.startswith('## @param'): - funcdef.addparam(line) - elif line.startswith('## @return'): - funcdef.addreturn(line) - elif line.startswith('function'): - funcdef.setname(line) - if options.skipprnorep and \ - funcdef.getaudience() == "Private" and \ - funcdef.getreplace() == "No": - pass - else: - allfuncs.append(funcdef) - funcdef=ShellFunction() - - allfuncs=sorted(allfuncs) - - outfile=open(options.outfile, "w") - outfile.write(asflicense) - for line in toc(allfuncs): - outfile.write(line) - - outfile.write("\n------\n\n") - - header=[] - for funcs in allfuncs: - if header != funcs.getinter(): - header=funcs.getinter() - line="## %s\n" % (funcs.headerbuild()) - outfile.write(line) - outfile.write(funcs.getdocpage()) - outfile.close() + if options.infile is None: + parser.error("At least one input file needs to be supplied") + elif options.outfile is None and options.lint is None: + parser.error("At least one of output file and lint mode needs to be specified") + + allfuncs = [] + try: + for filename in options.infile: + with open(filename,"r") as shellcode: + funcdef = ShellFunction() + for line in shellcode: + if line.startswith('## @description'): + funcdef.adddesc(line) + elif line.startswith('## @audience'): + funcdef.setaudience(line) + elif line.startswith('## @stability'): + funcdef.setstability(line) + elif line.startswith('## @replaceable'): + funcdef.setreplace(line) + elif line.startswith('## @param'): + funcdef.addparam(line) + elif line.startswith('## @return'): + funcdef.addreturn(line) + elif line.startswith('function'): + funcdef.setname(line) + if options.skipprnorep and \ + funcdef.getaudience() == "Private" and \ + funcdef.getreplace() == "No": + pass + else: + allfuncs.append(funcdef) + funcdef = ShellFunction() + except IOError, err: + print >> sys.stderr, "ERROR: Failed to read from file: %s. Aborting." % err.filename + sys.exit(1) + + allfuncs = sorted(allfuncs) + + if options.lint: + for funcs in allfuncs: + message = funcs.lint() + if 0 < len(message): + print message + + if options.outfile is not None: + with open(options.outfile, "w") as outfile: + outfile.write(asflicense) + for line in toc(allfuncs): + outfile.write(line) + outfile.write("\n------\n\n") + + header = [] + for funcs in allfuncs: + if header != funcs.getinter(): + header = funcs.getinter() + line = "## %s\n" % (funcs.headerbuild()) + outfile.write(line) + outfile.write(funcs.getdocpage()) if __name__ == "__main__": main()