ENH: Update FreeFOAM contributions to GPL v3
[freefoam.git] / data / utilities / extractBrief.py.in
blobb3f506002f14e14b6d52418fb7e73deaa143922f
1 #!@PYTHON_EXECUTABLE@
2 #-------------------------------------------------------------------------------
3 # ______ _ ____ __ __
4 # | ____| _| |_ / __ \ /\ | \/ |
5 # | |__ _ __ ___ ___ / \| | | | / \ | \ / |
6 # | __| '__/ _ \/ _ ( (| |) ) | | |/ /\ \ | |\/| |
7 # | | | | | __/ __/\_ _/| |__| / ____ \| | | |
8 # |_| |_| \___|\___| |_| \____/_/ \_\_| |_|
10 # FreeFOAM: The Cross-Platform CFD Toolkit
12 # Copyright (C) 2008-2012 Michael Wild <themiwi@users.sf.net>
13 # Gerber van der Graaf <gerber_graaf@users.sf.net>
14 #-------------------------------------------------------------------------------
15 # License
16 # This file is part of FreeFOAM.
18 # FreeFOAM is free software: you can redistribute it and/or modify it
19 # under the terms of the GNU General Public License as published by the
20 # Free Software Foundation, either version 3 of the License, or (at your
21 # option) any later version.
23 # FreeFOAM is distributed in the hope that it will be useful, but WITHOUT
24 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
25 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26 # for more details.
28 # You should have received a copy of the GNU General Public License
29 # along with FreeFOAM. If not, see <http://www.gnu.org/licenses/>.
31 # Script
32 # extractBrief
34 # Description
35 # Extracts the brief description from the header comment of an application
36 # source file and converts it to AsciiDoc code. The output is written to
37 # standard output.
39 #------------------------------------------------------------------------------
41 """Usage: extractBrief@PY_SCRIPT_SUFFIX@ <name> <file>
43 Extracts the brief description from the header comment of an application
44 source file and converts it to AsciiDoc code. The output is written to
45 standard output.
47 Options
48 -------
50 -help Display this help message
51 <name> Name of the application.
52 <file> The source file to to process.
54 """
56 import sys
57 import os.path
58 sys.path.insert(0, '@FOAM_PYTHON_DIR@')
59 import FreeFOAM.doxyToAsciidoc
60 from FreeFOAM.compat import *
62 args = sys.argv[1:]
63 while len(args) > 0:
64 a = args[0]
65 if a == '-h' or a == '-help':
66 echo(__doc__)
67 sys.exit(0)
68 else:
69 break
71 if len(args) != 2:
72 echo('Error: the name and input file required arguments', file=sys.stderr)
73 sys.exit(1)
75 name = args[0]
76 source = args[1]
78 if not os.path.isfile(source):
79 echo('Error: "%s" does not exist or is not a file'%source, file=sys.stderr)
80 sys.exit(1)
82 # parse the header comments
83 doc = FreeFOAM.doxyToAsciidoc.Parser(source).parse()
84 brief = ' '.join(doc['brief']).strip()
85 if brief[-1] != '.':
86 brief += '.'
88 echo('*linkff:%s[1]*::\n %s'%(name, brief))
90 # ------------------------- vim: set sw=3 sts=3 et: --------------- end-of-file