summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorSerhii Kostiuk <serhii.o.kostiuk@globallogic.com>2021-05-21 12:42:52 +0300
committerSerhii Kostiuk <serhii.o.kostiuk@globallogic.com>2021-05-21 12:45:29 +0300
commite37ef41001d2f9de47efc66e4ea573b88aa972c6 (patch)
tree30416366ff6882f551613f67ae33272530387dbd /scripts
parentd562fa43d6f61c0a6ad4fb79e91c90cf571884f3 (diff)
downloadlibmts-io-e37ef41001d2f9de47efc66e4ea573b88aa972c6.tar.gz
libmts-io-e37ef41001d2f9de47efc66e4ea573b88aa972c6.tar.bz2
libmts-io-e37ef41001d2f9de47efc66e4ea573b88aa972c6.zip
[GP-1111] mPower R. Apr 2021: +CEMODE shall be set to CEMODE=2
Ported the "generate_mcc_mnc_cpp.py" script to Python 3. Python 2 is not supported anymore and is not included to the modern distributions of Linux. The transformation is made mainly by `2to3` without refactoring and with only minimal changes required to support Python 3.
Diffstat (limited to 'scripts')
-rw-r--r--scripts/create-mcc-mnc-table.py140
1 files changed, 72 insertions, 68 deletions
diff --git a/scripts/create-mcc-mnc-table.py b/scripts/create-mcc-mnc-table.py
index cc30fef..a5af7c4 100644
--- a/scripts/create-mcc-mnc-table.py
+++ b/scripts/create-mcc-mnc-table.py
@@ -1,3 +1,5 @@
+#!/usr/bin/env python3
+
#Generates MTS_IO_MccMncTable.cpp file by pulling latest MCC/MNC values
#from http://mcc-mnc.com
@@ -5,73 +7,75 @@
import re
-import urllib2
+import urllib.request
+import urllib.parse
import datetime
-print "/*!"
-print " \\file MTS_IO_MccMncTable.cpp"
-print " \\brief Auto-Generated MCC-MNC Lookup Table"
-print " \\date " + str(datetime.date.today())
-print " \\author sgodinez"
-print ""
-print " An Auto-Generated MCC-MNC Lookup Table"
-print "*/"
-print ""
-print "#include <mts/MTS_IO_MccMncTable.h>"
-print "#include <mts/MTS_Logger.h>"
-print "#include <mts/MTS_Text.h>"
-print ""
-print "using namespace MTS::IO;"
-print ""
-print "MTS::AutoPtr<MTS::Lock> MccMncTable::m_apLock(new MTS::Lock());"
-print "MccMncTable* MccMncTable::m_pInstance = NULL;"
-print ""
-print "MccMncTable* MccMncTable::getInstance() {"
-print " if(m_pInstance == NULL) {"
-print " m_apLock->lock();"
-print " if (m_pInstance == NULL) {"
-print " m_pInstance = new MccMncTable();"
-print " }"
-print " m_apLock->unlock();"
-print " }"
-print " return m_pInstance;"
-print "}"
-print ""
-print "MccMncTable::MccMncTable() {"
-print " createTable();"
-print "}"
-print ""
-print "Json::Value MccMncTable::lookup(const std::string& sMcc, const std::string& sMnc) {"
-print " uint32_t iMcc, iMnc;"
-print " std::string sNormalizedMnc = sMnc;"
-print ' printTrace("[MCCMNC] MCCx[%s] MNCx[%s]", sMcc.c_str(), sMnc.c_str());'
-print " if (sMnc.length() == 2) {"
-print " sNormalizedMnc += 'f';"
-print " }"
-print " if (!MTS::Text::parseHex(iMcc, sMcc)) { return Json::Value::null; }"
-print " if (!MTS::Text::parseHex(iMnc, sNormalizedMnc)) { return Json::Value::null; }"
-print ' printTrace("[MCCMNC] MCC0X[%d] MNC0X[%d]", iMcc, iMnc);'
-print " if (m_mTable.count(iMcc)) {"
-print " if(m_mTable[iMcc].count(iMnc)) {"
-print " std::vector<std::string> vJson = MTS::Text::split(m_mTable[iMcc][iMnc], ',');"
-print " Json::Value j;"
-print ' j["iso"] = vJson[0];'
-print ' j["country"] = vJson[1];'
-print ' j["code"] = vJson[2];'
-print ' j["carrier"] = vJson[3];'
-print " return j;"
-print " }"
-print " }"
-print ""
-print " return Json::Value::null;"
-print "}"
-print ""
-print "void MccMncTable::createTable() {"
-print " std::string sData;"
+print("/*!")
+print(" \\file MTS_IO_MccMncTable.cpp")
+print(" \\brief Auto-Generated MCC-MNC Lookup Table")
+print(" \\date " + str(datetime.date.today()))
+print(" \\author sgodinez")
+print("")
+print(" An Auto-Generated MCC-MNC Lookup Table")
+print("*/")
+print("")
+print("#include <mts/MTS_IO_MccMncTable.h>")
+print("#include <mts/MTS_Logger.h>")
+print("#include <mts/MTS_Text.h>")
+print("")
+print("using namespace MTS::IO;")
+print("")
+print("MTS::AutoPtr<MTS::Lock> MccMncTable::m_apLock(new MTS::Lock());")
+print("MccMncTable* MccMncTable::m_pInstance = NULL;")
+print("")
+print("MccMncTable* MccMncTable::getInstance() {")
+print(" if(m_pInstance == NULL) {")
+print(" m_apLock->lock();")
+print(" if (m_pInstance == NULL) {")
+print(" m_pInstance = new MccMncTable();")
+print(" }")
+print(" m_apLock->unlock();")
+print(" }")
+print(" return m_pInstance;")
+print("}")
+print("")
+print("MccMncTable::MccMncTable() {")
+print(" createTable();")
+print("}")
+print("")
+print("Json::Value MccMncTable::lookup(const std::string& sMcc, const std::string& sMnc) {")
+print(" uint32_t iMcc, iMnc;")
+print(" std::string sNormalizedMnc = sMnc;")
+print(' printTrace("[MCCMNC] MCCx[%s] MNCx[%s]", sMcc.c_str(), sMnc.c_str());')
+print(" if (sMnc.length() == 2) {")
+print(" sNormalizedMnc += 'f';")
+print(" }")
+print(" if (!MTS::Text::parseHex(iMcc, sMcc)) { return Json::Value::null; }")
+print(" if (!MTS::Text::parseHex(iMnc, sNormalizedMnc)) { return Json::Value::null; }")
+print(' printTrace("[MCCMNC] MCC0X[%d] MNC0X[%d]", iMcc, iMnc);')
+print(" if (m_mTable.count(iMcc)) {")
+print(" if(m_mTable[iMcc].count(iMnc)) {")
+print(" std::vector<std::string> vJson = MTS::Text::split(m_mTable[iMcc][iMnc], ',');")
+print(" Json::Value j;")
+print(' j["iso"] = vJson[0];')
+print(' j["country"] = vJson[1];')
+print(' j["code"] = vJson[2];')
+print(' j["carrier"] = vJson[3];')
+print(" return j;")
+print(" }")
+print(" }")
+print("")
+print(" return Json::Value::null;")
+print("}")
+print("")
+print("void MccMncTable::createTable() {")
+print(" std::string sData;")
td_re = re.compile('<td>([^<]*)</td>'*6)
-html = urllib2.urlopen('http://mcc-mnc.com/').read()
+html_bytes = urllib.request.urlopen('http://mcc-mnc.com/').read() # type: bytes
+html = html_bytes.decode(encoding='utf-8')
tbody_start = False
for line in html.split('\n'):
@@ -94,15 +98,15 @@ for line in html.split('\n'):
mnc_int = int(mnc + 'f', 16)
else:
mnc_int = int(mnc, 16)
- print ' m_mTable[' + str(mcc_int) + '][' + str(mnc_int) + '] = "' + \
- iso + ',' + countryCode + ',' + country + ',' + carrier + '";'
- else:
- print " //MCC(" + mcc + ') MNC(N/A) ISO(' + iso + ') Country Code(' + countryCode + ') Country(' + country + ') Carrier(' + carrier + ')'
+ print(' m_mTable[' + str(mcc_int) + '][' + str(mnc_int) + '] = "' + \
+ iso + ',' + countryCode + ',' + country + ',' + carrier + '";')
+ else:
+ print(" //MCC(" + mcc + ') MNC(N/A) ISO(' + iso + ') Country Code(' + countryCode + ') Country(' + country + ') Carrier(' + carrier + ')')
-print "}"
-print ""
+print("}")
+print("")