
    =	fa                     z	   d Z dZdZdZddlZddlZddlZddl ddlm	Z	m
Z
mZ ddlmZ 	 dd	lmZ  G d dej,                        Z ej0                  eee edeefeeef      Zej?                  ej@                         ejC                  d      \  Z"Z#Z$Z%Z&Z'e&dk(  r( e	jP                         s>ejS                  dez         eZ%n' e	jT                         sejS                  dez         eZ%e%ek(  re&dk(  rejW                  d       	 ddl, ddl-m.Z. dZ1dZ2 e3e/jh                        Z1e'Pe5jm                  ddd      Z'e'jo                         dk(  r* e8e9ju                               Z'ej'                  de'z         e'jo                         dk7  rdZ	 e'jw                  d      \  Z<Z=dj}                  e<eg      Z'ej'                  de'z          e@d      ZAde<z  ZBej'                  deBz         eAj                  eBeDj                        ZFeFre1j                  eA       ndZ'e'dk(  rej'                  d        n^ej'                  d!e'z         eHj                   eHe'             e'eD_:        	 e:j                  e:j                  e:j                  e'              e.       Z2e2j                          e1j                  e2       	 ej'                  d"       e1j                          e/ja                  d       y e	j                  e&      \  Z3ZS eeSd#z         ZTejW                  d$       	  e3e/jh                        Z1eTj                  d      ZVeVj                          	 ej'                  d"       e1j                          y	 dd%lXmXZX  e       ZY	 eYj                          ej                  d(       ej                  d)       y# e$ r"Zej'                  e       dd
lmZ Y dZ[dZ[ww xY w# e$ r& ejS                  d       e/ja                  d       Y w xY w# e?$ r e'Z<dj}                  e'eg      Z'Y ww xY w# e:j                  $ r Y w xY w# eQ$ r Y sw xY w# eQ$ r e/ja                  d       Y yw xY w# e$ r& ejS                  d&       e/ja                  d       Y w xY w# eQ$ r ejS                  d'       Y !w xY w)*z6.0zFax Address Bookzhp-fabz$A simple fax address book for HPLIP.    N)*)utilstuimodule)input)import_module)dyn_import_modc                       e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd ZddZddZd ZeZd Zd Zd ZeZd ZeZd ZeZd ZeZd Zd ZeZd Z e Z!d Z"e"Z#d Z$d Z%y)Consolec                     t         j                  j                  |        d| _        t	        j
                         | _        t        j                  d      | _	        y )NzBType 'help' for a list of commands. Type 'exit' or 'quit' to quit.z	hp-fab > )
cmdCmd__init__introfaxFaxAddressBookdblogboldpromptselfs    /usr/share/hplip/fab.pyr   zConsole.__init__6   s;    Z
%%'hh{+    c                 .    t        | j                         y)z/Print a list of commands that have been enteredN)print_histr   argss     r   do_histzConsole.do_hist=   s    djjr   c                      yzExits from the console r   s     r   do_exitzConsole.do_exitA       r   c                      yr"   r$   r   s     r   do_quitzConsole.do_quitE   r&   r   c                 $    | j                  |      S )z$Exit on system end of file character)r%   r   s     r   do_EOFzConsole.do_EOFJ   s    ||D!!r   c                 D    t         j                  j                  | |       y)zGet help on commands
           'help' or '?' with no arguments prints a list of commands for which help is available
           'help <command>' or '? <command>' gives help on <command>
        N)r   r   do_helpr   s     r   r,   zConsole.do_helpN   s     	d#r   c                     t         j                  j                  |        g | _        i | _        i | _        | j                  d       y)zInitialization before prompting user for commands.
           Despite the claims in the Cmd documentaion, Cmd.preloop() is not a stub.
         N)r   r   preloopr   _locals_globalsdo_listr   s    r   r/   zConsole.preloopW   s5     	
Rr   c                 X    t         j                  j                  |        t        d       y)zTake care of any unfinished business.
           Despite the claims in the Cmd documentaion, Cmd.postloop() is not a stub.
        z
Exiting...N)r   r   postloopr   r   s    r   r4   zConsole.postloopb   s     	lr   c                 N    | xj                   |j                         gz  c_         |S )z This method is called after the line has been input but before
            it has been interpreted. If you want to modifdy the input line
            before execution (for example, variable substitution) do it here.
        )r   stripr   lines     r   precmdzConsole.precmdi   s    
 	

