
    /I_/7                         S SK r S SKr S SKJr  S SKJrJr   " S S\R                  5      r " S S5      rg! \\4 a    S SK	Jr  S SK
JrJr   N8f = f)    N)utils)ArgvParseErrorArgvParseHelpc                       \ rS rSrSS jrSrg)VersionAction   Nc                 :    [         R                  " [         R                  SS/5      nU(       d  [        S5      eUR	                  S5      nU(       d  [        S5      eU HV  nSU;   d  M  UR	                  5       n[
        R                  R                  SUS   -  5        [
        R                  " S5        MX     [        S5      e! [         aK  n[
        R                  R                  S	[        U5      -  5        [
        R                  " S
5         S nAg S nAff = f)N-l	ifupdown2z(dpkg -l ifupdown2 returns without output
zifupdown2:%s
   r   z)ifupdown2 package not found using dpkg -lz1error: cannot get current version using dpkg: %s
   )r   exec_commandldpkg_cmd	Exceptionsplitsysstdoutwriteexitstderrstr)	selfparser	namespacevaluesoption_stringdpkglineinfoes	            %/usr/share/ifupdown2/ifupdown/argv.py__call__VersionAction.__call__   s    	&&k'JKD JKK::d#D JKK$&::<DJJ$$%5a%ABHHQK  GHH 	JJQTWXYTZZ[HHQKK	s    A%C +AC 
DADD N)__name__
__module____qualname____firstlineno__r#   __static_attributes__r%       r"   r   r      s    r,   r   c                   d    \ rS rSrSSSSS.rS rS rS	 rS
 rS r	S r
S rS rS rS rS rSrg)Parse0   updownreloadquery)ifupifdownifreloadifqueryc                    US   U l         U R                  5       U l        USS  U l        U R                  S:X  a  SnOU R                  S:X  a  SnOSn[        R
                  " US9nU R                  S:X  a  U R                  U5        OvU R                  U5        U R                  S	:X  a  U R                  U5        OCU R                  S
:X  a  U R                  U5        O!U R                  S:X  a  U R                  U5        U R                  U5         UR                  U R                  5      U l        g ! [         a  nS H  nXQ;   d  M
  [        5       e   e S nAff = f)Nr   r   r3   z(query interfaces (all or interface list)r2   zreload interface configuration.zinterface management)descriptionr0   r1   )z-hz--help)executable_nameget_opopargvargparseArgumentParserupdate_ifreload_argparserupdate_argparserupdate_ifup_argparserupdate_ifdown_argparserupdate_ifquery_argparserupdate_common_argparser
parse_argsargs
SystemExitr   )r   r=   descr	argparserr!   help_strs         r"   __init__Parse.__init__8   s,   #Aw++-H	77g>EWW 5E*E++>	77h**95!!),ww$**95F",,Y7G#--i8$$Y/
	!,,TYY7DI 	
 -#'/) - 	s    D1 1
