sat_environment.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937
  1. # -*- coding:utf-8 -*-
  2. import sys, os, time
  3. reload(sys)
  4. sys.setdefaultencoding("utf-8")
  5. from utils.platform_Util import *
  6. from ConfigParser import *
  7. import json
  8. class TConfig:
  9. def __init__(self, ini_path):
  10. self.path = ini_path
  11. # 保存修改;
  12. def save_config(self, cfgParser):
  13. with open(self.path, 'wb') as configfile:
  14. if cfgParser:
  15. cfgParser.write(configfile)
  16. # 字符转字典;
  17. def get_dict(self, value):
  18. return json.loads(value)
  19. def get_value_dict(self, section, option):
  20. value = self.get_value(section, option)
  21. if value is None:
  22. return {}
  23. return json.loads(value)
  24. # 获取参数值;默认返回字符串
  25. def get_value(self, section, option):
  26. # 读取配置文件;
  27. cfgParser = ConfigParser()
  28. cfgParser.read(self.path)
  29. if cfgParser.has_option(section, option):
  30. return cfgParser.get(section, option)
  31. return None
  32. # 获取参数值;
  33. def get_int(self, section, option):
  34. # 读取配置文件;
  35. cfgParser = ConfigParser()
  36. cfgParser.read(self.path)
  37. if cfgParser.has_option(section, option):
  38. return cfgParser.getint(section, option)
  39. return None
  40. # 获取参数值;
  41. def get_float(self, section, option):
  42. # 读取配置文件;
  43. cfgParser = ConfigParser()
  44. cfgParser.read(self.path)
  45. if cfgParser.has_option(section, option):
  46. return cfgParser.getfloat(section, option)
  47. return None
  48. # 获取参数值;
  49. def get_boolean(self, section, option):
  50. # 读取配置文件;
  51. cfgParser = ConfigParser()
  52. cfgParser.read(self.path)
  53. if cfgParser.has_option(section, option):
  54. return cfgParser.getboolean(section, option)
  55. return None
  56. # 获取键值;
  57. def get_options(self, section):
  58. # 读取配置文件;
  59. cfgParser = ConfigParser()
  60. cfgParser.read(self.path)
  61. if cfgParser.has_section(section):
  62. return cfgParser.options(section)
  63. return None
  64. # 获取所有sections;
  65. def get_sections(self):
  66. # 读取配置文件;
  67. cfgParser = ConfigParser()
  68. cfgParser.read(self.path)
  69. return cfgParser.sections()
  70. # 获取指定section所有items;
  71. def get_items(self, section):
  72. # 读取配置文件;
  73. cfgParser = ConfigParser()
  74. cfgParser.read(self.path)
  75. if cfgParser.has_section(section):
  76. return cfgParser.items(section)
  77. return None
  78. # 添加section;
  79. def add_section(self, section):
  80. # 读取配置文件;
  81. cfgParser = ConfigParser()
  82. cfgParser.read(self.path)
  83. if cfgParser.has_section(section) is False:
  84. cfgParser.add_section(section)
  85. # 保存修改;
  86. self.save_config(cfgParser)
  87. # 设置值;
  88. def set_value(self, section, option, value):
  89. # 读取配置文件;
  90. cfgParser = ConfigParser()
  91. cfgParser.read(self.path)
  92. if cfgParser.has_section(section) is False:
  93. cfgParser.add_section(section)
  94. cfgParser.set(section, option, value)
  95. # 保存修改;
  96. self.save_config(cfgParser)
  97. # 删除指定option;
  98. def del_option(self, section, option):
  99. # 读取配置文件;
  100. cfgParser = ConfigParser()
  101. cfgParser.read(self.path)
  102. cfgParser.remove_option(section, option)
  103. # 保存修改;
  104. self.save_config(cfgParser)
  105. # 删除section;
  106. def del_section(self, section):
  107. # 读取配置文件;
  108. cfgParser = ConfigParser()
  109. cfgParser.read(self.path)
  110. cfgParser.remove_section(section)
  111. # 保存修改;
  112. self.save_config(cfgParser)
  113. def has_section(self, section):
  114. # 读取配置文件;
  115. cfgParser = ConfigParser()
  116. cfgParser.read(self.path)
  117. return cfgParser.has_section(section)
  118. def has_option(self, section, option):
  119. # 读取配置文件;
  120. cfgParser = ConfigParser()
  121. cfgParser.read(self.path)
  122. return cfgParser.has_option(section, option)
  123. try:
  124. # Python_Home = os.environ["PYTHONHOME"].split(";")[0]
  125. Python_Home = sys.prefix
  126. # Resource_CFG_Path = Python_Home + Environment.SDK_Relative_Path + "config/resource.cfg"
  127. Resource_CFG_Path = Python_Home + Environment.SDK_Relative_Path + "config/resource_run.cfg"
  128. Resource_CFG_Local_Path = Python_Home + Environment.SDK_Relative_Path + "config/resource.cfg"
  129. if not os.path.exists(Resource_CFG_Path):
  130. print 'server_run.cfg文件不存在,复制server.cfg文件'
  131. shutil.copy(Resource_CFG_Local_Path, Resource_CFG_Path)
  132. # Resource_CFG_Path = "config/resource.cfg"
  133. # 获取22293的配置路径
  134. COMConfigPath = os.path.join(Python_Home, 'Tools', 'Config', 'COMConfig.txt')
  135. Home_Init = True
  136. except KeyError, e:
  137. print "KeyError:", e.message
  138. Home_Init = False
  139. CFG_DICT = {}
  140. def getResourceConfigPath():
  141. return Resource_CFG_Path
  142. def mkCHdir(dir):
  143. # print "mkCHdir,dir=", dir
  144. if (os.path.exists(dir)):
  145. return dir
  146. # 例如:D:/SAT/result_schedule_id_schedule_name_task_number//detail
  147. # os.path.splite结果:('D:/SAT/result_schedule_id_schedule_name_task_number', 'detail')
  148. # 过滤//多个分割符的情况
  149. preDir = os.path.split(dir)[0]
  150. # print "mkdir,preDir=", preDir
  151. if (not os.path.exists(preDir)):
  152. mkCHdir(preDir)
  153. # 防止目录字符串最后带有/的情况,会出现两次创建同一个目录
  154. # 例如: D:/SAT/。会创建D:/SAT和D:/SAT/
  155. if (not os.path.exists(dir)):
  156. os.mkdir(dir)
  157. return dir
  158. def setLineParam(line):
  159. global CFG_DICT
  160. lineArr = line.split("=")
  161. # print "setLineParam,lineArr:", lineArr
  162. if (lineArr.__len__() == 2):
  163. CFG_DICT[lineArr[0].strip(" ")] = lineArr[1].strip(" ")
  164. def loadResourceCfg():
  165. global CFG_DICT
  166. if Home_Init == False:
  167. print "Not found config file,Please set the os path of PYTHONHOME"
  168. return False
  169. cfgFile = open(Resource_CFG_Path, "r", -1)
  170. strline = "init"
  171. while (strline <> None and strline <> ""):
  172. strline = cfgFile.readline().strip("\n").strip("\r")
  173. # print "line:", strline
  174. info = strline.decode("utf-8", "error")
  175. # 防止文本读取结束时,“#”判断出错
  176. if (info.__len__() > 1 and info[0] <> "#"):
  177. setLineParam(info)
  178. cfgFile.close()
  179. return True
  180. g_cfgParser = None
  181. def parseResourceCfg():
  182. global g_cfgParser
  183. global CFG_DICT
  184. if Home_Init == False:
  185. print "Not found config file,Please set the os path of PYTHONHOME"
  186. return False
  187. g_cfgParser = TConfig(Resource_CFG_Path)
  188. return True
  189. parseResourceCfg()
  190. def getOCRIpAddr():
  191. try:
  192. return g_cfgParser.get_value("COMM", "Env_OCR_IP_ADDR")
  193. except Exception, e:
  194. print e
  195. return ""
  196. def getOCRPort():
  197. try:
  198. return g_cfgParser.get_int("COMM", "Env_OCR_PORT")
  199. except Exception, e:
  200. print e
  201. return -1
  202. def getSerialCOM():
  203. try:
  204. return g_cfgParser.get_value("COMM", "Serial_Communicator_Port")
  205. except Exception, e:
  206. print e
  207. return ""
  208. def getSATHome():
  209. try:
  210. return g_cfgParser.get_value("COMM", "SAT_HOME")
  211. except Exception, e:
  212. print e
  213. return ""
  214. def getScriptExecDIR():
  215. satHome = getSATHome()
  216. return os.path.join(satHome, "ScriptExec")
  217. def getSATTmpDIR():
  218. path = g_cfgParser.get_value("COMM", "sat_tmp")
  219. if path is None:
  220. satHome = getSATHome()
  221. return os.path.join(satHome, "tmp")
  222. else:
  223. return path
  224. def getSATTranslationDIR():
  225. satHome = getSATHome()
  226. return os.path.join(satHome, "translation")
  227. def getSATRCUDIR():
  228. satHome = getSATHome()
  229. return os.path.join(satHome, "resource", "RCU")
  230. def getSATRCUGeneralDIR():
  231. SATRCUDIR = getSATRCUDIR()
  232. return os.path.join(SATRCUDIR, "general")
  233. def getSATRCUProductDIR():
  234. SATRCUDIR = getSATRCUDIR()
  235. return os.path.join(SATRCUDIR, "product")
  236. def getSATSmokingDIR():
  237. satHome = getSATHome()
  238. return os.path.join(satHome, "smoking")
  239. def getSATSmokingDownloaDIR():
  240. SATSmokingDIR = getSATSmokingDIR()
  241. return os.path.join(SATSmokingDIR, "download")
  242. def getSATSmokingOTAAPKDIR():
  243. SATSmokingDIR = getSATSmokingDIR()
  244. return os.path.join(SATSmokingDIR, "ota_apk")
  245. def getSATMenuTreeDIR():
  246. satHome = getSATHome()
  247. return os.path.join(satHome, "resource", "MenuTree")
  248. def getOCRTmpDir():
  249. tmpDir = getSATTmpDIR()
  250. return os.path.join(tmpDir, "ocr")
  251. def getOCRErrDir():
  252. tmpDir = getSATTmpDIR()
  253. return os.path.join(tmpDir, "ocr_err")
  254. def getSATProjectCfgDIR():
  255. return os.path.join(getSATHome(), "resource", "projectCfg")
  256. def getResourceBaseDIR():
  257. satHome = getSATHome()
  258. return os.path.join(satHome, "resource")
  259. def getHDMIResourceDIR():
  260. return os.path.join(getResourceBaseDIR(), "HDMI")
  261. def getHDMIstdTPDIR():
  262. return os.path.join(getHDMIResourceDIR(), "std_timing_pattern")
  263. def getAVResourceDIR():
  264. return os.path.join(getResourceBaseDIR(), "AV")
  265. def getAVstdTPDIR():
  266. return os.path.join(getAVResourceDIR(), "std_timing_pattern")
  267. def getVGAResourceDIR():
  268. return os.path.join(getResourceBaseDIR(), "VGA")
  269. def getVGAstdTPDIR():
  270. return os.path.join(getVGAResourceDIR(), "std_timing_pattern")
  271. def getYpbprResourceDIR():
  272. return os.path.join(getResourceBaseDIR(), "YPBPR")
  273. def getYpbprstdTPDIR():
  274. return os.path.join(getYpbprResourceDIR(), "std_timing_pattern")
  275. def getDTVResourceDIR():
  276. return os.path.join(getResourceBaseDIR(), "DTV")
  277. def getDTVstdTPDIR():
  278. return os.path.join(getDTVResourceDIR(), "std_ts")
  279. def getATVResourceDIR():
  280. return os.path.join(getResourceBaseDIR(), "ATV")
  281. def getATVstdTPDIR():
  282. return os.path.join(getATVResourceDIR(), "std_ts")
  283. def getResultDir():
  284. try:
  285. return g_cfgParser.get_value("COMM", "SAT_RESULT_DIR")
  286. except Exception, e:
  287. print e
  288. return "Error"
  289. def getPathModelDIR():
  290. return os.path.join(getSATHome(), "model")
  291. def getAbnormalDir():
  292. return os.path.join(getSATHome(), "abnormal")
  293. def initDirs():
  294. print mkCHdir(getSATHome())
  295. print mkCHdir(getResourceBaseDIR())
  296. print mkCHdir(getScriptExecDIR())
  297. print mkCHdir(getSATTmpDIR())
  298. print mkCHdir(getSATMenuTreeDIR())
  299. print mkCHdir(getHDMIResourceDIR())
  300. print mkCHdir(getHDMIstdTPDIR())
  301. print mkCHdir(getAVResourceDIR())
  302. print mkCHdir(getAVstdTPDIR())
  303. print mkCHdir(getVGAResourceDIR())
  304. print mkCHdir(getVGAstdTPDIR())
  305. print mkCHdir(getYpbprResourceDIR())
  306. print mkCHdir(getYpbprstdTPDIR())
  307. print mkCHdir(getDTVResourceDIR())
  308. print mkCHdir(getDTVstdTPDIR())
  309. print mkCHdir(getATVResourceDIR())
  310. print mkCHdir(getATVstdTPDIR())
  311. print mkCHdir(getResultDir())
  312. print mkCHdir(getPathModelDIR())
  313. print mkCHdir(getAbnormalDir())
  314. print mkCHdir(getOCRTmpDir())
  315. print mkCHdir(getSATTranslationDIR())
  316. print mkCHdir(getSATRCUDIR())
  317. print mkCHdir(getSATRCUGeneralDIR())
  318. print mkCHdir(getSATRCUProductDIR())
  319. print mkCHdir(getSATSmokingDIR())
  320. print mkCHdir(getSATSmokingDownloaDIR())
  321. print mkCHdir(getSATSmokingOTAAPKDIR())
  322. initDirs()
  323. def setSATHome(dir):
  324. try:
  325. g_cfgParser.set_value("COMM", "SAT_HOME", dir)
  326. # g_cfgParser.write(open(Resource_CFG_Path, "w"))
  327. except Exception, e:
  328. print e
  329. def setSATTmpDir(dir):
  330. try:
  331. g_cfgParser.set_value("COMM", "sat_tmp", dir)
  332. # g_cfgParser.write(open(Resource_CFG_Path, "w"))
  333. except Exception, e:
  334. print e
  335. def setResultDir(dir):
  336. try:
  337. g_cfgParser.set_value("COMM", "SAT_RESULT_DIR", dir)
  338. # g_cfgParser.write(open(Resource_CFG_Path, "w"))
  339. except Exception, e:
  340. print e
  341. def setScriptResultDIR(dir):
  342. try:
  343. g_cfgParser.set_value("COMM", "sat_script_dir", dir)
  344. # g_cfgParser.write(open(Resource_CFG_Path, "w"))
  345. except Exception, e:
  346. print e
  347. def getUB530_Port():
  348. return g_cfgParser.get_value("COMM", "ub530_port")
  349. def getTG39_Port():
  350. return g_cfgParser.get_value("COMM", "tg39_port")
  351. def get22293_Port():
  352. f = open(COMConfigPath)
  353. data = f.read()
  354. f.close()
  355. data_dict = eval(data)
  356. sourcegeninput = data_dict['SourceGenInput']
  357. return sourcegeninput
  358. def getRCUDeviceList():
  359. try:
  360. return eval(g_cfgParser.get_value("devices", "rcudevice_list"))
  361. except Exception,e:
  362. return ['redrat3','redrat4']
  363. def getRCUDeviceSelected():
  364. try:
  365. return g_cfgParser.get_value("devices", "rcudevice_selected")
  366. except Exception,e:
  367. return 'redrat3'
  368. def writeRCUDeviceSelected(rcu_device):
  369. g_cfgParser.set_value('devices', 'rcudevice_selected', rcu_device)
  370. def getRCUSelected():
  371. return g_cfgParser.get_value("devices", "rcu_selected")
  372. def getCcardSelected():
  373. return g_cfgParser.get_value("devices", "ccard_selected")
  374. def getATVSelected():
  375. return g_cfgParser.get_value("devices", "atv_selected")
  376. def getDTVSelected():
  377. return g_cfgParser.get_value("devices", "dtv_selected")
  378. def getAtv_list():
  379. return eval(g_cfgParser.get_value("devices", "atv_list"))
  380. def getDtv_list():
  381. return eval(g_cfgParser.get_value("devices", "dtv_list"))
  382. def writeDtv_list(dtv_list):
  383. g_cfgParser.set_value('devices', 'dtv_list', str(dtv_list))
  384. def getCcard_list():
  385. return eval(g_cfgParser.get_value("devices", "ccard_list"))
  386. def writeCcard_list(ccard_list):
  387. g_cfgParser.set_value('devices', 'ccard_list', str(ccard_list))
  388. def getVoicecard_list():
  389. return eval(g_cfgParser.get_value("devices", "voicecard_list"))
  390. def getSignalcard_list():
  391. return eval(g_cfgParser.get_value("devices", "signalcard_list"))
  392. def getSerialport_list():
  393. return eval(g_cfgParser.get_value("devices", "serialport_list"))
  394. def writeRCUSelected(rcu_selected_value):
  395. g_cfgParser.set_value('devices', 'rcu_selected', rcu_selected_value)
  396. def writeCcardSelected(ccard_selected_value):
  397. g_cfgParser.set_value('devices', 'ccard_selected', ccard_selected_value)
  398. def writeATVSelected(atv_selected_value):
  399. g_cfgParser.set_value('devices', 'atv_selected', atv_selected_value)
  400. def writeDTVSelected(dtv_selected_value):
  401. g_cfgParser.set_value('devices', 'dtv_selected', dtv_selected_value)
  402. def writeTG39_Port(port_number):
  403. g_cfgParser.set_value('COMM', 'tg39_port', 'COM' + port_number)
  404. def write22293_Port(port_number):
  405. f = open(COMConfigPath)
  406. data = f.read()
  407. data_dict = eval(data)
  408. f.close()
  409. f1 = open(COMConfigPath, 'w')
  410. data_dict['SourceGenInput'] = 'COM' + port_number
  411. f1.write(str(data_dict))
  412. f1.close()
  413. def writeSerialCOM(port_number):
  414. g_cfgParser.set_value('COMM', 'serial_communicator_port', 'COM' + port_number)
  415. def writeMenuTreeRootDir(menuTreeRootDir):
  416. try:
  417. g_cfgParser.add_section('MenuTree')
  418. except Exception, e:
  419. print e
  420. g_cfgParser.set_value('MenuTree', 'menuTreeRootDir', menuTreeRootDir)
  421. def writeMenuTreeSelectedChip(selectedChip):
  422. try:
  423. g_cfgParser.add_section('MenuTree')
  424. except Exception, e:
  425. print e
  426. g_cfgParser.set_value('MenuTree', 'menuTreeSelectedChip', selectedChip)
  427. def writeMenuTreeSelectedStyle(selectedStyle):
  428. try:
  429. g_cfgParser.add_section('MenuTree')
  430. except Exception, e:
  431. print e
  432. g_cfgParser.set_value('MenuTree', 'menuTreeSelectedStyle', selectedStyle)
  433. def writeMenuTreeSelectedChannel(selectedChannel):
  434. try:
  435. g_cfgParser.add_section('MenuTree')
  436. except Exception, e:
  437. print e
  438. g_cfgParser.set_value('MenuTree', 'menuTreeSelectedChannel', selectedChannel)
  439. def writeMenuTreeSelectedTVUI(selectedTVUI):
  440. try:
  441. g_cfgParser.add_section('MenuTree')
  442. except Exception, e:
  443. print e
  444. g_cfgParser.set_value('MenuTree', 'menuTreeSelectedTVUI', selectedTVUI)
  445. def getRCUSelectedFilePath():
  446. # rootPath = os.path.join(Python_Home, 'Tools', 'redhathub', 'data')
  447. rootPath = getSATRCUProductDIR()
  448. fileName = getRCUSelected() + '.xml'
  449. filePath = os.path.join(rootPath, fileName)
  450. print 'filePath:', filePath
  451. return filePath
  452. def getBaiduOCR_APPID():
  453. return g_cfgParser.get_value("baidu_ocr", "APP_ID")
  454. def getBaiduOCR_APIKey():
  455. return g_cfgParser.get_value("baidu_ocr", "API_KEY")
  456. def getBaiduOCR_SecretKey():
  457. return g_cfgParser.get_value("baidu_ocr", "SECRET_KEY")
  458. def getMenuTreeRootDir():
  459. value = None
  460. try:
  461. value = g_cfgParser.get_value('MenuTree', 'menuTreeRootDir')
  462. return value
  463. except Exception, e:
  464. print e
  465. return value
  466. def getMenuTreeSelectedChip():
  467. value = None
  468. try:
  469. value = g_cfgParser.get_value('MenuTree', 'menuTreeSelectedChip')
  470. return value
  471. except Exception, e:
  472. print e
  473. return value
  474. def getMenuTreeSelectedStyle():
  475. value = None
  476. try:
  477. value = g_cfgParser.get_value('MenuTree', 'menuTreeSelectedStyle')
  478. return value
  479. except Exception, e:
  480. print e
  481. return value
  482. def getMenuTreeSelectedChannel():
  483. value = None
  484. try:
  485. value = g_cfgParser.get_value('MenuTree', 'menuTreeSelectedChannel')
  486. return value
  487. except Exception, e:
  488. print e
  489. return value
  490. def getMenuTreeSelectedTVUI():
  491. value = None
  492. try:
  493. value = g_cfgParser.get_value('MenuTree', 'menuTreeSelectedTVUI')
  494. except Exception, e:
  495. print e
  496. if not value:
  497. return -1
  498. return int(value)
  499. def getMenuTreeSelectedTreePath():
  500. return os.path.join(getCurrentMenuTreeDir(), 'uitree.ini')
  501. def getMenuTreeSelectedProjectCfgPath():
  502. return os.path.join(getSATProjectCfgDIR(), getMenuTreeSelectedChip(), getMenuTreeSelectedStyle())
  503. # return os.path.join(getSATMenuTreeDIR(), getMenuTreeSelectedChip(), getMenuTreeSelectedStyle())
  504. def getCurrentMenuTreeDir():
  505. return os.path.join(getSATMenuTreeDIR(), getMenuTreeSelectedChip(), getMenuTreeSelectedStyle())
  506. def getMenuTree3SelectedProjectCfgPath():
  507. # return os.path.join(getSATProjectCfgDIR(), getMenuTreeSelectedChip(), getMenuTreeSelectedStyle())
  508. return os.path.join(getCurrentMenuTreeDir())
  509. def getMenuTree3SelectedPExcelPath():
  510. print u"MenuTree3框架加载的非tv表格路径为:", os.path.join(getCurrentMenuTreeDir(), "MenuTree.xls")
  511. return os.path.join(getCurrentMenuTreeDir(), "MenuTree.xls")
  512. def getMenuTree3SelectedTvExcelPath():
  513. # return os.path.join(getSATProjectCfgDIR(), getMenuTreeSelectedChip(), getMenuTreeSelectedStyle())
  514. channel = getMenuTreeSelectedChannel()
  515. if not channel or str(channel) == "":
  516. print u"未能读取到tv表格!!MenuTree3框架将使用默认的表格路径:", os.path.join(getCurrentMenuTreeDir(),
  517. "MenuTree.xls")
  518. return os.path.join(getCurrentMenuTreeDir(), "MenuTree.xls")
  519. else:
  520. print u"当前加载的TV制式为%s,MenuTree3框架载入的TV表格路径为:"%channel, os.path.join(getCurrentMenuTreeDir(),
  521. "MenuTree_" + channel + ".xls")
  522. return os.path.join(getCurrentMenuTreeDir(),
  523. "MenuTree_" + channel + ".xls")
  524. return os.path.join(getCurrentMenuTreeDir())
  525. def getChroma22293():
  526. try:
  527. return json.loads(g_cfgParser.get_value("COMM", "Chroma22293"))
  528. except Exception, e:
  529. print e
  530. return {}
  531. def setChroma22293(strJson):
  532. g_cfgParser.set_value('COMM', 'Chroma22293', strJson)
  533. # 获取Runner端TCPServer的port
  534. def getRunnerTcpPort():
  535. port = 9900
  536. prot_cfg_str = readConfigFile('COMM', 'runner_tcp_port')
  537. if prot_cfg_str:
  538. prot_cfg_int = int(prot_cfg_str)
  539. port = prot_cfg_int
  540. # print 'port:', port, type(port)
  541. return port
  542. # 写入Runner端TCPServer的port
  543. def writeRunnerTcpPort(port):
  544. writeConfigFile('COMM', 'runner_tcp_port', str(port))
  545. # 获取Tester端 设备监听TCPServer的port
  546. def getTesterListenTcpPort():
  547. port = 20000
  548. try:
  549. prot_cfg_str = readConfigFile('COMM', 'tester_listen_tcp_port')
  550. except Exception:
  551. prot_cfg_str = None
  552. if prot_cfg_str:
  553. prot_cfg_int = int(prot_cfg_str)
  554. port = prot_cfg_int
  555. # print 'port:', port, type(port)
  556. return port
  557. # 写入脚本中全步骤截图的开关
  558. def writeRestart(isSendKeyTakePicture):
  559. writeConfigFile('COMM', 'isRestart', str(isSendKeyTakePicture))
  560. # 获取脚本中全步骤截图的开关
  561. def getIsRestart():
  562. # isSendKeyTakePicture = "False"
  563. try:
  564. isSendKeyTakePicture = readConfigFile('COMM', 'isRestart')
  565. except Exception:
  566. isSendKeyTakePicture = "False"
  567. return isSendKeyTakePicture
  568. # 写入脚本中全步骤截图的开关
  569. def writeIsSendKeyTakePicture(isSendKeyTakePicture):
  570. writeConfigFile('COMM', 'isSendKeyTakePicture', str(isSendKeyTakePicture))
  571. # 获取脚本中全步骤截图的开关
  572. def getIsSendKeyTakePicture():
  573. # isSendKeyTakePicture = "False"
  574. try:
  575. isSendKeyTakePicture = readConfigFile('COMM', 'isSendKeyTakePicture')
  576. except Exception:
  577. isSendKeyTakePicture = "False"
  578. return isSendKeyTakePicture
  579. # 写入Tester界面中中全步骤截图的开关
  580. def writeIsSendKeyTakePictureTester(isSendKeyTakePicture):
  581. writeConfigFile('COMM', 'isSendKeyTakePicture_tester', str(isSendKeyTakePicture))
  582. # 读取Tester界面中中全步骤截图的开关
  583. def getIsSendKeyTakePictureTester():
  584. # isSendKeyTakePicture = "False"
  585. try:
  586. isSendKeyTakePicture = readConfigFile('COMM', 'isSendKeyTakePicture_tester')
  587. except Exception:
  588. isSendKeyTakePicture = "False"
  589. return isSendKeyTakePicture
  590. # 写入Runner端TCPServer的port
  591. def writeTesterListenTcpPort(port):
  592. writeConfigFile('COMM', 'tester_listen_tcp_port', str(port))
  593. # 写入配置文件接口
  594. def writeConfigFile(section, key, value):
  595. try:
  596. g_cfgParser.add_section(section)
  597. except Exception, e:
  598. print e
  599. g_cfgParser.set_value(section, key, value)
  600. # 读取配置文件接口
  601. def readConfigFile(session, key):
  602. value = None
  603. try:
  604. value = g_cfgParser.get_value(session, key)
  605. return value
  606. except Exception, e:
  607. print e
  608. return value
  609. # 读取音频设备列表;
  610. def getVoicecards():
  611. try:
  612. return json.loads(g_cfgParser.get_value("devices", "voicecards"))
  613. except Exception, e:
  614. print e
  615. return {}
  616. # 写入音频设备列表;
  617. def setVoicecards(strJson):
  618. g_cfgParser.set_value('devices', 'voicecards', strJson)
  619. '''
  620. 获取视频采集卡型号
  621. '''
  622. def getCCard_Selected():
  623. return readConfigFile('devices', 'ccard_selected')
  624. def getSoundList():
  625. try:
  626. sound_list_str = g_cfgParser.get_value("Sound", "sound_list")
  627. if type(sound_list_str) == type(''):
  628. sound_list = eval(sound_list_str)
  629. else:
  630. sound_list = sound_list_str
  631. if sound_list == []:
  632. sound_list = [1000, 1000]
  633. writeSoundList(sound_list)
  634. return sound_list
  635. except Exception, e:
  636. print e
  637. sound_list = [1000, 1000]
  638. writeSoundList(sound_list)
  639. return sound_list
  640. def writeSoundList(sound_list):
  641. writeConfigFile('Sound', 'sound_list', str(sound_list))
  642. def getOtaParamUrl_dict():
  643. return eval(g_cfgParser.get_value("URL", "getParam"))
  644. '''
  645. adb设备可用或不可用状态;
  646. return ture:可用,false:不可用
  647. '''
  648. def getAdbDeviceSatatus():
  649. Online = "Online"
  650. options = g_cfgParser.get_options("ADBSTATUS")
  651. # print "getAdbDeviceSatatus,options:",options
  652. if options is None:
  653. return False
  654. for option in options:
  655. status = g_cfgParser.get_value("ADBSTATUS",option)
  656. # print "getAdbDeviceSatatus,%s:"%option, status
  657. if status == Online:
  658. return True
  659. return False
  660. '''
  661. 获取adb设备状态描述
  662. return: none表示没有这个设备,Unauthorized表示设备未授权,offline表示设备离线,online表示在线可用
  663. '''
  664. def getAdbDevSTDesc():
  665. Online = "Online"
  666. options = g_cfgParser.get_options("ADBSTATUS")
  667. # print "getAdbDeviceSatatus,options:",options
  668. if options is None:
  669. return "none"
  670. for option in options:
  671. status = g_cfgParser.get_value("ADBSTATUS", option)
  672. return status
  673. return "none"
  674. if __name__ == "__main__":
  675. dict = getOtaParamUrl_dict()
  676. print "CN:",dict["CN"]
  677. print "ME:",dict["ME"]
  678. # print "OCR IP addr:", getOCRIpAddr()
  679. # print "OCR port:", getOCRPort()
  680. # print "Serial port:", getSerialCOM()
  681. # print "SAT Home:", getSATHome()
  682. # # setResultDir("D:/SAT/result_schedule_id_schedule_name_task_number/")
  683. # # print "Result DIR:", getResultDir()
  684. #
  685. # print 'getTG39_Port:', getTG39_Port()
  686. # print 'getRCUSelected:', getRCUSelected()
  687. # print 'getAtv_list:', getAtv_list(), type(getAtv_list())
  688. # writeRCUSelected('RC322')
  689. # list = getChroma22293()
  690. # for item in list:
  691. # print item["name"],item["port"]
  692. # print list
  693. # getDtv_list()
  694. # getRunnerTcpPort()
  695. # writeRunnerTcpPort(9966)
  696. # getRunnerTcpPort()