tzz|n$
r   c                     |S )zIf you want to stop the console, return something that evaluates to true.
           If you want to do some post command processing, do it here.
        r$   )r   stopr8   s      r   postcmdzConsole.postcmdq   s	     r   c                      y)zDo nothing on empty input lineNr$   r   s    r   	emptylinezConsole.emptylinew   s    r   c                 .    t         j                  d       y )Nz2Unrecognized command. Use 'help' to list commands.)r   errorr7   s     r   defaultzConsole.default{   s    		FGr   c                    |s	 |r-t        t        j                  d            j                         }n,t        t        j                  d            j                         }|j	                         dk(  rt        t        j                  d             y|s|ryt        j                  d       |r1| j                  j                  |      Ht        j                  d       | j                  j                  |      t        j                  d       	 |S |j                         }|r3| j                  j                  |      t        j                  d       y|S | j                  j                  |      t        j                  d       y|S )	Nz?Enter the name to add to the group (<enter>=done*, c=cancel) ? zEnter name (c=cancel) ? cCanceledr.   zName must not be blank.z4Name already exists. Please choose a different name.z.Name not found. Please enter a different name.)
r   r   r   r6   lowerr   redr@   r   get)r   r   fail_if_matchalt_textnicknames        r   get_nicknamezConsole.get_nickname~   s<   $SXX.o%pqwwyH$SXX.H%IJPPRH>>#s*#''*-.!		";<  !ww{{8,8		"XY  ww{{8,4		"RS   zz|H77;;x(4IITU 	 77;;x(0IINOr   c                    | j                   j                         }|s	 |r-t        t        j	                  d            j                         }n,t        t        j	                  d            j                         }|j                         dk(  rt        t        j                  d             y|s|ryt        j                  d       |dk(  rt        d       y|r||v r0t        j                  d	       ||vrt        j                  d
       	 |S |j                         }|r||v rt        j                  d	       y|S ||vrt        j                  d
       y|S )Nz4Enter the group to join (<enter>=done*, c=cancel) ? zEnter the group (c=cancel) ? rC   rD   r.   z!The group name must not be blank.Allz<Cannot specify group 'All'. Please choose a different group.z6Group already exists. Please choose a different group.z0Group not found. Please enter a different group.)
r   get_all_groupsr   r   r   r6   rE   r   rF   r@   )r   r   rH   rI   
all_groups	groupnames         r   get_groupnamezConsole.get_groupname   s9   WW++-
 %chh/e&f g m m oI %chh/N&O P V V XI ??$+#''*-. !		"EF %XY  J.		"Z[  !
2		"TU   

I
*IIVW 	 J.IIPQr   c                    |rg|j                         j                         d   }|j                  d      r| j                  d       y|j                  d      r| j	                  d       y| j                  d       | j	                  d       y)zl
        List names and/or groups.
        list [names|groups|all|]
        dir [names|groups|all|]
        r   namr.   Ngro)r6   split
startswithdo_names	do_groups)r   r   scopes      r   r2   zConsole.do_list   sn     JJL&&(+Eu%b!'r"brr   c           
         | j                   j                         }t        j                  |       t	        t        j                  d             t        |      dkD  rt        j                         }d|_	        t        |j                               D ]D  \  }}|j                  d      r|j                  ||d   |d   dj                  |d         f       F |j                          t	                y
t	        d	       t	                y
)z+
        List names.
        names
        z
Names:
r   )Namez
Fax NumberNotesMember of Group(s)__r   notes, groups(None)Nr   get_all_recordsr   debugr   r   lenr   	FormatterheaderlistitemsrV   addjoinoutputr   r   all_entriesfnamees         r   rW   zConsole.do_names   s    
 gg--/		+chh|$%{aALAH 1 1 34 Pat,EE451W:tyy87MNOP HHJ
 	 (Or   c                    | j                   j                         }t        j                  |       t	        t        j                  d             t        |      rt        j                         }d|_	        |D ]]  }|j                  |dj                  | j                   j                  |      D cg c]  }|j                  d      r| c}      f       _ |j                          t	                yt	        d       t	                yc c}w )z-
        List groups.
        groups
        z	
