sat_environment.py 25 KB

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