~abinit-maintainers/abinit/6.0-stable

« back to all changes in this revision

Viewing changes to config/scripts/update-options-conf

  • Committer: gonze
  • Date: 2010-03-05 21:09:44 UTC
  • mfrom: (172.2.2 6.0.3-private)
  • Revision ID: gonze@testf.pcpm.ucl.ac.be-20100305210944-um1081is9nepkm3k
Merge pouillon/6.0.3-public/174
added:
  config/scripts/reshape-options-conf
  config/scripts/update-options-conf
  config/scripts/update-version-number
pending merges:
  Yann Pouillon 2010-03-03 [merge] Merged trunk/6.0.3-public/173
    Yann Pouillon 2010-03-02 Imported Forge scripts from 6.1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
#
 
3
# Copyright (C) 2010 ABINIT Group (Yann Pouillon)
 
4
#
 
5
# This file is part of the ABINIT software package. For license information,
 
6
# please see the COPYING file in the top-level directory of the ABINIT source
 
7
# distribution.
 
8
#
 
9
 
 
10
from ConfigParser import ConfigParser
 
11
from time import gmtime,strftime
 
12
 
 
13
import commands
 
14
import os
 
15
import re
 
16
import sys
 
17
 
 
18
class MyConfigParser(ConfigParser):
 
19
 
 
20
  def optionxform(self,option):
 
21
    return str(option)
 
22
 
 
23
# ---------------------------------------------------------------------------- #
 
24
 
 
25
#
 
26
# Main program
 
27
#
 
28
 
 
29
# Initial setup
 
30
my_name   = "update-options-conf"
 
31
my_config = "config/specs/options.conf"
 
32
 
 
33
# Check if we are in the top of the ABINIT source tree
 
34
if ( not os.path.exists("configure.ac") or
 
35
     not os.path.exists("src/98_main/abinit.F90") ):
 
36
  print "%s: You must be in the top of an ABINIT source tree." % my_name
 
37
  print "%s: Aborting now." % my_name
 
38
  sys.exit(1)
 
39
 
 
40
# Check config file(s)
 
41
if ( not os.path.exists(my_config) ):
 
42
  print "%s: Could not find config file (%s)." % (my_name,cnf_file)
 
43
  print "%s: Aborting now." % my_name
 
44
  sys.exit(2)
 
45
 
 
46
# What time is it?
 
47
now = strftime("%Y/%m/%d %H:%M:%S +0000",gmtime())
 
48
 
 
49
# Init
 
50
re_sta = re.compile("^status.*(changed|new|removed|renamed)")
 
51
re_sec = re.compile("^\\[.*\\]$")
 
52
cnf = MyConfigParser()
 
53
cnf.read(my_config)
 
54
opt_inp = file(my_config,"r").readlines()
 
55
opt_out = ""
 
56
 
 
57
# Process config file
 
58
sec_buf = ""
 
59
sec_del = False
 
60
sec_idx = 0
 
61
sec_sta = ""
 
62
sec_tit = ""
 
63
for i in range(0,len(opt_inp)):
 
64
  line = opt_inp[i]
 
65
 
 
66
  # Starting a new section
 
67
  if ( re_sec.match(line) ):
 
68
    if ( not sec_del ):
 
69
      opt_out += sec_buf
 
70
    sec_buf = ""
 
71
    sec_del = False
 
72
    sec_idx = i
 
73
    sec_tit = re.sub("[\\[\\]]","",line).strip()
 
74
 
 
75
    if ( sec_tit != "DEFAULT" ):
 
76
      sec_sta = cnf.get(sec_tit,"status")
 
77
      if ( sec_sta == "removed" ):
 
78
        sec_del = True
 
79
 
 
80
  # Delete all status lines, but obsolete and unchanged
 
81
  if ( not re_sta.match(line) ):
 
82
    sec_buf += line
 
83
 
 
84
# Rewrite config file
 
85
file(my_config,"w").write(opt_out)