Debian Codegraph @

cmake/scripts/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, sys
22
23 # Directories to scan
24 subdirs = ["demo"]
25
26 # Check that we can find pylint.py
27 parser = "./utils/pylit/pylit.py"
28 if os.path.isfile(parser):
29 pass
30 else:
31 raise RuntimeError("Cannot find pylit.py. Are you running from the top level directory")
32
33 # Get absolute path to parser
34 parser = os.path.abspath(parser)
35
36 # Generate .py files from all .py.rst files
37 topdir = os.getcwd()
38 for subdir in subdirs:
39 for root, dirs, files in os.walk(subdir):
40
41 # Check for .py.rst files
42 rstfiles = [f for f in files if len(f) > 7 and f[-7:] == ".py.rst"]
43 if len(rstfiles) == 0:
44 continue
45
46 # Compile files
47 os.chdir(root)
48 print("Converting rst files in in {} ...".format(root))
49 for f in rstfiles:
50 command = sys.executable + " " + parser + " " + os.path.abspath(f)
51 #print(" " + command)
52 ret = os.system(command)
53 if not ret == 0:
54 raise RuntimeError("Unable to convert rst file to a .py ({})".format(f))
55
56 os.chdir(topdir)