attr_parser.py 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948
  1. # coding: utf-8
  2. # Copyright (C) 1994-2018 Altair Engineering, Inc.
  3. # For more information, contact Altair at www.altair.com.
  4. #
  5. # This file is part of the PBS Professional ("PBS Pro") software.
  6. #
  7. # Open Source License Information:
  8. #
  9. # PBS Pro is free software. You can redistribute it and/or modify it under the
  10. # terms of the GNU Affero General Public License as published by the Free
  11. # Software Foundation, either version 3 of the License, or (at your option) any
  12. # later version.
  13. #
  14. # PBS Pro is distributed in the hope that it will be useful, but WITHOUT ANY
  15. # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  16. # FOR A PARTICULAR PURPOSE.
  17. # See the GNU Affero General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU Affero General Public License
  20. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. #
  22. # Commercial License Information:
  23. #
  24. # For a copy of the commercial license terms and conditions,
  25. # go to: (http://www.pbspro.com/UserArea/agreement.html)
  26. # or contact the Altair Legal Department.
  27. #
  28. # Altair’s dual-license business model allows companies, individuals, and
  29. # organizations to create proprietary derivative works of PBS Pro and
  30. # distribute them - whether embedded or bundled with other software -
  31. # under a commercial license agreement.
  32. #
  33. # Use of Altair’s trademarks, including but not limited to "PBS™",
  34. # "PBS Professional®", and "PBS Pro™" and Altair’s logos is subject to Altair's
  35. # trademark licensing policies.
  36. """
  37. attr_parser.py will parse xml files also called master attribute files
  38. containing all the members of both server and ecl files,and will generate
  39. two corresponding files one for server and one for ecl
  40. """
  41. import sys
  42. import os
  43. import re
  44. import getopt
  45. import string
  46. import xml.parsers.expat
  47. import xml.dom.minidom
  48. import pdb
  49. list_ecl = []
  50. list_svr = []
  51. global e_flag
  52. global s_flag
  53. global ms
  54. global me
  55. e_flag = 0
  56. s_flag = 0
  57. class switch(object):
  58. """
  59. This class provides the functionality which is equivalent
  60. to switch/case statements in C. It only needs to be defined
  61. once.
  62. """
  63. def __init__(self, value):
  64. self.value = value
  65. self.fall = False
  66. def __iter__(self):
  67. """Return the match method once, then stop"""
  68. yield self.match
  69. raise StopIteration
  70. def match(self, *args):
  71. """Indicate whether or not to enter a case suite"""
  72. if self.fall or not args:
  73. return True
  74. elif self.value in args: # changed for v1.5, see below
  75. self.fall = True
  76. return True
  77. else:
  78. return False
  79. def fileappend(line):
  80. """
  81. fileappend function - (wrapper on top of append for being able to
  82. select the file where to write
  83. """
  84. global s_flag
  85. global e_flag
  86. if s_flag == 1 and e_flag == 0:
  87. list_svr.append(line)
  88. if e_flag == 1 and s_flag == 0:
  89. list_ecl.append(line)
  90. if e_flag == 0 and s_flag == 0:
  91. list_svr.append(line)
  92. list_ecl.append(line)
  93. return None
  94. def getText(efl, sfl):
  95. """
  96. getText function - (writes the data stored in lists to file)
  97. """
  98. buff1 = "".join(list_svr)
  99. buff2 = "".join(list_ecl)
  100. for line in buff1:
  101. sfl.write(line)
  102. for line in buff2:
  103. efl.write(line)
  104. def add_comma(string):
  105. """
  106. add_comma function - (will take Tag values and will put if there is any comma in it)
  107. """
  108. buff2 = string.split('\n')
  109. for line in buff2:
  110. if re.search(r'#', line):
  111. line = line.strip(' \t')
  112. list_svr.append('\t' + '\t' + line + '\n')
  113. elif re.search(r'\n', line):
  114. pass
  115. else:
  116. line = line.strip(' \t')
  117. list_svr.append('\t' + '\t' + '\t' + line + ',' + '\n')
  118. def attr(masterf, svrf, eclf):
  119. """
  120. attr function - (opens the files reads them and using minidom filters relevant
  121. data to individual lists)
  122. """
  123. from xml.dom import minidom
  124. global e_flag
  125. global s_flag
  126. doc = minidom.parse(masterf)
  127. nodes = doc.getElementsByTagName('data')
  128. for node in nodes:
  129. alist = node.getElementsByTagName('head')
  130. for a in alist:
  131. list_svr.append (
  132. "/*Disclaimer: This is a machine generated file.*/" + '\n')
  133. list_svr.append(
  134. "/*For modifying any attribute change corresponding XML file */" + '\n')
  135. list_ecl.append(
  136. "/*Disclaimer: This is a machine generated file.*/" + '\n')
  137. list_ecl.append(
  138. "/*For modifying any attribute change corresponding XML file */" + '\n')
  139. blist = a.getElementsByTagName('SVR')
  140. blist_ecl = a.getElementsByTagName('ECL')
  141. for s in blist:
  142. text1 = s.childNodes[0].nodeValue
  143. text1 = text1.strip(' \t')
  144. list_svr.append(text1)
  145. for e in blist_ecl:
  146. text2 = e.childNodes[0].nodeValue
  147. text2 = text2.strip(' \t')
  148. list_ecl.append(text2)
  149. at_list = node.getElementsByTagName('attributes')
  150. for i in at_list:
  151. e_flag = 0
  152. s_flag = 0
  153. attr_list = i.childNodes[0].nodeValue
  154. inc_name = i.getAttribute('include')
  155. list_svr.append( '\n' + inc_name)
  156. flag_name = i.getAttribute('flag')
  157. if flag_name == 'SVR':
  158. s_flag = 1
  159. if flag_name == 'ECL':
  160. e_flag = 1
  161. if flag_name == None:
  162. e_flag = 0
  163. s_flag = 0
  164. attr_list = attr_list.strip(' \t')
  165. fileappend(attr_list)
  166. h = None
  167. s_mem = None
  168. e_mem = None
  169. mem_list1 = i.getElementsByTagName('member_name')
  170. if mem_list1:
  171. bot = mem_list1[0].getElementsByTagName('both')
  172. svr = mem_list1[0].getElementsByTagName('SVR')
  173. ecl = mem_list1[0].getElementsByTagName('ECL')
  174. for b in bot:
  175. h = b.childNodes[0].nodeValue
  176. h = h.strip(' \t')
  177. fileappend(
  178. '\n' + '\t' + '{' + '\n' + '\t' + '\t' + h + ',' + '\n')
  179. for s in svr:
  180. s_mem = s.childNodes[0].nodeValue
  181. s_mem = s_mem.strip(' \t')
  182. fileappend(
  183. '\n' + '\t' + '{' + '\n' + '\t' + '\t' + s_mem + ',' + '\n')
  184. for e in ecl:
  185. e_mem = e.childNodes[0].nodeValue
  186. e_mem = e_mem.strip(' \t')
  187. fileappend(
  188. '\n' + '\t' + '{' + '\n' + '\t' + '\t' + e_mem + ',' + '\n')
  189. else:
  190. sys.exit(
  191. "member_name does not exist!" + i.childNodes[0].nodeValue)
  192. mem_list2 = i.getElementsByTagName('member_at_decode')
  193. if mem_list2:
  194. mem = mem_list2[0].childNodes[0].nodeValue
  195. mem = mem.strip(' \t')
  196. s_flag = 1 # This is not required in ECL files
  197. if re.search(r'^#', mem):
  198. add_comma(mem)
  199. else:
  200. fileappend('\t' + '\t' + mem + ',' + '\n')
  201. else:
  202. if h:
  203. tmp = h
  204. elif s_mem:
  205. tmp = s_mem
  206. elif e_mem:
  207. tmp = e_mem
  208. else:
  209. tmp = i.childNodes[0].nodeValue
  210. sys.exit(
  211. "member_at_decode <Tag> does not exist! for Attribute -> " + tmp)
  212. mem_list3 = i.getElementsByTagName('member_at_encode')
  213. if mem_list3:
  214. mem = mem_list3[0].childNodes[0].nodeValue
  215. mem = mem.strip(' \t')
  216. s_flag = 1
  217. if re.search(r'^#', mem):
  218. add_comma(mem)
  219. else:
  220. fileappend('\t' + '\t' + mem + ',' + '\n')
  221. else:
  222. if h:
  223. tmp = h
  224. elif s_mem:
  225. tmp = s_mem
  226. elif e_mem:
  227. tmp = e_mem
  228. else:
  229. tmp = i.childNodes[0].nodeValue
  230. sys.exit(
  231. "member_at_encode <Tag> does not exist! for Attribute -> " + tmp)
  232. mem_list4 = i.getElementsByTagName('member_at_set')
  233. s_flag = 1
  234. if mem_list4:
  235. mem = mem_list4[0].childNodes[0].nodeValue
  236. mem = mem.strip(' \t')
  237. if re.search(r'^#', mem):
  238. add_comma(mem)
  239. else:
  240. fileappend('\t' + '\t' + mem + ',' + '\n')
  241. else:
  242. if h:
  243. tmp = h
  244. elif s_mem:
  245. tmp = s_mem
  246. elif e_mem:
  247. tmp = e_mem
  248. else:
  249. tmp = i.childNodes[0].nodeValue
  250. sys.exit(
  251. "member_at_set <Tag> does not exist! for Attribute -> " + tmp)
  252. mem_list5 = i.getElementsByTagName('member_at_comp')
  253. s_flag = 1
  254. if mem_list5:
  255. mem = mem_list5[0].childNodes[0].nodeValue
  256. mem = mem.strip(' \t')
  257. if re.search(r'^#', mem):
  258. add_comma(mem)
  259. else:
  260. fileappend('\t' + '\t' + mem + ',' + '\n')
  261. else:
  262. if h:
  263. tmp = h
  264. elif s_mem:
  265. tmp = s_mem
  266. elif e_mem:
  267. tmp = e_mem
  268. else:
  269. tmp = i.childNodes[0].nodeValue
  270. sys.exit(
  271. "member_at_comp <Tag> does not exist! for Attribute -> " + tmp)
  272. mem_list6 = i.getElementsByTagName('member_at_free')
  273. s_flag = 1
  274. if mem_list6:
  275. mem = mem_list6[0].childNodes[0].nodeValue
  276. mem = mem.strip(' \t')
  277. if re.search(r'^#', mem):
  278. add_comma(mem)
  279. else:
  280. fileappend('\t' + '\t' + mem + ',' + '\n')
  281. else:
  282. if h:
  283. tmp = h
  284. elif s_mem:
  285. tmp = s_mem
  286. elif e_mem:
  287. tmp = e_mem
  288. else:
  289. tmp = i.childNodes[0].nodeValue
  290. sys.exit(
  291. "member_at_free <Tag> does not exist! for Attribute -> " + tmp)
  292. mem_list7 = i.getElementsByTagName('member_at_action')
  293. s_flag = 1
  294. if mem_list7:
  295. mem = mem_list7[0].childNodes[0].nodeValue
  296. mem = mem.strip(' \t')
  297. if re.search(r'^#', mem):
  298. add_comma(mem)
  299. else:
  300. fileappend('\t' + '\t' + mem + ',' + '\n')
  301. else:
  302. if h:
  303. tmp = h
  304. elif s_mem:
  305. tmp = s_mem
  306. elif e_mem:
  307. tmp = e_mem
  308. else:
  309. tmp = i.childNodes[0].nodeValue
  310. sys.exit(
  311. "member_at_action <Tag> does not exist! for Attribute -> " + tmp)
  312. e_flag = 0
  313. s_flag = 0
  314. mem_list8 = i.getElementsByTagName('member_at_flags')
  315. if mem_list8:
  316. mem = mem_list8[0].childNodes[0].nodeValue
  317. bot = mem_list8[0].getElementsByTagName('both')
  318. svr = mem_list8[0].getElementsByTagName('SVR')
  319. ecl = mem_list8[0].getElementsByTagName('ECL')
  320. for b in bot:
  321. h = b.childNodes[0].nodeValue
  322. h = h.strip(' \t')
  323. fileappend('\t' + '\t' + h + ',' + '\n')
  324. for s in svr:
  325. s_mem = s.childNodes[0].nodeValue
  326. s_mem = s_mem.strip(' \t')
  327. s_flag = 1
  328. if re.search(r'^#', s_mem):
  329. add_comma(s_mem)
  330. else:
  331. fileappend('\t' + '\t' + s_mem + ',' + '\n')
  332. s_flag = 0
  333. e_flag = 0
  334. for e in ecl:
  335. e_mem = e.childNodes[0].nodeValue
  336. e_mem = e_mem.strip(' \t')
  337. e_flag = 1
  338. fileappend('\t' + '\t' + e_mem + ',' + '\n')
  339. else:
  340. if h:
  341. tmp = h
  342. elif s_mem:
  343. tmp = s_mem
  344. elif e_mem:
  345. tmp = e_mem
  346. else:
  347. tmp = i.childNodes[0].nodeValue
  348. sys.exit(
  349. "member_at_flags <Tag> does not exist! for Attribute -> " + tmp)
  350. e_flag = 0
  351. s_flag = 0
  352. mem_list9 = i.getElementsByTagName('member_at_type')
  353. if mem_list9:
  354. mem = mem_list9[0].childNodes[0].nodeValue
  355. bot = mem_list9[0].getElementsByTagName('both')
  356. svr = mem_list9[0].getElementsByTagName('SVR')
  357. ecl = mem_list9[0].getElementsByTagName('ECL')
  358. for b in bot:
  359. h = b.childNodes[0].nodeValue
  360. h = h.strip(' \t')
  361. fileappend('\t' + '\t' + h + ',' + '\n')
  362. for s in svr:
  363. s_mem = s.childNodes[0].nodeValue
  364. s_mem = s_mem.strip(' \t')
  365. s_flag = 1
  366. if re.search(r'^#', s_mem):
  367. add_comma(s_mem)
  368. else:
  369. fileappend('\t' + '\t' + s_mem + ',' + '\n')
  370. s_flag = 0
  371. e_flag = 0
  372. for e in ecl:
  373. e_mem = e.childNodes[0].nodeValue
  374. e_mem = e_mem.strip(' \t')
  375. e_flag = 1
  376. fileappend('\t' + '\t' + e_mem + ',' + '\n')
  377. else:
  378. if h:
  379. tmp = h
  380. elif s_mem:
  381. tmp = s_mem
  382. elif e_mem:
  383. tmp = e_mem
  384. else:
  385. tmp = i.childNodes[0].nodeValue
  386. sys.exit(
  387. "member_at_type <Tag> does not exist! for Attribute -> " + tmp)
  388. e_flag = 0
  389. s_flag = 0
  390. mem_list10 = i.getElementsByTagName('member_at_parent')
  391. if mem_list10:
  392. mem = mem_list10[0].childNodes[0].nodeValue
  393. mem = mem.strip(' \t')
  394. s_flag = 1
  395. fileappend('\t' + '\t' + mem + '\n' + '\t' + '},')
  396. s_flag = 0
  397. else:
  398. pass
  399. e_flag = 0
  400. s_flag = 0
  401. mem_list11 = i.getElementsByTagName('member_verify_function')
  402. if mem_list11:
  403. mem = mem_list11[0].childNodes[0].nodeValue
  404. ecl = mem_list11[0].getElementsByTagName('ECL')
  405. e_mem1 = []
  406. # <Tag> member_verify_function, will always have only 2 ECL subtags.
  407. e_flag = 1
  408. for e in ecl:
  409. e_mem1.append(e.childNodes[0].nodeValue.strip(' \t'))
  410. fileappend('\t' + '\t' + e_mem1[0] + ',' + '\n')
  411. fileappend('\t' + '\t' + e_mem1[1] + '\t' + '\n' + '\t' + '},')
  412. e_flag = 0
  413. s_flag = 0
  414. else:
  415. pass
  416. tail_list = node.getElementsByTagName('tail')
  417. for t in tail_list:
  418. tail_value = t.childNodes[0].nodeValue
  419. if tail_value == None:
  420. pass
  421. fileappend('\n')
  422. tail_both = t.getElementsByTagName('both')
  423. tail_svr = t.getElementsByTagName('SVR')
  424. tail_ecl = t.getElementsByTagName('ECL')
  425. for tb in tail_both:
  426. b = tb.childNodes[0].nodeValue
  427. b = b.strip(' \t')
  428. list_ecl.append(b)
  429. list_svr.append(b)
  430. for ts in tail_svr:
  431. s = ts.childNodes[0].nodeValue
  432. s = s.strip(' \t')
  433. list_svr.append(s)
  434. for te in tail_ecl:
  435. e = te.childNodes[0].nodeValue
  436. e = e.strip(' \t')
  437. list_ecl.append(e)
  438. getText(eclf, svrf)
  439. def resc_attr(masterf, svrf, eclf):
  440. """
  441. resc_attr function - (opens the resc_def file reads them and using minidom
  442. filters relevant data to individual lists)
  443. """
  444. from xml.dom import minidom
  445. global e_flag
  446. global s_flag
  447. global ms
  448. global me
  449. doc = minidom.parse(masterf)
  450. nodes = doc.getElementsByTagName('data')
  451. for node in nodes:
  452. alist = node.getElementsByTagName('head')
  453. for a in alist:
  454. list_svr.append (
  455. "/*Disclaimer: This is a machine generated file.*/" + '\n')
  456. list_svr.append(
  457. "/*For modifying any attribute change corresponding XML file */" + '\n')
  458. list_ecl.append(
  459. "/*Disclaimer: This is a machine generated file.*/" + '\n')
  460. list_ecl.append(
  461. "/*For modifying any attribute change corresponding XML file */" + '\n')
  462. blist = a.getElementsByTagName('SVR')
  463. blist_ecl = a.getElementsByTagName('ECL')
  464. for s in blist:
  465. text1 = s.childNodes[0].nodeValue
  466. list_svr.append(text1)
  467. for e in blist_ecl:
  468. text2 = e.childNodes[0].nodeValue
  469. list_ecl.append(text2)
  470. at_list = node.getElementsByTagName('attributes')
  471. for i in at_list:
  472. attr_list = i.childNodes[0].nodeValue
  473. flag_name = i.getAttribute('flag')
  474. macro_name = i.getAttribute('macro')
  475. s_flag = 0
  476. e_flag = 0
  477. ms = 0
  478. me = 0
  479. mflg = i.getAttribute('mflag')
  480. if flag_name == 'SVR':
  481. s_flag = 1
  482. if flag_name == 'ECL':
  483. e_flag = 1
  484. if flag_name == None:
  485. e_flag = 0
  486. s_flag = 0
  487. if macro_name:
  488. ms = 1
  489. me = 1
  490. for case in switch(mflg):
  491. if case('SVR'):
  492. ms = 1
  493. me = 0
  494. break
  495. if case('ECL'):
  496. me = 1
  497. ms = 0
  498. break
  499. if me == 1 and macro_name != None:
  500. list_ecl.append('\n' + macro_name)
  501. if ms == 1 and macro_name != None:
  502. list_svr.append('\n' + macro_name)
  503. fileappend(attr_list)
  504. h = None
  505. s_mem = None
  506. e_mem = None
  507. mem_list1 = i.getElementsByTagName('member_name')
  508. if mem_list1:
  509. mem = mem_list1[0].childNodes[0].nodeValue
  510. bot = mem_list1[0].getElementsByTagName('both')
  511. svr = mem_list1[0].getElementsByTagName('SVR')
  512. ecl = mem_list1[0].getElementsByTagName('ECL')
  513. for b in bot:
  514. h = b.childNodes[0].nodeValue
  515. fileappend(
  516. '\n' + '\t' + '{' + '\n' + '\t' + '\t' + h.strip(' \t') + ',' + '\n')
  517. for s in svr:
  518. s_mem = s.childNodes[0].nodeValue
  519. s_mem = s_mem.strip(' \t')
  520. fileappend(
  521. '\n' + '\t' + '{' + '\n' + '\t' + '\t' + s_mem + ',' + '\n')
  522. for e in ecl:
  523. e_mem = e.childNodes[0].nodeValue
  524. e_mem = e_mem.strip(' \t')
  525. fileappend(
  526. '\n' + '\t' + '{' + '\n' + '\t' + '\t' + e_mem + ',' + '\n')
  527. else:
  528. sys.exit(
  529. "member_name does not exist!" + i.childNodes[0].nodeValue)
  530. mem_list2 = i.getElementsByTagName('member_at_decode')
  531. if mem_list2:
  532. mem = mem_list2[0].childNodes[0].nodeValue
  533. s_flag = 1 # This is not required in ECL files
  534. if re.search(r'^#', mem):
  535. add_comma(mem)
  536. else:
  537. fileappend('\t' + '\t' + mem + ',' + '\n')
  538. else:
  539. if h:
  540. tmp = h
  541. elif s_mem:
  542. tmp = s_mem
  543. elif e_mem:
  544. tmp = e_mem
  545. else:
  546. tmp = i.childNodes[0].nodeValue
  547. sys.exit(
  548. "member_at_decode <Tag> does not exist! for Attribute -> " + tmp)
  549. mem_list3 = i.getElementsByTagName('member_at_encode')
  550. if mem_list3:
  551. mem = mem_list3[0].childNodes[0].nodeValue
  552. s_flag = 1 # This is not required in ECL files
  553. if re.search(r'^#', mem):
  554. add_comma(mem)
  555. else:
  556. fileappend('\t' + '\t' + mem + ',' + '\n')
  557. else:
  558. if h:
  559. tmp = h
  560. elif s_mem:
  561. tmp = s_mem
  562. elif e_mem:
  563. tmp = e_mem
  564. else:
  565. tmp = i.childNodes[0].nodeValue
  566. sys.exit(
  567. "member_at_encode <Tag> does not exist! for Attribute -> " + tmp)
  568. mem_list4 = i.getElementsByTagName('member_at_set')
  569. if mem_list4:
  570. mem = mem_list4[0].childNodes[0].nodeValue
  571. s_flag = 1 # This is not required in ECL files
  572. if re.search(r'^#', mem):
  573. add_comma(mem)
  574. else:
  575. fileappend('\t' + '\t' + mem + ',' + '\n')
  576. else:
  577. if h:
  578. tmp = h
  579. elif s_mem:
  580. tmp = s_mem
  581. elif e_mem:
  582. tmp = e_mem
  583. else:
  584. tmp = i.childNodes[0].nodeValue
  585. sys.exit(
  586. "member_at_set <Tag> does not exist! for Attribute -> " + tmp)
  587. mem_list5 = i.getElementsByTagName('member_at_comp')
  588. if mem_list5:
  589. mem = mem_list5[0].childNodes[0].nodeValue
  590. s_flag = 1 # This is not required in ECL files
  591. if re.search(r'^#', mem):
  592. add_comma(mem)
  593. else:
  594. fileappend('\t' + '\t' + mem + ',' + '\n')
  595. else:
  596. if h:
  597. tmp = h
  598. elif s_mem:
  599. tmp = s_mem
  600. elif e_mem:
  601. tmp = e_mem
  602. else:
  603. tmp = i.childNodes[0].nodeValue
  604. sys.exit(
  605. "member_at_comp <Tag> does not exist! for Attribute -> " + tmp)
  606. mem_list6 = i.getElementsByTagName('member_at_free')
  607. if mem_list6:
  608. mem = mem_list6[0].childNodes[0].nodeValue
  609. s_flag = 1 # This is not required in ECL files
  610. if re.search(r'^#', mem):
  611. add_comma(mem)
  612. else:
  613. fileappend('\t' + '\t' + mem + ',' + '\n')
  614. else:
  615. if h:
  616. tmp = h
  617. elif s_mem:
  618. tmp = s_mem
  619. elif e_mem:
  620. tmp = e_mem
  621. else:
  622. tmp = i.childNodes[0].nodeValue
  623. sys.exit(
  624. "member_at_free <Tag> does not exist! for Attribute -> " + tmp)
  625. mem_list7 = i.getElementsByTagName('member_at_action')
  626. if mem_list7:
  627. mem = mem_list7[0].childNodes[0].nodeValue
  628. s_flag = 1 # This is not required in ECL files
  629. if re.search(r'^#', mem):
  630. add_comma(mem)
  631. else:
  632. fileappend('\t' + '\t' + mem + ',' + '\n')
  633. else:
  634. if h:
  635. tmp = h
  636. elif s_mem:
  637. tmp = s_mem
  638. elif e_mem:
  639. tmp = e_mem
  640. else:
  641. tmp = i.childNodes[0].nodeValue
  642. sys.exit(
  643. "member_at_action <Tag> does not exist! for Attribute -> " + tmp)
  644. e_flag = 0
  645. s_flag = 0
  646. mem_list8 = i.getElementsByTagName('member_at_flags')
  647. if mem_list8:
  648. mem = mem_list8[0].childNodes[0].nodeValue
  649. bot = mem_list8[0].getElementsByTagName('both')
  650. svr = mem_list8[0].getElementsByTagName('SVR')
  651. ecl = mem_list8[0].getElementsByTagName('ECL')
  652. for b in bot:
  653. h = b.childNodes[0].nodeValue
  654. fileappend('\t' + '\t' + h + ',' + '\n')
  655. for s in svr:
  656. s_mem = s.childNodes[0].nodeValue
  657. s_flag = 1
  658. if re.search(r'^#', s_mem):
  659. add_comma(s_mem)
  660. else:
  661. fileappend('\t' + '\t' + s_mem + ',' + '\n')
  662. s_flag = 0
  663. e_flag = 0
  664. for e in ecl:
  665. e_mem = e.childNodes[0].nodeValue
  666. e_flag = 1
  667. fileappend('\t' + '\t' + e_mem + ',' + '\n')
  668. else:
  669. if h:
  670. tmp = h
  671. elif s_mem:
  672. tmp = s_mem
  673. elif e_mem:
  674. tmp = e_mem
  675. else:
  676. tmp = i.childNodes[0].nodeValue
  677. sys.exit(
  678. "member_at_flags <Tag> does not exist! for Attribute -> " + tmp)
  679. e_flag = 0
  680. s_flag = 0
  681. mem_list9 = i.getElementsByTagName('member_at_type')
  682. if mem_list9:
  683. mem = mem_list9[0].childNodes[0].nodeValue
  684. bot = mem_list9[0].getElementsByTagName('both')
  685. svr = mem_list9[0].getElementsByTagName('SVR')
  686. ecl = mem_list9[0].getElementsByTagName('ECL')
  687. for b in bot:
  688. h = b.childNodes[0].nodeValue
  689. fileappend('\t' + '\t' + h + ',' + '\n')
  690. for s in svr:
  691. s_mem = s.childNodes[0].nodeValue
  692. s_flag = 1
  693. if re.search(r'^#', s_mem):
  694. add_comma(s_mem)
  695. else:
  696. fileappend('\t' + '\t' + s_mem + ',' + '\n')
  697. e_flag = 0
  698. s_flag = 0
  699. for e in ecl:
  700. e_mem = e.childNodes[0].nodeValue
  701. e_flag = 1
  702. fileappend('\t' + '\t' + e_mem + ',' + '\n')
  703. else:
  704. if h:
  705. tmp = h
  706. elif s_mem:
  707. tmp = s_mem
  708. elif e_mem:
  709. tmp = e_mem
  710. else:
  711. tmp = i.childNodes[0].nodeValue
  712. sys.exit(
  713. "member_at_type <Tag> does not exist! for Attribute -> " + tmp)
  714. e_flag = 0
  715. s_flag = 0
  716. mem_list10 = i.getElementsByTagName('member_at_entlim')
  717. if mem_list10:
  718. mem = mem_list10[0].childNodes[0].nodeValue
  719. s_flag = 1
  720. fileappend('\t' + '\t' + mem + ',' + '\n')
  721. else:
  722. if h:
  723. tmp = h
  724. elif s_mem:
  725. tmp = s_mem
  726. elif e_mem:
  727. tmp = e_mem
  728. else:
  729. tmp = i.childNodes[0].nodeValue
  730. sys.exit(
  731. "member_at_entlim <Tag> does not exist! for Attribute -> " + tmp)
  732. mem_list11 = i.getElementsByTagName('member_at_struct')
  733. if mem_list11:
  734. mem = mem_list11[0].childNodes[0].nodeValue
  735. s_flag = 1
  736. fileappend('\t' + '\t' + mem + '\n' + '\t' + '},')
  737. if ms == 1:
  738. fileappend('\n' + '#endif' + '\n')
  739. else:
  740. if h:
  741. tmp = h
  742. elif s_mem:
  743. tmp = s_mem
  744. elif e_mem:
  745. tmp = e_mem
  746. else:
  747. tmp = i.childNodes[0].nodeValue
  748. sys.exit(
  749. "member_at_struct <Tag> does not exist! for Attribute -> " + tmp)
  750. e_flag = 0
  751. s_flag = 0
  752. mem_list12 = i.getElementsByTagName('member_verify_function')
  753. if mem_list12:
  754. mem = mem_list12[0].childNodes[0].nodeValue
  755. ecl = mem_list12[0].getElementsByTagName('ECL')
  756. for e in ecl:
  757. e_mem = e.childNodes[0].nodeValue
  758. ecl = mem_list12[0].getElementsByTagName('ECL')
  759. e_mem1 = []
  760. # <Tag> member_verify_function, will always have only 2 ECL subtags.
  761. e_flag = 1
  762. for e in ecl:
  763. e_mem1.append(e.childNodes[0].nodeValue.strip(' \t'))
  764. fileappend('\t' + '\t' + e_mem1[0] + ',' + '\n')
  765. fileappend('\t' + '\t' + e_mem1[1] + '\t' + '\n' + '\t' + '},')
  766. if me == 1:
  767. fileappend('\n' + '#endif' + '\n')
  768. e_flag = 0
  769. s_flag = 0
  770. else:
  771. pass
  772. tail_list = node.getElementsByTagName('tail')
  773. for t in tail_list:
  774. tail_value = t.childNodes[0].nodeValue
  775. if tail_value == None:
  776. pass
  777. fileappend('\n')
  778. tail_both = t.getElementsByTagName('both')
  779. tail_svr = t.getElementsByTagName('SVR')
  780. tail_ecl = t.getElementsByTagName('ECL')
  781. for tb in tail_both:
  782. b = tb.childNodes[0].nodeValue
  783. list_ecl.append(b)
  784. list_svr.append(b)
  785. for ts in tail_svr:
  786. s = ts.childNodes[0].nodeValue
  787. list_svr.append(s)
  788. for te in tail_ecl:
  789. e = te.childNodes[0].nodeValue
  790. list_ecl.append(e)
  791. getText(eclf, svrf)
  792. def main(argv):
  793. """
  794. The Main Module starts here-
  795. Opens files,and calls appropriate functions based on Object values.
  796. """
  797. global SVR_FILE
  798. global ECL_FILE
  799. global MASTER_FILE
  800. global ATTRIBUTE_SCRIPT_ARG
  801. if len(sys.argv) == 2:
  802. usage()
  803. sys.exit(1)
  804. try:
  805. opts, args = getopt.getopt(
  806. argv, "m:s:e:a:h", ["master=", "svr=", "ecl=", "attr=", "help"])
  807. except getopt.error, err:
  808. print str(err)
  809. usage()
  810. sys.exit(1)
  811. for opt, arg in opts:
  812. if opt in ('-h', "--help"):
  813. usage()
  814. sys.exit(1)
  815. elif opt in ("-m", "--master"):
  816. MASTER_FILE = arg
  817. elif opt in ("-s", "--svr"):
  818. SVR_FILE = arg
  819. elif opt in ("-e", "--ecl"):
  820. ECL_FILE = arg
  821. elif opt in ("-a", "--attr"):
  822. ATTRIBUTE_SCRIPT_ARG = arg
  823. else:
  824. print "Invalid Option!"
  825. sys.exit(1)
  826. # Error conditions are checked here.
  827. if MASTER_FILE is None or not os.path.isfile(MASTER_FILE) or not os.path.getsize(MASTER_FILE) > 0:
  828. print "Master file not found or data is not present in File"
  829. sys.exit(1)
  830. if SVR_FILE is None:
  831. SVR_FILE = "attr_def.c"
  832. if ECL_FILE is None:
  833. ECL_FILE = "ecl_attr_def.c"
  834. if ATTRIBUTE_SCRIPT_ARG is None or not str:
  835. print "Attribute type is required"
  836. sys.exit(1)
  837. try:
  838. m_file = open(MASTER_FILE)
  839. except IOError, err:
  840. print str(err)
  841. print 'Cannot Open Master File!'
  842. sys.exit(1)
  843. try:
  844. s_file = open(SVR_FILE, 'w')
  845. except IOError, err:
  846. print str(err)
  847. print 'Cannot Open Server File!'
  848. sys.exit(1)
  849. try:
  850. e_file = open(ECL_FILE, 'w')
  851. except IOError, err:
  852. print str(err)
  853. print 'Cannot Open Ecl File!'
  854. sys.exit(1)
  855. n = str(ATTRIBUTE_SCRIPT_ARG)
  856. for case in switch(n):
  857. if case('job', 'server', 'node', 'queue', 'sched', 'resv'):
  858. attr(m_file, s_file, e_file)
  859. break
  860. if case('resc'):
  861. resc_attr(m_file, s_file, e_file)
  862. break
  863. if case(): # default, could also just omit condition or 'if True'
  864. print "Invalid Object!"
  865. # No need to break here, it'll stop anyway
  866. m_file.close()
  867. s_file.close()
  868. e_file.close()
  869. def usage():
  870. """
  871. Usage (depicts the usage of the script)
  872. """
  873. print "usage: prog -m <MASTER_FILE> -s <svr_attr_file> -e <ecl_attr_file> -a <object>"
  874. if __name__ == "__main__":
  875. main(sys.argv[1:])