Debian Codegraph @

python/demo/generate-demo-files.py

raw
1 # Copyright (C) 2016 Garth N. Wells
2 #
3 # This file is part of DOLFIN.
4 #
5 # DOLFIN is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Lesser General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # DOLFIN 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
13 # GNU Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
17 #
18 # Recompile all ffc forms (use when FFC has been updated)
19 # This script should be run from the top level directory.
20
21 import os
22 import sys
23
24
25 # Get directory of this file
26 dir_path = os.path.dirname(os.path.realpath(__file__))
27
28 # Directories to scan
29 subdirs = [dir_path]
30
31 # Check that we can find pylint.py
32 parser = dir_path + "/../../utils/pylit/pylit.py"
33 if os.path.isfile(parser):
34 pass
35 else:
36 raise RuntimeError("Cannot find pylit.py. Are you running from the top level directory")
37
38 # Get absolute path to parser
39 parser = os.path.abspath(parser)
40
41 # Generate .py files from all .py.rst files
42 topdir = os.getcwd()
43 for subdir in subdirs:
44 for root, dirs, files in os.walk(subdir):
45
46 # Check for .py.rst files
47 rstfiles = [f for f in files if len(f) > 7 and f[-7:] == ".py.rst"]
48 if len(rstfiles) == 0:
49 continue
50
51 # Compile files
52 os.chdir(root)
53 print("Converting rst files in in {} ...".format(root))
54 for f in rstfiles:
55 command = sys.executable + " " + parser + " " + os.path.abspath(f)
56 #print(" " + command)
57 ret = os.system(command)
58 if not ret == 0:
59 raise RuntimeError("Unable to convert rst file to a .py ({})".format(f))
60
61 os.chdir(topdir)