Salome HOME
integration derniers ajustements pour windows
[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('x', 'xml', 'boolean', 'xml', "Open sat xml/html documentation in browser (x as firefoX)", 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 The doc command gives access to the sat documentation.
37     
38 example:
39 >> sat doc         # --xml as default
40 >> sat doc --xml
41 >> sat doc --pdf
42 """)
43
44 def run(args, runner, logger):
45     '''method that is called when salomeTools is called with log parameter.
46     '''
47     # Parse the options
48     (options, args) = parser.parse_args(args)
49
50     # get the log directory. 
51     satDir = runner.cfg.VARS.salometoolsway
52     docDir = os.path.join(satDir, "doc")
53     htmlFile = os.path.join(docDir, "build", "html", "index.html")
54     pdfFile = os.path.join(satDir, "doc", "build", "latex", "salomeTools.pdf")
55     rstFiles = os.path.join(satDir, "doc", "src", "*.rst")
56     rstFilesCommands = os.path.join(satDir, "doc", "src", "commands", "*.rst")
57     readmeFile = os.path.join(satDir, "doc", "README")
58
59     logger.write("docdir %s\n" % docDir, 6)
60     logger.write("options %s\n" % options, 6)
61
62     if options.pdf:
63         if not os.path.isfile(pdfFile):
64             msg = "\npdf documentation not found. Please build it inside doc directory\n"\
65                   "(follow README instructions in doc directory)\n"
66             logger.error(msg)
67             return 1
68         src.system.show_in_editor(runner.cfg.USER.pdf_viewer, pdfFile, logger)
69
70     elif options.edit:
71         src.system.show_in_editor(runner.cfg.USER.editor, rstFiles, logger)
72         src.system.show_in_editor(runner.cfg.USER.editor, rstFilesCommands, logger)
73
74     elif options.compile:
75         logger.write("How to compile documentation:\n%s" % open(readmeFile,"r").read(), 3)
76
77     else:
78         if not os.path.isfile(htmlFile):
79             msg = "\nhtml documentation not found. Please build it inside doc directory\n"\
80                   "(follow README instructions in doc directory)\n"
81             logger.error(msg)
82             return 1
83         src.system.show_in_editor(runner.cfg.USER.browser, htmlFile, logger)
84
85     return 0