Salome HOME
sat #11080 done, add command doc and upgrade documentation
[tools/sat.git] / commands / doc.py
1 #!/usr/bin/env python
2 #-*- coding:utf-8 -*-
3 #  Copyright (C) 2010-2012  CEA/DEN
4 #
5 #  This library is free software; you can redistribute it and/or
6 #  modify it under the terms of the GNU Lesser General Public
7 #  License as published by the Free Software Foundation; either
8 #  version 2.1 of the License.
9 #
10 #  This library is distributed in the hope that it will be useful,
11 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 #  Lesser General Public License for more details.
14 #
15 #  You should have received a copy of the GNU Lesser General Public
16 #  License along with this library; if not, write to the Free Software
17 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18
19 import os
20 import src
21
22 # Define all possible option for log command :  sat doc <options>
23 parser = src.options.Options()
24 parser.add_option('h', 'html', 'boolean', 'html', "Open sat html documentation in browser", None)
25 parser.add_option('p', 'pdf', 'boolean', 'pdf', "Open sat pdf documentation in viewer", False)
26 parser.add_option('e', 'edit', 'boolean', 'edit', "edit/modify source dodumentation rst files", False)
27 parser.add_option('c', 'compile', 'boolean', 'compile', "how to compile html/pdf doc", False)
28
29 def description():
30     """method that is called when salomeTools is called with --help option.
31
32     :return: The text to display for the log command description.
33     :rtype: str
34     """
35     return _("""\
36     Gives access to the sat documentation.
37     
38     example:
39     >> sat doc         # --html as default
40     >> sat doc --html
41     >> sat doc --pdf""")
42
43 def run(args, runner, logger):
44     '''method that is called when salomeTools is called with log parameter.
45     '''
46     # Parse the options
47     (options, args) = parser.parse_args(args)
48
49     # get the log directory. 
50     satDir = runner.cfg.VARS.salometoolsway
51     docDir = os.path.join(satDir, "doc")
52     htmlFile = os.path.join(docDir, "build", "html", "index.html")
53     pdfFile = os.path.join(satDir, "doc", "build", "latex", "salomeTools.pdf")
54     rstFiles = os.path.join(satDir, "doc", "src", "*.rst")
55     rstFilesCommands = os.path.join(satDir, "doc", "src", "commands", "*.rst")
56     readmeFile = os.path.join(satDir, "doc", "README")
57
58     logger.write("docdir %s\n" % docDir, 6)
59     logger.write("options %s\n" % options, 6)
60
61     if options.html:
62         src.system.show_in_editor(runner.cfg.USER.browser, htmlFile, logger)
63     if options.pdf:
64         src.system.show_in_editor(runner.cfg.USER.pdf_viewer, pdfFile, logger)
65     if options.edit:
66         src.system.show_in_editor(runner.cfg.USER.editor, rstFiles, logger)
67         src.system.show_in_editor(runner.cfg.USER.editor, rstFilesCommands, logger)
68     if options.compile:
69         logger.write("How to comile documentation:\n%s" % open(readmeFile,"r").read(), 3)
70     return 0