1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
#!/usr/bin/env python
#-------------------------------------------------------------------------------
# This file is part of Code_Saturne, a general-purpose CFD tool.
#
# Copyright (C) 1998-2016 EDF S.A.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
# Street, Fifth Floor, Boston, MA 02110-1301, USA.
#-------------------------------------------------------------------------------
"""
This module describes the script used to display information on Code_Saturne.
This module defines the following functions:
- process_cmd_line
- print_version
- launch_manual
"""
#-------------------------------------------------------------------------------
# Library modules import
#-------------------------------------------------------------------------------
import os, sys, shutil, stat, fnmatch
from optparse import OptionParser
#-------------------------------------------------------------------------------
# Processes the passed command line arguments
#-------------------------------------------------------------------------------
def process_cmd_line(argv, pkg):
"""
Processes the passed command line arguments.
Input Argument:
arg -- This can be either a list of arguments as in
sys.argv[1:] or a string that is similar to the one
passed on the command line. If it is a string the
string is split to create a list of arguments.
"""
if sys.argv[0][-3:] == '.py':
usage = "usage: %prog [options]"
else:
usage = "usage: %prog info [options]"
parser = OptionParser(usage=usage)
parser.add_option("-r", "--reader", dest="pdf_reader", type="string",
metavar="<pdfreader>",
help="define a pdf reader")
parser.add_option("-g", "--guide", dest="guides", type="string",
metavar="<guide>", action="append",
help="open a manual " + str(get_docs(pkg)))
parser.add_option("--version", dest="version",
action="store_true",
help="print version number")
parser.set_defaults(pdf_reader=None)
parser.set_defaults(guides=[])
parser.set_defaults(version=False)
(options, args) = parser.parse_args(argv)
if options.version:
print_version(pkg)
sys.exit(0)
if len(args) > 0 or len(options.guides) == 0:
parser.print_help()
sys.exit(1)
return options.guides, options.pdf_reader
#-------------------------------------------------------------------------------
# Print Code_Saturne version
#-------------------------------------------------------------------------------
def print_version(pkg):
"""
Print Code_Saturne version.
"""
print(pkg.code_name + " version: " + pkg.version_full)
#-------------------------------------------------------------------------------
# Launch the PDF manual
#-------------------------------------------------------------------------------
def get_docs(pkg):
"""
Return the list of available PDF and Doxygen manuals for the command line.
"""
l = []
if os.path.isdir(pkg.get_dir('docdir')):
for docs in fnmatch.filter(os.listdir(pkg.get_dir('docdir')), '*.pdf'):
l.append(docs[:-4])
doxy_dir = os.path.join(pkg.get_dir('docdir'),'doxygen', 'src')
if os.path.isdir(doxy_dir):
for docs in fnmatch.filter(os.listdir(doxy_dir), 'index.html'):
l.append('Doxygen')
return l
def launch_manual(reader, m, pkg):
"""
Launch the corresponding PDF manual.
"""
sys_tools = ["xdg-open", # Generic
"gnome-open", # Gnome
"kfmclient exec", # KDE
"kde-open", # KDE 4
"exo-open"] # Xfce
if not m == "Doxygen":
readers = ["okular", "evince", "kpdf", "gpdf", "xpdf", "acroread"]
manual = os.path.join(pkg.get_dir('docdir'), m) + '.pdf'
else:
readers = ["firefox"]
manual = os.path.join(pkg.get_dir('docdir'),'doxygen', 'src', 'index.html')
if not os.path.isfile(manual):
print("File %s not found." % manual)
return
# On Windows platform, use the system standard launcher
if sys.platform.startswith('win'):
os.startfile(manual)
# On Linux and Unix-like platforms,
# - first: use the reader specified by the user, if any
# - second: try the different tool that open with the default system reader
# - last: try some classical pdf viewers
else:
if reader is not None:
cmd = reader + ' ' + manual + ' 2>/dev/null &'
os.system(cmd)
else:
for r in (sys_tools + readers):
cmd = r + ' ' + manual + ' 2>/dev/null &'
if os.system(cmd) == 0:
return
#-------------------------------------------------------------------------------
# Main
#-------------------------------------------------------------------------------
def main(argv, pkg):
"""
Main function.
"""
manuals, reader = process_cmd_line(argv, pkg)
for m in manuals:
launch_manual(reader, m, pkg)
#-------------------------------------------------------------------------------
# End
#-------------------------------------------------------------------------------
|