File: clean-build-examples

package info (click to toggle)
abinit 9.10.4-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 518,712 kB
  • sloc: xml: 877,568; f90: 577,240; python: 80,760; perl: 7,019; ansic: 4,585; sh: 1,925; javascript: 601; fortran: 557; cpp: 454; objc: 323; makefile: 77; csh: 42; pascal: 31
file content (59 lines) | stat: -rwxr-xr-x 1,637 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
#!/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

from time import gmtime,strftime

import os
import re
import sys

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

#
# Main program
#

# Initial setup
my_name    = "clean-build-examples"

# 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)

# Init
re_cf = re.compile("\.cf$")
re_garbage = re.compile("#")

# What time is it?
now = strftime("%Y/%m/%d %H:%M:%S +0000",gmtime())

# Process all existing build examples
for (root,dirs,files) in os.walk("./doc/build/config-examples"):

  for src in files:
    if ( re_cf.search(src) ):
      cf_inp = file(os.path.join(root,src),"r").readlines()
      cf_out = list()
      cf_chk = dict()

      for line in cf_inp:
        if ( not re_garbage.match(line) ):
          cf_out.append(line)
          (key,val) = re.sub("\t+","\t",line).split("\t")
          cf_chk[key] = val

      open(os.path.join(root,src),"wt").write("".join(cf_out))

      if ( "filename" not in cf_chk ):
        sys.stderr.write("%s: Error: %s has no 'filename' field\n" % \
          (my_name,os.path.join(root,src)))