Groups:
)GroupMembersr`   r^   rb   N)r   rN   r   re   r   r   rf   r   rg   rh   rk   rl   group_membersrV   rm   )r   r   rO   rp   groupxs         r   rX   zConsole.do_groups  s    
 WW++-
		*chh}%&z?A+AH# oudiiDGG4I4I%4P(kqXYXdXdeiXj(klmnoHHJ
 	 (O )ls   -DDc           	      \   | j                  |d      }|sy| j                  j                  |      }t        j	                  |       t        t        j                  d|z               d}d}d}|d   }	 t        t        j                  d|z              j                         }|j                         d	k(  rt        t        j                  d
             y|s|st        j                  d       ||s|}d}	|D ]  }
|
dvst        j                  d       d}	 n |	rn|d   }t        t        j                  d|z              j                         }|j                         d	k(  rt        t        j                  d
             y|s|}|d   rt        d       g }|d   D ][  }|dk(  r	t        j                  d|z  d      \  }	}|	s t        t        j                  d
              y|sK|j                  |       ] t        d       	 | j                  ddd      }|j                         d	k(  rt        t        j                  d
             y|sn| j                  j!                         }||vrSt        j#                  d       t        j                  dd      \  }	}|	st        t        j                  d
             y|s||d   v rt        j                  d       |j                  |       | j                  j%                  |||||||       | j'                  |       t                y)zI
        Edit an name.
        edit [name]
        modify [name]
        FrH   Nz!
Edit/modify information for %s:
r.   r   Tz&Fax Number (<enter>='%s', c=cancel) ? rC   rD   Fax number must not be empty.0123456789-(+) *#zOInvalid characters in fax number. Fax number may only contain '0123456789-(+) 'r_   z!Notes (<enter>='%s', c=cancel) ? ra   z
Leave or Stay in a Group:
rM   zStay in group %s *(y=yes* (stay), n=no (leave), c=cancel) ? choice_promptz
Join New Group(s):
rH   rI   Group not found.zIs this a new groupz!(y=yes* (new), n=no, c=cancel) ? TGroup already specified. Choose a different group name or press <enter> to continue.)rK   r   rG   r   re   r   r   r   r6   rE   rF   r@   r   enter_yes_noappendrQ   rN   warnsetdo_show)r   r   rJ   rr   lastname	firstnametitlesave_faxnumfaxnumokrC   
save_notesr_   
new_groupsgans	add_grouprO   s                     r   do_editzConsole.do_edit)  s    $$T$?GGKK!		!chh<xGHI@ 	h388$L{$Z[\bbdF||~$cggj)*+		9:$B //IIopB	 5- 0 wZ
chhBZOPQWWY;;=C#''*%&EX;12
8 	%AEz&&':Q'>JLGB cggj)*!!!$	% 	&'**2UT*RI C'cggj)*//1J
*+,**+@"EGC #''*-.AhK'		pqi(9 < 	HeY&*eTXr   c                    | j                  |d      }|sy| j                  j                  |      }g }t        d       |D ]h  }|j	                  d      st        j                  d|z  d      \  }}n3|s t        t        j                  d	              y|sX|j                  |       j t        d
       	 | j                  ddd      }|j                         dk(  rt        t        j                  d	             y|j                         sn|j                  |       i| j                  j                  ||       t                y)zQ
        Edit a group.
        editgrp [group]
        modifygrp [group]
        Frz   Nz
Existing Names in Group:
r^   zShould '%s' stay in this group r}   r~   rD   z
Add New Names to Group:
Tr.   r   rC   )rQ   r   rv   r   rV   r   r   r   rF   r   rK   rE   update_groups)	r   r   rw   old_entriesnew_entriesrr   r   r   rJ   s	            r   
do_editgrpzConsole.do_editgrp  s+    ""4u"=fgg++E2,- 	&A<<%**+Lq+P"NPC cggj)*""1%	& 	+,((54(PH~~3&cggj)*>>#x(  	e[1r   c           	         | j                  |d      }|syt        t        j                  d|z               d}d}d}	 t	        t        j                  d            j                         }|j                         dk(  rt        t        j                  d             y|st        j                  d	       wd}|D ]  }|d
vst        j                  d       d} n |rnt	        t        j                  d            j                         }	|	j                         j                         dk(  rt        t        j                  d             yg }
| j                  j                         }	 t	        t        j                  d            j                         }|j                         dk(  rt        t        j                  d             y|sn|dk(  rt        t        j                  d             ||vrqt        j                  d       	 t	        t        j                  d            j                         j                         }|dvrt        j                  d       U	 |dk(  r||
v rt        j                  d       |
j                  |       (|
j                  d       | j                  j                  ||||||
|	       | j                  |       y)zD
        Add an name.
        add [name]
        new [name]
        Trz   Nz
Enter information for %s:
r.   zFax Number (c=cancel) ? rC   rD   r{   r|   zQInvalid characters in fax number. Fax number may only contain '0123456789-(+) *#'FzNotes (c=cancel) ? z,Member of group (<enter>=done*, c=cancel) ? rM   zCannot specify 'All'.r   z%Is this a new group (y=yes*, n=no) ? )r.   nyz1Please enter 'y', 'n' or press <enter> for 'yes'.r   r   )rK   r   r   r   r   r6   rE   rF   r@   r   rN   r   r   r   r   )r   r   rJ   r   r   r   r   r   rC   r_   ra   rO   r   
user_inputs                 r   do_addzConsole.do_add  se    $$T$>chh6ABC( 	388$>?@FFHF||~$cggj)*		9:B //IIqrB	 5' * chh456<<>;;= C'#''*%&WW++-
chh'UWX^^`I C'cggj)*E!cgg567
*+,!&sxx0W'X!Y!_!_!a!g!g!iJ!7		"UV $F"		pqMM)$C F 	eHeY&&%PXr   c                 T   | j                  |d      }|syg }	 | j                  ddd      }|j                         dk(  rt        t        j                  d             y|j                         sn|j                  |       i| j                  j                  ||       t                y)	zL
        Add a group.
        addgrp [group]
        newgrp [group]
        Trz   Nr.   Fr   rC   rD   )	rQ   rK   rE   r   r   rF   r   r   r   )r   r   rw   entriesrJ   s        r   	do_addgrpzConsole.do_addgrpR  s     ""4t"<f((54(PH~~3&cggj)*>>#NN8$  	eW-r   c           
         | j                   j                         }t        j                  |       t	        t        j                  d             t        |      dkD  rt        j                         }d|_	        t        |j                               D ]D  \  }}|j                  d      r|j                  ||d   |d   dj                  |d         f       F |j                          t	                y	)
