You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

547 lines
17 KiB

6 years ago
  1. """SCons.Tool.rpmutils.py
  2. RPM specific helper routines for general usage in the test framework
  3. and SCons core modules.
  4. Since we check for the RPM package target name in several places,
  5. we have to know which machine/system name RPM will use for the current
  6. hardware setup. The following dictionaries and functions try to
  7. mimic the exact naming rules of the RPM source code.
  8. They were directly derived from the file "rpmrc.in" of the version
  9. rpm-4.9.1.3. For updating to a more recent version of RPM, this Python
  10. script can be used standalone. The usage() function below shows the
  11. exact syntax.
  12. """
  13. # Copyright (c) 2001 - 2017 The SCons Foundation
  14. #
  15. # Permission is hereby granted, free of charge, to any person obtaining
  16. # a copy of this software and associated documentation files (the
  17. # "Software"), to deal in the Software without restriction, including
  18. # without limitation the rights to use, copy, modify, merge, publish,
  19. # distribute, sublicense, and/or sell copies of the Software, and to
  20. # permit persons to whom the Software is furnished to do so, subject to
  21. # the following conditions:
  22. #
  23. # The above copyright notice and this permission notice shall be included
  24. # in all copies or substantial portions of the Software.
  25. #
  26. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
  27. # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  28. # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  29. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  30. # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  31. # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  32. # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  33. from __future__ import print_function
  34. __revision__ = "src/engine/SCons/Tool/rpmutils.py rel_3.0.0:4395:8972f6a2f699 2017/09/18 12:59:24 bdbaddog"
  35. import platform
  36. import subprocess
  37. import SCons.Util
  38. # Start of rpmrc dictionaries (Marker, don't change or remove!)
  39. os_canon = {
  40. 'AIX' : ['AIX','5'],
  41. 'AmigaOS' : ['AmigaOS','5'],
  42. 'BSD_OS' : ['bsdi','12'],
  43. 'CYGWIN32_95' : ['cygwin32','15'],
  44. 'CYGWIN32_NT' : ['cygwin32','14'],
  45. 'Darwin' : ['darwin','21'],
  46. 'FreeBSD' : ['FreeBSD','8'],
  47. 'HP-UX' : ['hpux10','6'],
  48. 'IRIX' : ['Irix','2'],
  49. 'IRIX64' : ['Irix64','10'],
  50. 'Linux' : ['Linux','1'],
  51. 'Linux/390' : ['OS/390','20'],
  52. 'Linux/ESA' : ['VM/ESA','20'],
  53. 'MacOSX' : ['macosx','21'],
  54. 'MiNT' : ['FreeMiNT','17'],
  55. 'NEXTSTEP' : ['NextStep','11'],
  56. 'OS/390' : ['OS/390','18'],
  57. 'OSF1' : ['osf1','7'],
  58. 'SCO_SV' : ['SCO_SV3.2v5.0.2','9'],
  59. 'SunOS4' : ['SunOS','4'],
  60. 'SunOS5' : ['solaris','3'],
  61. 'UNIX_SV' : ['MP_RAS','16'],
  62. 'VM/ESA' : ['VM/ESA','19'],
  63. 'machten' : ['machten','13'],
  64. 'osf3.2' : ['osf1','7'],
  65. 'osf4.0' : ['osf1','7'],
  66. }
  67. buildarch_compat = {
  68. 'alpha' : ['noarch'],
  69. 'alphaev5' : ['alpha'],
  70. 'alphaev56' : ['alphaev5'],
  71. 'alphaev6' : ['alphapca56'],
  72. 'alphaev67' : ['alphaev6'],
  73. 'alphapca56' : ['alphaev56'],
  74. 'amd64' : ['x86_64'],
  75. 'armv3l' : ['noarch'],
  76. 'armv4b' : ['noarch'],
  77. 'armv4l' : ['armv3l'],
  78. 'armv4tl' : ['armv4l'],
  79. 'armv5tejl' : ['armv5tel'],
  80. 'armv5tel' : ['armv4tl'],
  81. 'armv6l' : ['armv5tejl'],
  82. 'armv7l' : ['armv6l'],
  83. 'atariclone' : ['m68kmint','noarch'],
  84. 'atarist' : ['m68kmint','noarch'],
  85. 'atariste' : ['m68kmint','noarch'],
  86. 'ataritt' : ['m68kmint','noarch'],
  87. 'athlon' : ['i686'],
  88. 'falcon' : ['m68kmint','noarch'],
  89. 'geode' : ['i586'],
  90. 'hades' : ['m68kmint','noarch'],
  91. 'hppa1.0' : ['parisc'],
  92. 'hppa1.1' : ['hppa1.0'],
  93. 'hppa1.2' : ['hppa1.1'],
  94. 'hppa2.0' : ['hppa1.2'],
  95. 'i386' : ['noarch','fat'],
  96. 'i486' : ['i386'],
  97. 'i586' : ['i486'],
  98. 'i686' : ['i586'],
  99. 'ia32e' : ['x86_64'],
  100. 'ia64' : ['noarch'],
  101. 'm68k' : ['noarch'],
  102. 'milan' : ['m68kmint','noarch'],
  103. 'mips' : ['noarch'],
  104. 'mipsel' : ['noarch'],
  105. 'parisc' : ['noarch'],
  106. 'pentium3' : ['i686'],
  107. 'pentium4' : ['pentium3'],
  108. 'ppc' : ['noarch','fat'],
  109. 'ppc32dy4' : ['noarch'],
  110. 'ppc64' : ['noarch','fat'],
  111. 'ppc64iseries' : ['ppc64'],
  112. 'ppc64pseries' : ['ppc64'],
  113. 'ppc8260' : ['noarch'],
  114. 'ppc8560' : ['noarch'],
  115. 'ppciseries' : ['noarch'],
  116. 'ppcpseries' : ['noarch'],
  117. 's390' : ['noarch'],
  118. 's390x' : ['noarch'],
  119. 'sh3' : ['noarch'],
  120. 'sh4' : ['noarch'],
  121. 'sh4a' : ['sh4'],
  122. 'sparc' : ['noarch'],
  123. 'sparc64' : ['sparcv9v'],
  124. 'sparc64v' : ['sparc64'],
  125. 'sparcv8' : ['sparc'],
  126. 'sparcv9' : ['sparcv8'],
  127. 'sparcv9v' : ['sparcv9'],
  128. 'sun4c' : ['noarch'],
  129. 'sun4d' : ['noarch'],
  130. 'sun4m' : ['noarch'],
  131. 'sun4u' : ['noarch'],
  132. 'x86_64' : ['noarch'],
  133. }
  134. os_compat = {
  135. 'BSD_OS' : ['bsdi'],
  136. 'Darwin' : ['MacOSX'],
  137. 'FreeMiNT' : ['mint','MiNT','TOS'],
  138. 'IRIX64' : ['IRIX'],
  139. 'MiNT' : ['FreeMiNT','mint','TOS'],
  140. 'TOS' : ['FreeMiNT','MiNT','mint'],
  141. 'bsdi4.0' : ['bsdi'],
  142. 'hpux10.00' : ['hpux9.07'],
  143. 'hpux10.01' : ['hpux10.00'],
  144. 'hpux10.10' : ['hpux10.01'],
  145. 'hpux10.20' : ['hpux10.10'],
  146. 'hpux10.30' : ['hpux10.20'],
  147. 'hpux11.00' : ['hpux10.30'],
  148. 'hpux9.05' : ['hpux9.04'],
  149. 'hpux9.07' : ['hpux9.05'],
  150. 'mint' : ['FreeMiNT','MiNT','TOS'],
  151. 'ncr-sysv4.3' : ['ncr-sysv4.2'],
  152. 'osf4.0' : ['osf3.2','osf1'],
  153. 'solaris2.4' : ['solaris2.3'],
  154. 'solaris2.5' : ['solaris2.3','solaris2.4'],
  155. 'solaris2.6' : ['solaris2.3','solaris2.4','solaris2.5'],
  156. 'solaris2.7' : ['solaris2.3','solaris2.4','solaris2.5','solaris2.6'],
  157. }
  158. arch_compat = {
  159. 'alpha' : ['axp','noarch'],
  160. 'alphaev5' : ['alpha'],
  161. 'alphaev56' : ['alphaev5'],
  162. 'alphaev6' : ['alphapca56'],
  163. 'alphaev67' : ['alphaev6'],
  164. 'alphapca56' : ['alphaev56'],
  165. 'amd64' : ['x86_64','athlon','noarch'],
  166. 'armv3l' : ['noarch'],
  167. 'armv4b' : ['noarch'],
  168. 'armv4l' : ['armv3l'],
  169. 'armv4tl' : ['armv4l'],
  170. 'armv5tejl' : ['armv5tel'],
  171. 'armv5tel' : ['armv4tl'],
  172. 'armv6l' : ['armv5tejl'],
  173. 'armv7l' : ['armv6l'],
  174. 'atariclone' : ['m68kmint','noarch'],
  175. 'atarist' : ['m68kmint','noarch'],
  176. 'atariste' : ['m68kmint','noarch'],
  177. 'ataritt' : ['m68kmint','noarch'],
  178. 'athlon' : ['i686'],
  179. 'falcon' : ['m68kmint','noarch'],
  180. 'geode' : ['i586'],
  181. 'hades' : ['m68kmint','noarch'],
  182. 'hppa1.0' : ['parisc'],
  183. 'hppa1.1' : ['hppa1.0'],
  184. 'hppa1.2' : ['hppa1.1'],
  185. 'hppa2.0' : ['hppa1.2'],
  186. 'i370' : ['noarch'],
  187. 'i386' : ['noarch','fat'],
  188. 'i486' : ['i386'],
  189. 'i586' : ['i486'],
  190. 'i686' : ['i586'],
  191. 'ia32e' : ['x86_64','athlon','noarch'],
  192. 'ia64' : ['noarch'],
  193. 'milan' : ['m68kmint','noarch'],
  194. 'mips' : ['noarch'],
  195. 'mipsel' : ['noarch'],
  196. 'osfmach3_i386' : ['i486'],
  197. 'osfmach3_i486' : ['i486','osfmach3_i386'],
  198. 'osfmach3_i586' : ['i586','osfmach3_i486'],
  199. 'osfmach3_i686' : ['i686','osfmach3_i586'],
  200. 'osfmach3_ppc' : ['ppc'],
  201. 'parisc' : ['noarch'],
  202. 'pentium3' : ['i686'],
  203. 'pentium4' : ['pentium3'],
  204. 'powerpc' : ['ppc'],
  205. 'powerppc' : ['ppc'],
  206. 'ppc' : ['rs6000'],
  207. 'ppc32dy4' : ['ppc'],
  208. 'ppc64' : ['ppc'],
  209. 'ppc64iseries' : ['ppc64'],
  210. 'ppc64pseries' : ['ppc64'],
  211. 'ppc8260' : ['ppc'],
  212. 'ppc8560' : ['ppc'],
  213. 'ppciseries' : ['ppc'],
  214. 'ppcpseries' : ['ppc'],
  215. 'rs6000' : ['noarch','fat'],
  216. 's390' : ['noarch'],
  217. 's390x' : ['s390','noarch'],
  218. 'sh3' : ['noarch'],
  219. 'sh4' : ['noarch'],
  220. 'sh4a' : ['sh4'],
  221. 'sparc' : ['noarch'],
  222. 'sparc64' : ['sparcv9'],
  223. 'sparc64v' : ['sparc64'],
  224. 'sparcv8' : ['sparc'],
  225. 'sparcv9' : ['sparcv8'],
  226. 'sparcv9v' : ['sparcv9'],
  227. 'sun4c' : ['sparc'],
  228. 'sun4d' : ['sparc'],
  229. 'sun4m' : ['sparc'],
  230. 'sun4u' : ['sparc64'],
  231. 'x86_64' : ['amd64','athlon','noarch'],
  232. }
  233. buildarchtranslate = {
  234. 'alphaev5' : ['alpha'],
  235. 'alphaev56' : ['alpha'],
  236. 'alphaev6' : ['alpha'],
  237. 'alphaev67' : ['alpha'],
  238. 'alphapca56' : ['alpha'],
  239. 'amd64' : ['x86_64'],
  240. 'armv3l' : ['armv3l'],
  241. 'armv4b' : ['armv4b'],
  242. 'armv4l' : ['armv4l'],
  243. 'armv4tl' : ['armv4tl'],
  244. 'armv5tejl' : ['armv5tejl'],
  245. 'armv5tel' : ['armv5tel'],
  246. 'armv6l' : ['armv6l'],
  247. 'armv7l' : ['armv7l'],
  248. 'atariclone' : ['m68kmint'],
  249. 'atarist' : ['m68kmint'],
  250. 'atariste' : ['m68kmint'],
  251. 'ataritt' : ['m68kmint'],
  252. 'athlon' : ['i386'],
  253. 'falcon' : ['m68kmint'],
  254. 'geode' : ['i386'],
  255. 'hades' : ['m68kmint'],
  256. 'i386' : ['i386'],
  257. 'i486' : ['i386'],
  258. 'i586' : ['i386'],
  259. 'i686' : ['i386'],
  260. 'ia32e' : ['x86_64'],
  261. 'ia64' : ['ia64'],
  262. 'milan' : ['m68kmint'],
  263. 'osfmach3_i386' : ['i386'],
  264. 'osfmach3_i486' : ['i386'],
  265. 'osfmach3_i586' : ['i386'],
  266. 'osfmach3_i686' : ['i386'],
  267. 'osfmach3_ppc' : ['ppc'],
  268. 'pentium3' : ['i386'],
  269. 'pentium4' : ['i386'],
  270. 'powerpc' : ['ppc'],
  271. 'powerppc' : ['ppc'],
  272. 'ppc32dy4' : ['ppc'],
  273. 'ppc64iseries' : ['ppc64'],
  274. 'ppc64pseries' : ['ppc64'],
  275. 'ppc8260' : ['ppc'],
  276. 'ppc8560' : ['ppc'],
  277. 'ppciseries' : ['ppc'],
  278. 'ppcpseries' : ['ppc'],
  279. 's390' : ['s390'],
  280. 's390x' : ['s390x'],
  281. 'sh3' : ['sh3'],
  282. 'sh4' : ['sh4'],
  283. 'sh4a' : ['sh4'],
  284. 'sparc64v' : ['sparc64'],
  285. 'sparcv8' : ['sparc'],
  286. 'sparcv9' : ['sparc'],
  287. 'sparcv9v' : ['sparc'],
  288. 'sun4c' : ['sparc'],
  289. 'sun4d' : ['sparc'],
  290. 'sun4m' : ['sparc'],
  291. 'sun4u' : ['sparc64'],
  292. 'x86_64' : ['x86_64'],
  293. }
  294. optflags = {
  295. 'alpha' : ['-O2','-g','-mieee'],
  296. 'alphaev5' : ['-O2','-g','-mieee','-mtune=ev5'],
  297. 'alphaev56' : ['-O2','-g','-mieee','-mtune=ev56'],
  298. 'alphaev6' : ['-O2','-g','-mieee','-mtune=ev6'],
  299. 'alphaev67' : ['-O2','-g','-mieee','-mtune=ev67'],
  300. 'alphapca56' : ['-O2','-g','-mieee','-mtune=pca56'],
  301. 'amd64' : ['-O2','-g'],
  302. 'armv3l' : ['-O2','-g','-march=armv3'],
  303. 'armv4b' : ['-O2','-g','-march=armv4'],
  304. 'armv4l' : ['-O2','-g','-march=armv4'],
  305. 'armv4tl' : ['-O2','-g','-march=armv4t'],
  306. 'armv5tejl' : ['-O2','-g','-march=armv5te'],
  307. 'armv5tel' : ['-O2','-g','-march=armv5te'],
  308. 'armv6l' : ['-O2','-g','-march=armv6'],
  309. 'armv7l' : ['-O2','-g','-march=armv7'],
  310. 'atariclone' : ['-O2','-g','-fomit-frame-pointer'],
  311. 'atarist' : ['-O2','-g','-fomit-frame-pointer'],
  312. 'atariste' : ['-O2','-g','-fomit-frame-pointer'],
  313. 'ataritt' : ['-O2','-g','-fomit-frame-pointer'],
  314. 'athlon' : ['-O2','-g','-march=athlon'],
  315. 'falcon' : ['-O2','-g','-fomit-frame-pointer'],
  316. 'fat' : ['-O2','-g','-arch','i386','-arch','ppc'],
  317. 'geode' : ['-Os','-g','-m32','-march=geode'],
  318. 'hades' : ['-O2','-g','-fomit-frame-pointer'],
  319. 'hppa1.0' : ['-O2','-g','-mpa-risc-1-0'],
  320. 'hppa1.1' : ['-O2','-g','-mpa-risc-1-0'],
  321. 'hppa1.2' : ['-O2','-g','-mpa-risc-1-0'],
  322. 'hppa2.0' : ['-O2','-g','-mpa-risc-1-0'],
  323. 'i386' : ['-O2','-g','-march=i386','-mtune=i686'],
  324. 'i486' : ['-O2','-g','-march=i486'],
  325. 'i586' : ['-O2','-g','-march=i586'],
  326. 'i686' : ['-O2','-g','-march=i686'],
  327. 'ia32e' : ['-O2','-g'],
  328. 'ia64' : ['-O2','-g'],
  329. 'm68k' : ['-O2','-g','-fomit-frame-pointer'],
  330. 'milan' : ['-O2','-g','-fomit-frame-pointer'],
  331. 'mips' : ['-O2','-g'],
  332. 'mipsel' : ['-O2','-g'],
  333. 'parisc' : ['-O2','-g','-mpa-risc-1-0'],
  334. 'pentium3' : ['-O2','-g','-march=pentium3'],
  335. 'pentium4' : ['-O2','-g','-march=pentium4'],
  336. 'ppc' : ['-O2','-g','-fsigned-char'],
  337. 'ppc32dy4' : ['-O2','-g','-fsigned-char'],
  338. 'ppc64' : ['-O2','-g','-fsigned-char'],
  339. 'ppc8260' : ['-O2','-g','-fsigned-char'],
  340. 'ppc8560' : ['-O2','-g','-fsigned-char'],
  341. 'ppciseries' : ['-O2','-g','-fsigned-char'],
  342. 'ppcpseries' : ['-O2','-g','-fsigned-char'],
  343. 's390' : ['-O2','-g'],
  344. 's390x' : ['-O2','-g'],
  345. 'sh3' : ['-O2','-g'],
  346. 'sh4' : ['-O2','-g','-mieee'],
  347. 'sh4a' : ['-O2','-g','-mieee'],
  348. 'sparc' : ['-O2','-g','-m32','-mtune=ultrasparc'],
  349. 'sparc64' : ['-O2','-g','-m64','-mtune=ultrasparc'],
  350. 'sparc64v' : ['-O2','-g','-m64','-mtune=niagara'],
  351. 'sparcv8' : ['-O2','-g','-m32','-mtune=ultrasparc','-mv8'],
  352. 'sparcv9' : ['-O2','-g','-m32','-mtune=ultrasparc'],
  353. 'sparcv9v' : ['-O2','-g','-m32','-mtune=niagara'],
  354. 'x86_64' : ['-O2','-g'],
  355. }
  356. arch_canon = {
  357. 'IP' : ['sgi','7'],
  358. 'alpha' : ['alpha','2'],
  359. 'alphaev5' : ['alphaev5','2'],
  360. 'alphaev56' : ['alphaev56','2'],
  361. 'alphaev6' : ['alphaev6','2'],
  362. 'alphaev67' : ['alphaev67','2'],
  363. 'alphapca56' : ['alphapca56','2'],
  364. 'amd64' : ['amd64','1'],
  365. 'armv3l' : ['armv3l','12'],
  366. 'armv4b' : ['armv4b','12'],
  367. 'armv4l' : ['armv4l','12'],
  368. 'armv5tejl' : ['armv5tejl','12'],
  369. 'armv5tel' : ['armv5tel','12'],
  370. 'armv6l' : ['armv6l','12'],
  371. 'armv7l' : ['armv7l','12'],
  372. 'atariclone' : ['m68kmint','13'],
  373. 'atarist' : ['m68kmint','13'],
  374. 'atariste' : ['m68kmint','13'],
  375. 'ataritt' : ['m68kmint','13'],
  376. 'athlon' : ['athlon','1'],
  377. 'falcon' : ['m68kmint','13'],
  378. 'geode' : ['geode','1'],
  379. 'hades' : ['m68kmint','13'],
  380. 'i370' : ['i370','14'],
  381. 'i386' : ['i386','1'],
  382. 'i486' : ['i486','1'],
  383. 'i586' : ['i586','1'],
  384. 'i686' : ['i686','1'],
  385. 'ia32e' : ['ia32e','1'],
  386. 'ia64' : ['ia64','9'],
  387. 'm68k' : ['m68k','6'],
  388. 'm68kmint' : ['m68kmint','13'],
  389. 'milan' : ['m68kmint','13'],
  390. 'mips' : ['mips','4'],
  391. 'mipsel' : ['mipsel','11'],
  392. 'pentium3' : ['pentium3','1'],
  393. 'pentium4' : ['pentium4','1'],
  394. 'ppc' : ['ppc','5'],
  395. 'ppc32dy4' : ['ppc32dy4','5'],
  396. 'ppc64' : ['ppc64','16'],
  397. 'ppc64iseries' : ['ppc64iseries','16'],
  398. 'ppc64pseries' : ['ppc64pseries','16'],
  399. 'ppc8260' : ['ppc8260','5'],
  400. 'ppc8560' : ['ppc8560','5'],
  401. 'ppciseries' : ['ppciseries','5'],
  402. 'ppcpseries' : ['ppcpseries','5'],
  403. 'rs6000' : ['rs6000','8'],
  404. 's390' : ['s390','14'],
  405. 's390x' : ['s390x','15'],
  406. 'sh' : ['sh','17'],
  407. 'sh3' : ['sh3','17'],
  408. 'sh4' : ['sh4','17'],
  409. 'sh4a' : ['sh4a','17'],
  410. 'sparc' : ['sparc','3'],
  411. 'sparc64' : ['sparc64','2'],
  412. 'sparc64v' : ['sparc64v','2'],
  413. 'sparcv8' : ['sparcv8','3'],
  414. 'sparcv9' : ['sparcv9','3'],
  415. 'sparcv9v' : ['sparcv9v','3'],
  416. 'sun4' : ['sparc','3'],
  417. 'sun4c' : ['sparc','3'],
  418. 'sun4d' : ['sparc','3'],
  419. 'sun4m' : ['sparc','3'],
  420. 'sun4u' : ['sparc64','2'],
  421. 'x86_64' : ['x86_64','1'],
  422. 'xtensa' : ['xtensa','18'],
  423. }
  424. # End of rpmrc dictionaries (Marker, don't change or remove!)
  425. def defaultMachine(use_rpm_default=True):
  426. """ Return the canonicalized machine name. """
  427. if use_rpm_default:
  428. try:
  429. # This should be the most reliable way to get the default arch
  430. rmachine = subprocess.check_output(['rpm', '--eval=%_target_cpu'], shell=False).rstrip()
  431. rmachine = SCons.Util.to_str(rmachine)
  432. except Exception as e:
  433. # Something went wrong, try again by looking up platform.machine()
  434. return defaultMachine(False)
  435. else:
  436. rmachine = platform.machine()
  437. # Try to lookup the string in the canon table
  438. if rmachine in arch_canon:
  439. rmachine = arch_canon[rmachine][0]
  440. return rmachine
  441. def defaultSystem():
  442. """ Return the canonicalized system name. """
  443. rsystem = platform.system()
  444. # Try to lookup the string in the canon tables
  445. if rsystem in os_canon:
  446. rsystem = os_canon[rsystem][0]
  447. return rsystem
  448. def defaultNames():
  449. """ Return the canonicalized machine and system name. """
  450. return defaultMachine(), defaultSystem()
  451. def updateRpmDicts(rpmrc, pyfile):
  452. """ Read the given rpmrc file with RPM definitions and update the
  453. info dictionaries in the file pyfile with it.
  454. The arguments will usually be 'rpmrc.in' from a recent RPM source
  455. tree, and 'rpmutils.py' referring to this script itself.
  456. See also usage() below.
  457. """
  458. try:
  459. # Read old rpmutils.py file
  460. oldpy = open(pyfile,"r").readlines()
  461. # Read current rpmrc.in file
  462. rpm = open(rpmrc,"r").readlines()
  463. # Parse for data
  464. data = {}
  465. # Allowed section names that get parsed
  466. sections = ['optflags',
  467. 'arch_canon',
  468. 'os_canon',
  469. 'buildarchtranslate',
  470. 'arch_compat',
  471. 'os_compat',
  472. 'buildarch_compat']
  473. for l in rpm:
  474. l = l.rstrip('\n').replace(':',' ')
  475. # Skip comments
  476. if l.lstrip().startswith('#'):
  477. continue
  478. tokens = l.strip().split()
  479. if len(tokens):
  480. key = tokens[0]
  481. if key in sections:
  482. # Have we met this section before?
  483. if tokens[0] not in data:
  484. # No, so insert it
  485. data[key] = {}
  486. # Insert data
  487. data[key][tokens[1]] = tokens[2:]
  488. # Write new rpmutils.py file
  489. out = open(pyfile,"w")
  490. pm = 0
  491. for l in oldpy:
  492. if pm:
  493. if l.startswith('# End of rpmrc dictionaries'):
  494. pm = 0
  495. out.write(l)
  496. else:
  497. out.write(l)
  498. if l.startswith('# Start of rpmrc dictionaries'):
  499. pm = 1
  500. # Write data sections to single dictionaries
  501. for key, entries in data.items():
  502. out.write("%s = {\n" % key)
  503. for arch in sorted(entries.keys()):
  504. out.write(" '%s' : ['%s'],\n" % (arch, "','".join(entries[arch])))
  505. out.write("}\n\n")
  506. out.close()
  507. except:
  508. pass
  509. def usage():
  510. print("rpmutils.py rpmrc.in rpmutils.py")
  511. def main():
  512. import sys
  513. if len(sys.argv) < 3:
  514. usage()
  515. sys.exit(0)
  516. updateRpmDicts(sys.argv[1], sys.argv[2])
  517. if __name__ == "__main__":
  518. main()