File: cs_script.py

package info (click to toggle)
code-saturne 7.0.2%2Brepack-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 62,868 kB
  • sloc: ansic: 395,271; f90: 100,755; python: 86,746; cpp: 6,227; makefile: 4,247; xml: 2,389; sh: 1,091; javascript: 69
file content (208 lines) | stat: -rw-r--r-- 6,792 bytes parent folder | download
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/usr/bin/env python3

#-------------------------------------------------------------------------------

# This file is part of Code_Saturne, a general-purpose CFD tool.
#
# Copyright (C) 1998-2021 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.

#-------------------------------------------------------------------------------

import os
import sys

#-------------------------------------------------------------------------------

class master_script:

    def __init__(self, argv = None, package = None):

        self.command = argv
        self.package = package

        self.commands = {'studymanager':self.studymanager,
                         'smgr':self.studymanager,
                         'bdiff':self.bdiff,
                         'bdump':self.bdump,
                         'compile':self.compile,
                         'config':self.config,
                         'cplgui':self.gui,
                         'create':self.create,
                         'gui':self.gui,
                         'studymanagergui':self.studymanager_gui,
                         'smgrgui':self.studymanager_gui,
                         'trackcvg':self.trackcvg,
                         'info':self.info,
                         'parametric':self.parametric,
                         'run':self.run,
                         'salome':self.salome,
                         'submit':self.submit,
                         'symbol2line':self.symbol2line,
                         'update':self.update,
                         'up':self.update}

        if package != None:
            sys.path.insert(1, package.get_dir('pythondir'))

    def execute(self):

        help_commands = ("help", "--help", "-h")
        vers_commands = ("--version", "-v")

        if len(self.command) < 1:
            # On Windows platform, we have two executables frozen by cx_freeze:
            # a .com designed for a console mode (it can also be accessed
            # without the extension) and a .exe designed for a GUI mode.
            # At the moment, running the main script does not launch the GUI
            # mode. Therefore, we force the 'gui' option in this case.
            # This can be changed later on.
            if sys.platform.startswith('win') and \
                    os.path.basename(sys.argv[0]).endswith('exe'):
                command = 'gui'
            else:
                self.usage()
                sys.exit(0)
        else:
            command = self.command[0]

        if command in help_commands:
            subcommand = False
            if len(self.command) > 1:
                subcommand = True
                command = self.command[1]
                if self.command[1] in self.commands:
                    options = self.command[1:] + ['--help']
                    return self.commands[command](options)
            if not subcommand:
                self.usage()
                sys.exit(0)

        if command in self.commands:
            options = self.command[1:]
            return self.commands[command](options)
        else:
            self.usage()
            sys.exit(1)

    def usage(self):

        usage = \
            """Usage: %(prog)s <topic>

Topics:
  help
  studymanager
  smgr
  bdiff
  bdump
  compile
  config
  cplgui
  create
  gui
  parametric
  studymanagergui
  smgrgui
  trackcvg
  update
  up
  info
  run
  submit
  symbol2line

Options:
  -h, --help  show this help message and exit"""

        print(usage % {'prog':sys.argv[0]})

    def studymanager(self, options = None):
        from code_saturne import cs_studymanager
        return cs_studymanager.main(options, self.package)

    def bdiff(self, options = None):
        from code_saturne import cs_bdiff
        return cs_bdiff.main(options, self.package)

    def bdump(self, options = None):
        from code_saturne import cs_bdump
        return cs_bdump.main(options, self.package)

    def compile(self, options = None):
        from code_saturne import cs_compile
        return cs_compile.main(options, self.package)

    def config(self, options = None):
        from code_saturne import cs_config
        return cs_config.main(options, self.package)

    def create(self, options = None):
        from code_saturne import cs_create
        return cs_create.main(options, self.package)

    def gui(self, options = None):
        if self.package.config.features["gui"] == "no":
            raise Exception("This code_saturne build does not include the GUI.")
        from code_saturne import cs_gui
        return cs_gui.main(options, self.package)

    def studymanager_gui(self, options = None):
        from code_saturne import cs_studymanager_gui
        return cs_studymanager_gui.main(options, self.package)

    def trackcvg(self, options = None):
        from code_saturne import cs_trackcvg
        return cs_trackcvg.main(options, self.package)

    def info(self, options = None):
        from code_saturne import cs_info
        return cs_info.main(options, self.package)

    def parametric(self, options = None):
        from code_saturne import cs_parametric_study
        return cs_parametric_study.main(options, self.package)

    def run(self, options = None):
        from code_saturne import cs_run
        return cs_run.main(options, self.package)

    def salome(self, options = None):
        salome_cfd = \
            """%(prog)s salome

Command has been replaced by:
  salome_cfd
command"""

        print(salome_cfd % {'prog':sys.argv[0]})
        return 1

    def submit(self, options = None):
        from code_saturne import cs_submit
        return cs_submit.main(options, self.package)

    def update(self, options = None):
        from code_saturne import cs_update
        return cs_update.main(options, self.package)

    def symbol2line(self, options = None):
        from code_saturne import cs_debug_symbol
        return cs_debug_symbol.main(options, self.package)

#-------------------------------------------------------------------------------
# End
#-------------------------------------------------------------------------------