search_repl.py 2.57 KB
Newer Older
1
#!/usr/bin/python
2 3 4 5 6
#/*
# * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
# * contributor license agreements.  See the NOTICE file distributed with
# * this work for additional information regarding copyright ownership.
# * The OpenAirInterface Software Alliance licenses this file to You under
Cedric Roux's avatar
Cedric Roux committed
7
# * the OAI Public License, Version 1.1  (the "License"); you may not use this file
8 9 10 11 12 13 14 15 16 17 18 19 20 21
# * except in compliance with the License.
# * You may obtain a copy of the License at
# *
# *      http://www.openairinterface.org/?page_id=698
# *
# * Unless required by applicable law or agreed to in writing, software
# * distributed under the License is distributed on an "AS IS" BASIS,
# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# * See the License for the specific language governing permissions and
# * limitations under the License.
# *-------------------------------------------------------------------------------
# * For more information about the OpenAirInterface (OAI) Software Alliance:
# *      contact@openairinterface.org
# */
Rohit Gupta's avatar
Rohit Gupta committed
22 23 24

# \author Navid Nikaein, Rohit Gupta

25 26
import sys
import re
27
import os
28 29 30 31 32 33

#Arg 1 name of file
#Arg 2 keyword
#arg 3 replacement text
#Note that these should be seperated by spaces
if len(sys.argv) != 4:
34
  print "search_repl.py: Wrong number of arguments. This program needs 3 arguments. The number of arguments supplied : " + str(sys.argv)
35
  sys.exit()
36
filename = os.path.expandvars(sys.argv[1])
37 38 39
keyword = sys.argv[2]
replacement_text = sys.argv[3]

40

41 42 43 44 45 46
file = open(filename, 'r')
string = file.read()
file.close()


if keyword == 'mme_ip_address':
47
   replacement_text = keyword + ' =  ( { ' + replacement_text + ' } ) ; '
48
   string = re.sub(r"mme_ip_address\s*=\s*\(([^\$]+?)\)\s*;", replacement_text, string, re.M)
49
elif keyword == 'IPV4_LIST' or keyword=='GUMMEI_LIST' or keyword == 'TAI_LIST':
50
   replacement_text = keyword + ' =  ( ' + replacement_text + '  ) ; '
51
   string = re.sub(r"%s\s*=\s*\(([^\$]+?)\)\s*;" % keyword, replacement_text, string, re.M)
52 53 54
elif keyword == 'rrh_gw_config':
   replacement_text = keyword + ' =  ( { ' + replacement_text + ' } ) ; '
   string = re.sub(r"rrh_gw_config\s*=\s*\(([^\$]+?)\)\s*;", replacement_text, string, re.M)
55
else :
56 57
   replacement_text = keyword + ' =  ' + replacement_text + ' ; '
   string = re.sub(r"%s\s*=\s*([^\$]+?)\s*;" % keyword , replacement_text, string, re.M)   
58 59 60
#else : 
#   replacement_text = keyword + ' =\"' + replacement_text + '\" ; '
#   string = re.sub(r"%s\s*=\s*\"([^\$]+?)\"\s*;" % keyword , replacement_text, string, re.M)
61 62 63 64 65

file = open(filename, 'w')
file.write(string)
file.close()