z2
        View all name data.
        view
        z
View all Data:
r   )r[   Faxr\   r]   r^   r   r_   r`   ra   Nrc   rn   s         r   do_viewzConsole.do_viewo  s    
 gg--/		+chh+,-{aAEAH 1 1 34 Pat,EE451W:tyy87MNOP HHJr   c                    | j                  |d      }|sy| j                  j                  |      }|rt        j                         }d|_        |j                  d|f       |j                  d|d   f       |j                  d|d	   f       |j                  d
dj                  |d         f       |j                          t                yt        j                  d       t                y)zW
        Show a name (all details).
        show [name]
        details [name]
        Frz   N)KeyValuezName:zFax Number:r   zNotes:r_   zMember of Group(s):r`   ra   z:Name not found. Use the 'names' command to view all names.)rK   r   rG   r   rg   rh   rk   rl   rm   r   r@   r   )r   r   rq   rr   rp   s        r   r   zConsole.do_show  s       U ;VGGKKA'AHEE7D/" EE=!E(+,EE8QwZ()EE($))AhK*@ABHHJ
 	 IIRSr   c                 z    | j                  |d      }|sy| j                  j                  |       t                y)zE
        Remove a name.
        rm [name]
        del [name]
        Frz   N)rK   r   deleter   )r   r   rJ   s      r   do_rmzConsole.do_rm  s3     $$T$?x r   c                 z    | j                  |d      }|sy| j                  j                  |       t                y)zN
        Remove a group.
        rmgrp [group]
        delgrp [group]
        Frz   N)rQ   r   delete_groupr   )r   r   rw   s      r   do_rmgrpzConsole.do_rmgrp  s5     ""4u"=fU#r   c                 @    t        j                  t        t               y)z