E;EEEc                 H   U R                   S:X  a7  U R                  R                  (       d  U R                  R                  (       a  gU R                   S:X  a]  U R                  R                  (       dA  U R                  R
                  (       d&  U R                  R                  (       d  [        S5      eO\U R                  R                  (       dA  U R                  R                  (       d&  U R                  R                  (       d  [        S5      eU R                  R                  (       a&  U R                  R                  (       a  [        S5      eU R                   S:w  aA  U R                  R                  (       a&  U R                  R                  (       a  [        S5      eg)Nr3   Tr2   z+'-a' or '-c' or '-allow' option is requiredz*'-a' option or interface list are requiredz5'-a' option and interface list are mutually exclusivez0'--allow' option is mutually exclusive with '-a')	r<   rG   
syntaxhelplistallcurrentlyupCLASSr   iflistr   s    r"   validateParse.validate\   s    77g499#7#7499>>77h99==)>)>tyy$%RSS!!$))--		 !MNN99		 !XYY77h499??tyy}} !STTr,   c           
          U R                   R                  5        H)  u  pU R                  R                  U5      (       d  M'  Us  $    [	        SSR                  [        U R                   R                  5       5      5      -  5      e! [         a?    [	        SSR                  [        U R                   R                  5       5      5      -  5      ef = f)Nz%Unexpected executable. Should be '%s'z' or ')		valid_opsitemsr:   endswithr   joinrP   keysr   )r   keyvalues      r"   r;   Parse.get_opm   s    	w"nn224
''0055 L 5 !!H8==Y]^b^l^l^q^q^sYtKu!uvv 	w !H8==Y]^b^l^l^q^q^sYtKu!uvv	ws   =B B A B A	Cc                     U R                   $ r&   )rG   rU   s    r"   get_argsParse.get_argsv   s    yyr,   c           	      J   UR                  SSSSSS9  UR                  SSS	S
S9  UR                  SSSSSS9  UR                  SSSSSS9  UR                  SSSS[        R                  S9  UR                  SSSSS9  UR                  SSSSSS9  UR                  SS S[        R                  S9  UR                  S!S"S[        R                  S9  UR                  S#S$S%SS&S9  UR                  S'S(S)S*S+S,9  UR                  S-S.S/S0S0S1/S2S39  UR                  S4S5S6S*S7S8/S9S39  g*):z$base parser, common to all commands -a--all
store_trueF$process all interfaces marked "auto")actionrequiredhelprT   IFACE*zTinterface list separated by spaces. IFACE list is mutually exclusive with -a option.metavarnargsrk   -v	--verboseverbosedestri   rk   -d--debugdebugoutput debug infoz-qz--quietquiet--allowrS   append#ignore non-"allow-CLASS" interfaces-w--with-dependswithdependszrun with all dependent interfaces. This option is redundant when '-a' is specified. With '-a' interfaces are always executed in dependency order
--perfmodeperfmode	--nocachenocache-X	--excludeexcludepatsz^Exclude interfaces from the list of interfaces to operate on. Can be specified multiple times.z-iz--interfacesinterfacesfileNzFSpecify interfaces file instead of file defined in ifupdown2.conf file)ru   defaultrk   z-tz--interfaces-formatinterfacesfileformatnativejsonzinterfaces file formatru   r   choicesrk   z-Tz--typetypeifacevlanztype of interface entry (iface or vlan). This option can be used in case of ambiguity between a vlan interface and an iface interface of the same name)add_argumentr>   SUPPRESSr   rJ   s     r"   rA   Parse.update_argparsery   s   tW\E$J 	 	Lx%W 	 	X 	t[y\eftYW\XkltYW\X`XiXijywxNstt%5MR^%c 	 	d 	|*\X`XiXij{<V^VgVght[}X%G 	 	H 	t^:JTX$l 	 	nt%:AWai(0&'9@X 	 	ZtXFDSZ\bRc%_ 	 	`r,   c                     UR                  SSSSSS9  UR                  SSS	SS
9  UR                  SS9nUR                  SSSSSS9  UR                  SSSSS/SS9  UR                  SSSSSS9  g)z&common arg parser for ifup and ifdown -f--forceforcerg   force run all operationsrt   r
   --syslogsyslogru   ri   Frj   -n--no-actnoact,print out what would happen, but don't do it-p--print-dependencyprintdependencyrP   dotzprint iface dependencyru   r   rk   z--no-scriptsz--admin-statenoaddonszUdont run any addon modules/scripts. Only bring the interface administratively up/downN)r   add_mutually_exclusive_groupr   rJ   groups      r"   update_ifupdown_argparserParse.update_ifupdown_argparser   s    tYW\XrstZh|T666F4', N 	 	P4!5<M$*E?9Q 	 	S>?T` w 	 	yr,   c                 r    UR                  SSSSSS9  UR                  SSS	SS
S9  U R                  U5        g )N-s--syntax-checksyntaxcheckrg   #Only run the interfaces file parserrt   z-kz--skip-upperifacesskipupperifacesa  ifup by default tries to add newly created interfaces into its upper/parent interfaces. Eg. if a bridge port is created as a result of ifup on the port, ifup automatically adds the port to the bridge. This option can be used to disable this default behaviour)r   r   r   s     r"   rB   Parse.update_ifup_argparser   sX    t%5M&29^ 	 	`t%9@QZf%E 	 	F
 	&&y1r,   c                 L    U R                  U5        UR                  SSSSSS9  g )N-u--use-current-configusecurrentconfigrg   zBy default ifdown looks at the saved state for interfaces to bring down. This option allows ifdown to look at the current interfaces file. Useful when your state file is corrupted or you want down to use the latest from the interfaces filert   )r   r   r   s     r"   rC   Parse.update_ifdown_argparser   s4    &&y1t%;$6|%J 	 	Kr,   c           	         UR                  SSSSSS9  UR                  SS9nUR                  S	S
SSSS9  UR                  SSSSSS9  UR                  SSSSSS9  UR                  SSS[        R                  S9  UR                  SSSSSS/SS9  UR                  SS S!SS"/S#S$9  UR                  S%S&SS'S(S9  UR                  S)SS*S+S9  g,)-zarg parser for ifquery options r
   z--listrg   rP   z"list all matching known interfaces)ri   ru   rk   Fr   z-rz	--runningrunningz#query running state of an interfacert   -cz--check	checkcurrzCcheck interface file contents against running state of an interfacez-xz--rawrawzprint raw config file entriesz--print-savedstateprintsavedstatez-oz--formatformatr   r   zinterface display formatr   r   r   r   r   zprint interface dependencyr   r   z--syntax-helprO   z'print supported interface config syntaxz--with-defaultswithdefaultszfcheck policy default file contents, for unconfigured attributes, against running state of an interfaceN)r   r   r>   r   r   s      r"   rD   Parse.update_ifquery_argparser   s<    	tXl$H 	 	J666F49\ E 	 	G4\ e 	 	g4EPop/K\ckctctutZh(0&'9@Z 	 	\t%9@Q(.=Y 	 	[t_\P\$M 	 	O0N%L 	 	Mr,   c                    UR                  SS9nUR                  SSSSS9  UR                  SS	S
SSS9  UR                  SSSSS9  UR                  SSS[        R                  S9  UR                  SSSSSS9  UR                  SSSSSS9  UR                  SSSSSS9  UR                  S S!S"S[        R                  S9  UR                  S#S$S[        R                  S9  UR                  S%S&S[        R                  S9  UR                  S'S(S)S[        R                  S9  UR                  S*S+S,SS-S9  UR                  S.S/S0SS19  UR                  S2S3S4SS5S9  UR                  S6S7S8SS9S9  g:);zparser for ifreload Tr   re   rf   rg   rh   )ri   rk   r   z--currently-uprR   zReload the configuration for all interfaces which are currently up regardless of whether an interface has "auto <interface>" configuration within the /etc/network/interfaces file.rt   r{   rS   r|   r}   rT   rl   rm   rn   r   r   r   r   rq   rr   rs   rv   rw   rx   ry   r~   r   r   r   r   r   r   r   r   r   r   r   r   zBy default ifreload looks at saved state for interfaces to bring down. With this option ifreload will only look at the current interfaces file. Useful when your state file is corrupted or you want down to use the latest from the interfaces filer
   r   r   r   r   r   r   r   r   r   r   r   N)r   r   r>   r   r   s      r"   r@   Parse.update_ifreload_argparser   s   666E4Djk4!1l!l 	 	m 	978Jopx(J[J[\tZgl$S 	 	Ut[y\eftYW\Xklt%5MR^emevevw|*\X`XiXij{<V^VgVght[}X\d\m\mn 	t%;BT]i%? 	 	@
 	tZh|TtYW\Xrst%5MR^$I 	 	Kr,   c                 V    UR                  SS[        SS9  UR                  SSSSS	S
9  g)zgeneral parsing rules z-Vz	--versionr   )ri   rp   z	--nldebugnldebugrg   Fzprint netlink debug messages)ru   ri   r   rk   N)r   r   r   s     r"   rE   Parse.update_common_argparser   s=     	t[aP/ 	 	
r,   )rG   r=   r:   r<   N)r'   r(   r)   r*   rY   rL   rV   r;   rb   rA   r   rB   rC   rD   r@   rE   r+   r%   r,   r"   r.   r.   0   sT    	I"H"w`:
y2KM. KD

r,   r.   )r   r>   ifupdown2.ifupdown.utilsr   ifupdown2.ifupdown.exceptionsr   r   ImportErrorModuleNotFoundErrorifupdown.utilsifupdown.exceptionsActionr   r.   r%   r,   r"   <module>r      sX     B.KHOO 8H
 H
C 	() B$AABs   8 AA