ó ºµiVc@s•dZddlZddlZddlZddlmZmZmZmZddl m Z d„Z de fd„ƒYZ de fd „ƒYZ dS( s menu.conf parser and generator iÿÿÿÿN(t BootmgmtErrortBootmgmtArgumentErrortBootmgmtConfigReadErrortBootmgmtConfigWriteError(t LoggerMixincCsdtjƒS(s;Returns a timestamp string with all significant digits s%f(ttime(((s0../../common/bootmgmt/backend/loader/menuconf.pyt timestamp'stMenuConfigEntrycBsƒeZdZd d„Zd„Zd„Zed„ƒZed„ƒZ ed„ƒZ d„Z d„Z e d „ƒZd „ZRS( sñMenuConfigEntry represents one menu entry (section) from a MenuConfigParser. Each entry is linked with the MenuConfigParser that created it so that when it is modified, it can inform the parent that state has been modified. cCsÒtt|ƒjƒ|s2td|jjƒ‚n| s]t|ƒtk s]t|ƒdkrvtd|jjƒ‚n||_ ||_ |r£|j |ƒ|_ n i|_ d|j krÎt ƒ|j d\}}t|tƒs|jd|ƒt|ƒ||d}n3t|ƒt|ƒkrktj||ƒ}nd}|SWnttfk rnXtj||ƒS(s¼Compares two MenuConfigEntry instances. the entry with the most-recent modified timestamp wins, otherwise, the entry with the lexically-largest section tuple wins. Riÿÿÿÿi(RRR)RR=R*tKeyError(RR<t self_modifiedtother_modifiedtcmpval((s0../../common/bootmgmt/backend/loader/menuconf.pyt__cmp__³s   N(R t __module__t__doc__R/R R"RtpropertyRR,R0R7R:t staticmethodR=RB(((s0../../common/bootmgmt/backend/loader/menuconf.pyR-s       R-cBsàeZdZdZdZded„Zd„Zd„Ze d„ƒZ e j d„ƒZ e d „ƒZ dd „Zd „Zdded „Zd „Zd„Zd„Zd„Zd„Zd„Zd„Zded„ZRS(sDThe MenuConfigParser class provides an interface to the menu.conf file. The menu.conf file contains a set of sections, each (except for two) of which describes a single Solaris boot entry in the automatically-generated boot-loader menu. The syntax of the menu.conf is that accepted by the ConfigParser class. The sections and properties include: [meta] order = [global] Zero or More of: [:] title= [Required] default={True|False} # If this is the default boot entry transient={True|False} # If this is a transient entry Other properties, depending on the : bootfs= [SolarisDiskBootInstance] [required] kargs= [SolarisBootInstance] [optional] kernel= [SolarisBootInstance] [optional] boot_archive= [SolarisBootInstance] [optional] credential= [SolarisBootInstance] [optional] s·# # This file is modified without notice. # DO NOT EDIT THIS FILE DIRECTLY. CHANGES MAY NOT BE PRESERVED. # Changes to this file can be made indirectly via bootadm(1M) subcommands. # t|s/rpool/boot/grub/menu.confcCsrtt|ƒjƒ||_d|_g|_t|_t j ƒ|_ i|_ i|_ |sn|j|ƒndS(säCreates or loads the menu configuration from the specified file. If the file does not exist, an empty menu configuration is created, but is not written to disk (see the write() method). If new_conf is True, the file's contents are not loaded; instead, an empty menu configuration is created (but not written yet). The following Exceptions may be generated: BootmgmtConfigReadError -- If there's a problem reading config file. N(R R-R t _filenameR/tlast_written_patht entry_listRt_dirtyt ConfigParsertRawConfigParsert _cfgparsert _meta_optionstglobal_optionst_load(Rtfilenametnew_conf((s0../../common/bootmgmt/backend/loader/menuconf.pyR ïs       cCs§|s|jdƒdS|jd|ƒy|jjt|ƒƒWnHtk r‹}|jtjkry|jd|ƒdStd|ƒ‚nX|jƒ|j j ƒdS(sôAttempt to load the file specified. If it does not exist, proceed with an empty SafeConfigParser. The following Exceptions may be generated: BootmgmtConfigReadError -- If there's a problem reading config file. s7No filename specified -- not loading menu configurationNsLoading menu.conf from %ss[IGNORED] %s not founds1Error trying to read the menu configuration file ( R&RNtreadfptopentIOErrorterrnotENOENTRt_load_sectionsRJtsort(RRRtioerr((s0../../common/bootmgmt/backend/loader/menuconf.pyRQs   cCs.x'|jjƒD]}|jtjƒ}d}t|ƒdkr©yB|djƒt|dƒf}t |||jj |ƒƒ}Wqýt k r¥|j d|ƒqýXnT|dkrÓt |jj dƒƒ|_n*|dkrýt |jj dƒƒ|_n|r|j d|ƒ|jj|ƒqqWdS( s²Creates MenuConfigEntry objects from the ConfigParser's section list and adds them to the entry list. Also loads the meta and global sections, if found. iiis'Malformed section name: "%s"-- ignoringtmetatglobalsAdding entry to list: %sN(RNtsectionsR1R-R.R/RtstripR2RRR*R&R#RORPRJR(Rtsectt section_splitt new_entry((s0../../common/bootmgmt/backend/loader/menuconf.pyRYs&      cCs|jS(s:Returns the state of the internal dirty variable. (RK(R((s0../../common/bootmgmt/backend/loader/menuconf.pyR?scCs/|j|kr+|jd|ƒ||_ndS(s‹Sets the state of the internal dirty variable. Emits a debug message if the state of the internal dirty variable changed. s dirty => %sN(RKR&(Rtval((s0../../common/bootmgmt/backend/loader/menuconf.pyREscCs|jS(sYReturns the filename of the menu.conf that this object was created with. (RH(R((s0../../common/bootmgmt/backend/loader/menuconf.pyRROscCsN|j|ƒ}t|||ƒ}|jj|ƒt|_|jd|ƒ|S(sóAdd an entry to the menu configuration file. The section_name parameter is used to derive the section name. If the propdict is not None, it contains the properties used to initialize the new menu entry. sAdded new entry: %s(tgen_new_sectionRRJRRRR&(Rt section_nametpropdictt new_sectiontnewent((s0../../common/bootmgmt/backend/loader/menuconf.pyt add_entryWs  cs#|jd‡fd†dtƒdS(sKDelete an entry by matching the object address to one in the list. tcmp_fncs ˆ|kS(N((tx(tentry(s0../../common/bootmgmt/backend/loader/menuconf.pytkst match_allN(tdelete_entriesR(RRl((Rls0../../common/bootmgmt/backend/loader/menuconf.pyt delete_entryhsc CsL|r¾t|jƒ}|rIg|jD]}||ƒs%|^q%|_n7|r€g|jD]}||jkrY|^qY|_n|t|jƒ}|jd|ƒ|dkrHt|_qHnŠd}xt|jƒD]p\}}|rù||jdks|rÔ|||ƒrÔ|jdt|jƒƒ|j|=t|_d}PqÔqÔW|S(sDeletes one or more menu configuration entries. Entries are found based by either matching the section_name argument (if cmp_fn is None) or by invoking cmp_fn for each entry in the entry list. If cmp_fn returns True, that entry is deleted. cmp_fn takes 1 argument-- the entry instance to consider for deletion). If match_all is True, then all entries that match are deleted; otherwise, only the first match is deleted. Returns a count of the number of deleted entries. sDeleted %d entr(y|ies)isDeleting entry %si( RRJReR&RRt enumerateRR'( RReRjRntorig_lenRktcountR6Rl((s0../../common/bootmgmt/backend/loader/menuconf.pyRoms* .!   cCsN|jj|ƒ}|rJ|jdƒ}g|D]}|jƒ^q.}|SdS(s%CDS = comma-delimited string t,N(ROR(R1R_R/(Rtpropnamet stringlisttlist_of_stringsRk((s0../../common/bootmgmt/backend/loader/menuconf.pyt_get_meta_cds_list•s cCs|r{dj|ƒ}||jks7|j||kr{|jd||jj|dƒ|fƒ||j|s   " Ÿ