generateTemplate.py 4.9 KB
Newer Older
1 2 3
#/*
# * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
# * contributor license agreements.  See the NOTICE file distributed with
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
# * this work for additional information regarding copyright ownership.
# * The OpenAirInterface Software Alliance licenses this file to You under
# * the OAI Public License, Version 1.1  (the "License"); you may not use this file
# * 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
# */
#---------------------------------------------------------------------

#-----------------------------------------------------------
# Import
#-----------------------------------------------------------
26
import re
27
import yaml
28
import os
29
import sys
30 31


32 33 34 35 36
def main():
  #read yaml input parameters
  f = open(f'{sys.argv[1]}',)
  data = yaml.full_load(f)
  dir = os.listdir(f'{data[0]["paths"]["source_dir"]}')
37

38 39 40 41
  #identify configs, read and replace corresponding values
  for config in data[1]["configurations"]:
    filePrefix = config["filePrefix"]
    outputfilename = config["outputfilename"]
42
    print('================================================')
43 44
    print('filePrefix = ' + filePrefix)
    print('outputfilename = ' + outputfilename)
45 46
    for inputfile in dir:
      if inputfile.find(filePrefix) >=0:
47 48
        prefix_outputfile = {"cu.band7.tm1.25PRB": f'{data[0]["paths"]["dest_dir"]}/{outputfilename}', 
                             "du.band7.tm1.25PRB": f'{data[0]["paths"]["dest_dir"]}/{outputfilename}',
49 50
                             "rru.fdd": f'{data[0]["paths"]["dest_dir"]}/{outputfilename}',
                             "rru.tdd": f'{data[0]["paths"]["dest_dir"]}/{outputfilename}',
51
                             "enb.band7.tm1.fr1.25PRB.usrpb210.conf": f'{data[0]["paths"]["dest_dir"]}/{outputfilename}',
Mohammed Ismail's avatar
Mohammed Ismail committed
52
                             "enb.band40.tm1.25PRB.FairScheduler.usrpb210": f'{data[0]["paths"]["dest_dir"]}/{outputfilename}',
53
                             "rcc.band7.tm1.nfapi": f'{data[0]["paths"]["dest_dir"]}/{outputfilename}',
54 55
                             "rcc.band7.tm1.if4p5.lo.25PRB": f'{data[0]["paths"]["dest_dir"]}/{outputfilename}',
                             "rcc.band40.tm1.25PRB": f'{data[0]["paths"]["dest_dir"]}/{outputfilename}',
56
                             "gnb.band78.tm1.fr1.106PRB.usrpb210.conf": f'{data[0]["paths"]["dest_dir"]}/{outputfilename}',
57 58
                             "ue.nfapi": f'{data[0]["paths"]["dest_dir"]}/{outputfilename}',
                             "ue_sim_ci": f'{data[0]["paths"]["dest_dir"]}/{outputfilename}'
59
                             }
60
        print('inputfile = ' + inputfile)
61 62
        if filePrefix in prefix_outputfile:
          outputfile1 = prefix_outputfile[filePrefix]  
63

64 65 66 67 68 69 70 71
        directory = f'{data[0]["paths"]["dest_dir"]}'
        if not os.path.exists(directory):
          os.makedirs(directory, exist_ok=True)

        with open(f'{data[0]["paths"]["source_dir"]}{inputfile}', mode='r') as inputfile, \
             open(outputfile1, mode='w') as outputfile:
          for line in inputfile:
            count = 0
72 73 74
            if re.search(r'EHPLMN_LIST', line):
              outputfile.write(line)
              continue
75 76 77 78 79 80 81 82 83 84 85 86 87 88
            for key in config["config"]:
              if line.find(key["key"]) >= 0:
                count += 1
                if re.search(r'preference', line):
                  templine = line
                elif re.search(r'plmn_list', line):
                  templine = re.sub(r'[0-9]+', '""', line)
                  templine = re.sub(r'\"\"', key["env"]["mcc"], templine, 1)
                  templine = re.sub(r'\"\"', key["env"]["mnc"], templine, 1) 
                  templine = re.sub(r'\"\"', key["env"]["mnc_length"], templine, 1)               
                elif re.search('downlink_frequency', line):
                  templine = re.sub(r'[0-9]+', key["env"], line)
                elif re.search('uplink_frequency_offset', line):
                  templine = re.sub(r'[0-9]+', key["env"], line)
89
               
90 91 92 93 94
                elif re.search(r'"(.*?)"', line):
                  templine = re.sub(r'(?<=")[^"]*(?=")', key["env"], line)    
                elif re.search(r'[0-9]', line):
                  templine = re.sub(r'\d+', key["env"], line)
                outputfile.write(templine)
95
            
96 97 98 99 100
            if count == 0:
              outputfile.write(line)
              
if __name__ == "__main__":
    main()