"Fossies" - the Fresh Open Source Software Archive

Member "scons-3.0.5/engine/SCons/Tool/rpmutils.py" (26 Mar 2019, 17183 Bytes) of package /linux/misc/scons-3.0.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "rpmutils.py" see the Fossies "Dox" file reference documentation.

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