About fab.N)r   	log_title	__title____version__r   s     r   do_aboutzConsole.do_about  s    	;/r   c                    |j                         j                         }|st        j                  d       y|d   }t	        |      dkD  r|d   j                         }nd}|dvrt        j                  d|z         yt        j                  j                  |      st        j                  d|z         y|dk(  rrt        j                  j                  |      d   j                         }|d	k(  rd
}n:|dk(  rd}n2t        |d      j                  d      j                         }d|v rd
}nd}|dk(  r-t        d|z         | j                  j                  |      \  }}n0|dv r,t        d|z         | j                  j                  |      \  }}s t        j                         t                y| j!                  d       t                y)z]
        Import LDIF
        import <filename> [type]
        [type] = vcf|ldif|auto
        z+You must specify a filename to import from.Nr      auto)r   ldifvcfvcardzInvalid type: %szFile %s not found.z.vcfr   z.ldifr   ri   zbegin:vcardzImporting from LDIF file %s...)r   r   zImporting from VCF file %s...r.   )r6   rU   r   r@   rf   rE   ospathexistssplitextopenreadr   r   import_ldifimport_vcardr2   )r   r   filenametypextheadr   	error_strs           r   	do_importzConsole.do_import  s    zz|!!#IICD7t9q=q'--/CC66II(3./ww~~h'II*X56&=''""8,Q/557Cf}Hc*//5;;= D(C C&=2X=> GG//9MB	$$1H<= GG00:MB	IIi  	 LLr   N)TF)&__name__
__module____qualname__r   r    r%   r(   r*   r,   r/   r4   r9   r<   r>   rA   rK   rQ   r2   do_dirrW   rX   r   	do_modifyr   do_modifygrpr   do_newr   	do_newgrpr   r   
do_detailsr   do_delr   	do_delgrpr   r   r$   r   r   r   r   4   s    ,
"$	H-`3j* F0.HT I-^ LdN F4 I08 J F I05r   r   F)handle_device_printerqt3zU%s GUI mode requires GUI support (try running with --qt4). Entering interactive mode.zU%s GUI mode requires GUI support (try running with --qt3). Entering interactive mode.zhp-fab(qt3))FaxAddrBookFormz,Unable to load Qt3 support. Is it installed?r   uilocsystemzUsing system locale: %srC   utf8.z&Trying to load .qm file for %s locale.zhplip_%s.qmzName of .qm file: %szUsing default 'C' localezUsing locale: %szStarting GUI loop...z
.fabwindowzhp-fab(qt4))r   z1Fax address book disabled - Python 2.3+ required.z
User exit.r.   zDone.)\r   r   __mod____doc__r   getoptr   base.gbaser   r   r   base.sixext.movesr   	importlibr   ImportErrorrr   r   re   
base.utilsr	   r   r   ModuleGUI_MODEINTERACTIVE_MODEUI_TOOLKIT_QT3UI_TOOLKIT_QT4UI_TOOLKIT_QT5modsetUsageUSAGE_FLAG_NONEparseStdOptsopts
device_uriprinter_namemode
ui_toolkitr   canEnterGUIModer@   canEnterGUIMode4
set_moduleqtui.faxaddrbookformr   sysexitappaddrbookQApplicationargv	user_confrG   rE   str
QTextCodeclocalerU   lrx   rl   
ValueErrorQTranslatortransqm_fileloadproplocalization_dirloadedinstallTranslatorQLocale
setDefault	setlocaleLC_ALL	normalizeErrorshowsetMainWidget	exec_loopKeyboardInterruptimport_dialog
ui_packager   	FABWindowfabexec_r   consolecmdloopinfor$   r   r   <module>r     s  . 	

0   	  # # #;'Icgg I\ fmmGYWd/0#^^DF V## $ 51 6j,j#  5  "		ilsst!5!!#		ilsst 8U}%	:
 388$;--eX6Cyy{h&*++-.		3c9:99;#A)yy~1hh1v&
 II>DE%E#a'GII,w67ZZ)>)>?F%%e,#:II01II(3./ws|,DK  0@0@0EF #$(#	II,-MMO 	 $75#6#6z#B j:45 	}%sxx(C,,t$CHHJ		01		 iG  HHRLHHWe  ;IIaL::;d  	IIDEHHQK	(  )hhQx()0 <<  ! 		* %   		EF   		, s   N; 	O% 'P *+P4 >!Q
 !Q :Q2 R  ;O" OO"%'PPP10P14QQ
QQQ/.Q/2'RR R:9R: