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
|
#!/usr/bin/env python3
#
# Copyright (C) 2009-2022 ABINIT Group (Yann Pouillon)
#
# This file is part of the ABINIT software package. For license information,
# please see the COPYING file in the top-level directory of the ABINIT source
# distribution.
#
from __future__ import print_function, division, absolute_import #, unicode_literals
try:
from ConfigParser import ConfigParser
except ImportError:
from configparser import ConfigParser
from time import gmtime,strftime
import os
import re
import sys
class MyConfigParser(ConfigParser):
def optionxform(self,option):
return str(option)
def key_is_ok(key):
# Init keys to ignore
cnf_ignore = ["status"]
if ( key in cnf_ignore ):
return False
else:
return True
# ---------------------------------------------------------------------------- #
#
# Main program
#
# Initial setup
my_name = "make-build-examples"
my_configs = ["config/specs/testfarm.conf"]
my_template = "doc/build/config-template.ac9"
my_outdir = "doc/build/config-examples"
my_fbck = "config/specs/fbversion.conf"
# Check if we are in the top of the ABINIT source tree
if ( not os.path.exists("configure.ac") or
not os.path.exists("src/98_main/abinit.F90") ):
print("%s: You must be in the top of an ABINIT source tree." % my_name)
print("%s: Aborting now." % my_name)
sys.exit(1)
# Check if we have a config file
for my_config in my_configs:
if ( not os.path.exists(my_config) ):
print("%s: Could not find config file (%s)." % (my_name,my_config))
print("%s: Aborting now." % my_name)
sys.exit(2)
# Check if we have a template
if ( os.path.exists(my_template) ):
inp_data = open(my_template,"rt").readlines()
else:
print("%s: Could not find template file (%s)." % (my_name,my_template))
print("%s: Aborting now." % my_name)
sys.exit(3)
# Check if we have a fallback config file
if ( os.path.exists(my_fbck) ):
fcnf = MyConfigParser()
fcnf.read(my_fbck)
if len(fcnf.sections()) != 0:
fbversion = '_'+fcnf.sections()[0]
else:
fbversion = ''
else:
print("%s: Could not find fbversion file (%s)." % (my_name,my_fbck))
print("%s: Aborting now." % my_name)
sys.exit(4)
# What time is it?
now = strftime("%Y/%m/%d %H:%M:%S +0000",gmtime())
# Prepare the storage space
if ( not os.path.exists(my_outdir) ):
os.makedirs(my_outdir)
for old_ex in os.listdir(my_outdir):
item = os.path.join(my_outdir, old_ex)
#print("Removing item:", item)
if os.path.isdir(item):
if os.listdir(item) != 0:
raise RuntimeError("Cannot remove non-empty directory:", item)
os.rmdir(item)
else:
os.remove(item)
# Process config files and write examples
for my_config in my_configs:
cnf = MyConfigParser()
cnf.read(my_config)
for sec in cnf.sections():
cnf_vars = dict(cnf.items(sec))
cnf_keys = list(cnf_vars.keys())
cnf_keys.sort()
out_data = ""
# Uncomment variables in template data
for line in inp_data:
do_print = True
for key in cnf_keys:
if ( re.match("#%s=" % (key),line) or \
(re.match("#fcflags_opt_",line) and re.match("fcflags_opt_",key)) ):
if ( key_is_ok(key) ):
out_data += "%s=\"%s\"\n" % (key,cnf_vars[key])
do_print = False
if ( do_print ):
out_data += line
# Inject fbversion in out_data
out_data=out_data.replace("_FB_",fbversion)
# Write data
out_path = os.path.join(my_outdir, sec+".ac9")
open(out_path, "wt").write(out_data)
# FIXME: Create symbolic link until the test farm gets updated
old_path = os.path.join(my_outdir, sec+".ac")
if ( os.path.exists(old_path) or os.path.islink(old_path) ):
os.remove(old_path)
os.symlink(sec+".ac9", old_path)
|