Qc@sdZddlZddlZddlZddlZi8dd6dd6dd6d d 6d d 6d d6dd6dd6dd6dd6dd6dd6dd6dd6dd 6d!d"6d#d$6d%d&6d'd(6d)d*6d+d,6d-d.6d/d06d1d26d3d46d5d66d7d86d9d:6d;d<6d=d>6d?d@6dAdB6dCdD6dEdF6dGdH6dIdJ6dKdL6dMdN6dOdP6dQdR6dSdT6dUdV6dWdX6dYdZ6d[d\6d]d^6d_d`6dadb6dcdd6dedf6dgdh6didj6dkdl6dmdn6dodp6dqdr6ZdsejfdtYZdS(usN cmlsystem.py -- CML2 configurator front-end support by Eric S. Raymond, Mode-independent code for front ends. This supplies one big class that you initialize by loading a compiled rulebase. The class provides functions for doing tests and manipulations on the rulebase, and for writing out configuration files. iNsAbout to write %s=%s (type %s)tABOUTs#bad token `%s' while expecting '='.t BADEQUALSsOCompiler/configurator version mismatch (%s/%s), recompile the rulebase please. t BADVERSIONs4unrecognized name `%s' while expecting known symbol.tBADTOKENs&Boolean symbol %s cannot have value m.tBADTRITs0 %sBinding from constraint: %s=%s (source %s)tBINDINGs ...menu %s check donet CHECKDONEs Checking menu %s...tCHECKINGs Committing new bindings.tCOMMITs( Value %s for %s failed constraint %st CONSTRAINTsCannot set derived symbol %stDERIVEDs %s value %s excluded by %stEXCLUDEDs Failed constraint %stFAILREQs (frozen)tFROZENsHelp-required flag is %stHELPFLAGs/Symbol %s forced to n during recovery attempt. tINCONSTs% %s not visible, ancestor %s falsetINVISANCs) %s not visible, ancestor %s invisiblet INVISANC2s %s not visible, no helpt INVISHELPs( %s not visible, %s guard %s is falsetINVISMEs is_visible(%s) calledt INVISSTARTs% %s not visible, upward visibilitytINVISUPs)All M-valued symbols will be forced to Y.tMODULESNs'All tristate symbols will default to M.tMODULESMs$Tristate symbols won't default to M.tMODULESYs" %s not visible, it has no helptNOHELPs(not saveable) tNOTSAVEDsNo visible items at %st NOVISIBLEs %sOld value of %s is %stOLDVALs3 Query of choices menu %s elided, button pressedt RADIOINVISsReading configuration from %stREADINGs/Attempting recovery from invalid configuration:tRECOVERYs Recovery OK.t RECOVEROKs' %sRedundant assignment forced by %st REDUNDANTs"Attempt to rename %s to %s failed.tRENAMEs Rolling back new bindings: tROLLBACKs# # That's all, folks! tSAVEENDs(%sAttempt to set frozen symbol %s failedt SETFAILEDs%s=%stSETTINGs*# # Automatically generated, don't edit # t SHAUTOGENs# # Derived symbols # t SHDERIVEDs (deduced from %s)t SIDEEFFECTs- %s not visible, all subqueries invisible.tSUBINVISs( Set of %s = %s triggered by guard %stTRIGGERsTrit flag is now %stTRITFLAGs( %s not visible, trits are suppressedtTRITSOFFs!Node %s unknown value type: %s %st TYPEUNKNOWNs %sSymbol %s unchangedt UNCHANGEDs# # Uncommitted bindings # tUNCOMMITs%File load violated these constraints:tUNLOAD1s6Undoing file loads, recovery failed these constraints:tUNLOAD2s%s is not saveablet UNSAVEABLEsUser action on %s.t USERSETTINGs Valid range of %s is %st VALIDRANGEs Node %s %s has unknown value: %st VALUNKNOWNs Query of %s *not* elidedtVISIBLEt CMLSystemcBs(eZdZidd6dd6dd6dd6dd6dd6ZdZdZd Zd Zd d9d YZd Z dZ d:dddZ dZ dZdZdZdZd:dZdZddZddZejd:ddZddZd:ddZdZd Zd!Zd"Zd#Zd$Z d%Z!d&Z"d'Z#d(Z$d)Z%dd:d*Z&d+Z'dd,Z(d:dd-Z)d.Z*d/Z+e,j-d0Z.e,j-d1Z/d2Z0d3Z1d4Z2d5Z3d6Z4d7Z5d8Z6RS(;s2A rulebase, from the point of view of a front end.s!=s==s<=t>s>=ttmenuR?R^RZtitems(RXtsibling((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyt_freezes   cSsg|js|jdkrdS|jdkrcx1|jD]&}|j|r5|j r5dSq5WdSdS(sIs the symbol frozen?tmessageiRgR;i(smenuschoices(R>R?Rht is_visibleRb(RXRJtitem((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyt_frozensiR(R?tcPickletloadtopent__dict__RLtdirRTRURcROt__str__tfreezeRbRYtcdepthtsyststderrterroutt suppressionst interactivetcommitst_engtlangt side_effectsttrit_tiet trits_enabledtversiontwritet SystemExit(RJtrulesRoR[RfRjRn((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyt__init__ds6                'cCs|jo|j o|jS(N(RIRat is_symbol(RJRX((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pytis_newscCs*|j|kr&|jj|dndS(sBConditionally emit a debug message to the designated error stream.s N(RYRyR(RJt thresholdtmsg((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyt debug_emitst __BindingcBseZdZdZRS(cCs(||_||_||_d|_dS(Ni(RXRZtlinktvisible(RJRXRZR((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyRs   cCsd|jj|jfS(Ns%s=%s(RXR^RZ(RJ((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyt__repr__s(t__name__t __module__RR(((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyRs cCs;t|dsdSx!|jD]}|jr|jSqWdS(sCGet the most recent visible value for symbol off the binding stack.RCN(thasattrRBRCRRZ(RJRXtbinding((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyt __bindevals  cCs/|}x"|r*|jd7_|j}q WdS(Ni(R`Rg(RJRXRg((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyt __bindmarks ic Cs|jddd|j|j|| |f|s=|}n|jj|r|j|}x8|r|j|kr|j|krdS|j}q_Wn||jkr|dks||krd}n|j d| f}|j d|j|f|}|r)||kr)| r)|j j |n||j kr|tjkra|j j |j dq|tjkr|j j |j d q|tjkr|j j |j d qn|jr|jd d |qn|j|||jj|}||j|Find all symbols which need to have their old bindings removedR;(REtkeysRgR?textendRhR(RJtundotprimary((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyt__find_commit_set's cCs^x'|jD]}|j||jq W|jj|j|jj|jd|_dS(sCommit all new bindings.iN(t_CMLSystem__find_commit_sett_CMLSystem__unbindsymbolRDtupdateRERLR|(RJRX((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyt __bindcommit2s  cCsD|jj|}|r@|}x|r<d|_|j}q!WndS(s)Make every old binding of symbol visible.iN(RDRRR(RJRRR((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyt __bindreveal:s   cCsD|jj|}|r@|}x|r<d|_|j}q!WndS(sCTemporarily make old bindings hanging on a given primary invisible.iN(RDRRR(RJRRR((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyt __bindconcealBs   cCsd}|dkr|j}nxw|jD]i\}}|d|jd |j||jkf}x"|r|| d}|j}qdW|d d}q+W|S( s%Dump the state of the bindings stack.RMs# %s(%s, touched=%d): tinactivetactives, is N(RR(RBRDRhR^RRGR(RJRReRR((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pytbinddumpJs  *  cCsd}|j}|s(|j|n||jdddjtt|d7}g}|jd|jdxtt|j D]}t j |j ||j st j|j |j}xF|D];}||kr|j r|jr|j|qqWqqW|r||jdd7}xI|D]A}||jd|jf7}|j|t j|jjq4W|j}|s|j|||jd7}q|j||jdddjtt|d7}n|S( s-Attempt to commit the results of a file load.RMR1s iRRR R2(t sanecheckt_CMLSystem__commitR~tjointmaptreprRRRt constraintsRTtevaluatetreducedRYt flatten_exprt predicateRbRVRR^t_CMLSystem__set_symbol_internalRWRFRLt_CMLSystem__rollback(RJRuterrorst violationstnukemRt flattenedtsym((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyt loadcommit\s4 /  %    2cCspddl}|jt||}|jd7_|jd|jd|fd}d}|j}d|_g|_xd}|j} | sPn| dkr|jdd}q{n%| d kr|jdd}q{nt |j r%| dt |j !|j kr%| t |j } n|j j | rG|j | } n5d} |j|jd | } || d }d}|j} | d kr|j|jd | f} || d }d}n|j} |sq{n| d|jkr| dd!} n| sq{n| jrM|jd|j|jd| jfq{n| dkr| jdkr|j|jd| jf} || d }q{nd| _| jdkr| dkrd|_n| j}|j| | }|j| ||jj||kr{|d}q{q{|jj|rM||j|7}n|jj|||_||fS(s9Load bindings from a defconfig-format configuration file.iNt$iRiRMs$$commits$$freezeRs t=RiR RtboolRttrit(tshlexRqt wordcharsRR~R{Rt get_tokenRRtprefixR<RRBt error_leadertquotest is_derivedR^R?RaRRctvalue_from_stringRRFRLtinstreamtcloseRIR(RJtfileRuRtstreamtchangesRtstashtdobindtsymnameRXterrmsgtsepRZtoldvaltnewval((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyRps         .     +!        tnormalcCs|jdkrdS|jr?|j s;tj|jr?dS|jrXtj|jS|dkrhdS|j|s{dSdS(s?Should this symbol be visible in the configuration written out?iitprobe(R`Rt visibilityRTRt saveabilityRl(RJtnodetmode((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pytsaveables(  cCsd}|jr$|j}i|_nyt|tdkrudtj}t|d}|j|jdn|}|dkr&yddlm }m }ddl } |jd | j d |jd |d |d td d} |jd| j | jWq&q&Xn|j|j||||dkrtd|jjr}|j|jdnxR|jjD]>} | jr|r|jn|j| |||qqWn|r||_|j|jd|j|j|jn|dkr4|j|jdnt|tdkr|jytj||Wqtk r|jd||f} t| qXnd|_|r|jndSWntk r} | jdSXdS(s8Save a configuration to the named output stream or file.RMs.tmpconfig%d.shtwR'tlisti(tgmtimetstrftimeNs# Generated on: s s# At: s%a, %d %b %Y %H:%M:%S +0000s /proc/versiontrs# cSs |jS(N(R(tx((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyt sR(R0RR$R"i(RBRER?tostgetpidRqRR~ttimeRRtsockett gethostnametreadRt_CMLSystem__save_recursetstarttfilterR<R=RttwirlRtrenametOSErrortIOErrorR|tendtargs(RJtoutfiletbatonRREt shelltemptoutfpRRRtinfpRKtreasontdetails((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pytsavesb     !          RMc Cs|j|j}|j|j}|jd|jd||t|fy|jdkrx|jd||fn|jdkr|jd||fn|jdkr|jd||fny|jdkr|jd || fnO|dkr#|j r#|jd |fn t |jd ||j|f|r]|jd|n|jdWn4t j \}}}d||fGHt dnXdS(NiRRPs%s=%dRQs%s=0x%xRRs%s="%s"RRs%s=%ss%s=nR6s # s s#Internal error %s while writing %s.i(sboolstrit(RR^RcRYRR~R?RRBRVt ValueErrorRwtexc_infoR( RJRXt shellstreamtlabelRRZterrtypeterrvalterrtrace((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyt save_symbol's,* cCsO|j||}|s:|jd|jd|jdS|jr|jd|jf|j|x'|jD]}|j||||qqW|jdn|j dkr8d}|j r||j 7}n|j r|dkr| r|d7}n|dkr"| r"||jd 7}n|j |||n|rK|j ndS( NiR3s # # %s # s RkRMRRR(RRR~R^RhRtprompttvisitRR?t propertiest showpropsRR(RJRRRRRtchildR((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyt__save_recurse@s*    cCst|tjo|j S(s'Is a term mutable (symbol, not frozen)?(t isinstanceRTRURb(RJRX((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyt is_mutableZscCsQ|jd|jd|jf|js.dS|j|sb|jd|jd|jfdS|j|s|jd|jd|jfdS|jdkrxpt|jj j |dt |jj D]@}|jj |jdkrPq|j |jj |rdSqWdS|j |s/dS|jd|jd|jdS( sShould we ask this question?iRiRiRRkR7(RR~R^Rzt_CMLSystem__help_visiblet_CMLSystem__upward_visibleR?RRgRhtindexRRlt_CMLSystem__subqueries_visible(RJtqueryR((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyRl^s(! !!5cCsJ|js dS|j|s dS|j|s3dS|j|sFdSdS(Nii(RzRt_CMLSystem__dep_visibleR(RJR ((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pytis_visible_menus_choices}s cCsX|jrT|j rT|jrT|jj rT|jd|jd|jdSdS(NiRii(Rthelpthelp_tieRcRR~R^(RJR ((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyt__help_visibles2cCs|}x||jkr|jdkrttj|j rt|jd|jd|j|jtj|jfdS|j |sdS|j }q WdS(NiRii( RRRBRTRRR~R^tdisplay_expressionR!Rg(RJR tupward((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyt__upward_visibles"6 cCs|jrd}|jdks-|jdkrx<|jD]1}|jdkr7|j|rhd}Pqhq7q7W|dkrdSqndS(NiRgR;Rki(RhR?R"(RJR R`R((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyt__subqueries_visibles    cCsxq|jD]b}tj||j}|jdkrD||krDPq |jdkr ||tjkkr Pq q WdS|jd|jd| tj| | fdS(s;Do ancestry relationships allow given value of given symbolRRiiR i( t ancestorsRTRRYR?RWRR~R(RJRXRZtancestortv((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyt__dep_value_oks$0cCsx|jD]}tj|sJ|jd|jd|j|jfdS|jr tj|j r |jd|jd|j|jfdSq WdS(s3Do ancestry relations allow a symbol to be visible?iRiRi(R*RTRRR~R^R(RJRXtsuper((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyt __dep_visibles''cCs1|jdd| | | | f|jr|jr|j}|tjkr|j|krl|}nK|jstj}n6|dkrtj}n|dkrtj}n|}|j|||ddqnx'|j D]}|j ||||qWx*|j j D]}|j ||||q WdS(s;Force a symbol's ancestors up, based on the symbol's value.is' dep_force_ancestors(%s, %s, %s, %s)RRRiN( RRVR?RTRWRRRRR*t_CMLSystem__dep_force_ancestorsRg(RJt dependentRt dependvalueR+tanctypeRtupper((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyt__dep_force_ancestorss$$        c CsC|jdd| | | | f|jr|jr|j}tj|}||kr|j|krx|}nH|jstj}n3|dkr|}n|tjkr|}n|}|j|||ddqn|jrxT|jD]}|j ||||qWn*x'|j D]} |j |||| qWdS(s?Force a symbol's descendents down, based on the symbol's value.is( dep_force_dependents(%s, %s, %s, %s)RRiN( RRVR?RTRRRWRRht _CMLSystem__dep_force_dependentst dependents( RJtguardRt guardvalueR1tdeptypetdepvalueRRtlower((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyt__dep_force_dependentss($         cCsb|jd|jd|j g|_x*|jjD]}|j||jq8Wg|_dS(sRoll back all new bindings.iR#N(RR~RGRERRR(RJRX((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyt __rollbacks  cCs|r+|jd|jd|jdn|jd|jd|jr|j|jkrtj|j|_|jd|jdtj|j fn|jr|j|jkr|jd|jd|jj nx$|jD]}|r|j qqWg|_|r(|j dn|rxOt t |jD]8}|j|j|}|dkrD||j|=(RRTRURRNR@RRYRKRR~RvR^RRBRRWR8trelational_mapRRRVRR?tmaxRZtmin( RJRPRR^RtopR[R\R8t left_mutablet right_mutabletleftvaltrightval((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyt__inner_constrains  +     00                 cCs@|j s|j| rdS|jdd|j|jf|jd|_|jdkr|jdkr|j r|jj|j }}y+x$|j|j|s|d7}qWWn?t k r|jd|j d| f|}d|_ nX|j |j|tjn|jdd|j|jfdS( s,Register the fact that we've visited a menu.NisVisiting %s (%s) startsiR;RisVisiting %s (%s) ends(RgRlRR^R?RLRbRhRR@t IndexErrorR~RzRIRTR(RJRKtbasetind((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyRjs +  cCs|jdkr)|j r)|jd}nbx_|jr|j}|jj|}|t|jjdkru|}q,|j|d}Pq,W|dkr|j}n|S(s4Return the next menu or symbol in depth-first order.RgiiN(R?R@RhRgRRRBR(RJtheretuptwhere((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyt next_nodes     cCs|jdkr)|j r)|jd}nRxO|jrz|j}|jj|}|dkre|}q,|j|d}Pq,W|dkr|j}n|S(s8Return the previous menu or symbol in depth-first order.RgiiN(R?R@RhRgRRBR(RJRmRnRo((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyt previous_nodes      cCs tj|}tjdd}xr|jjD]a}|jr1|jdkr1||}|dkrmq1q|j |r|j j |qq1q1Wd|_ xN|j D]C}|j dkr|j |_ q|j |j krd|_ PqqW|j j d|_|S(s:Return a menu composed of symbols matching a given regexp.tsearchRgRkiN(tretcompileRTRUR<R=RR?RBRrRhRRgRtnosuppressions(RJtpatternthooktregexpthitsRKttextRX((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyRrs&      cCs|j|dS(s:Return a menu composed of symbols matching a given regexp.cSs|j|jS(N(R^R(R((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyRs(Rr(RJRv((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyt symbolsearchscCs|j|dS(s:Return a menu composed of symbols matching a given regexp.cSs |jS(N(R#(R((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyRs(Rr(RJRv((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyt helpsearchscCs|js dS|jrCx|jD]\}}||kr dSq Wnoxl|jD]a}t|tdtdfkr||krdSqM||dkrM||dkrMdSqMWdS(sACheck whether a value is within a symbol's specified valid range.iil(RtenumR?(RJRXRZRt possibilitytspan((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyt range_checks    $  (N(7RRt__doc__RaRLRRRRRSRRBRKRRRBRFRERRRpRRwtstdoutR RRRRlR"RRRt_CMLSystem__dep_value_okR!R0R6RRRRIRRR@RTRRNR]RRpRqRrR{R|R(((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyR8Lsf  V    0     ( [ :         ! c  ?e      (RRRwRsRTR}t CMLRulebaseR8(((s@/home/bertrand/FreeVMS/FreeVMS/sources/contrib/cml2/cmlsystem.pyt sx$