• File: get_attachment.pyo
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/lib/python2.7/site-packages/redhat_support_tool/plugins/get_attachment.pyo
  • Date Modified: 03/28/2024 3:28 PM
  • File size: 12.68 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit

fc@sddlmZddlmZmZddlmZmZddlm	Z	ddl
Z
ddlZddlZddl
jjZddljjZddlZddlZdZejdZde	fd	YZdS(
i(tOption(tRequestErrortConnectionError(tEmptyValueErrort_(tPluginNs&Spenser Shumaker <sshumake@redhat.com>s*redhat_support_tool.plugins.get_attachmentt
GetAttachmentcBseZdZejdZedZedZedZ	edZ
dZdZdZ
d	Zd
ZdZdZdddd
ZRS(t
getattachments ^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$cCs
tdS(s
        The usage statement that will be printed by OptionParser.

        Example:
            - %prog -c CASENUMBER [options] <comment text here>
        Important: %prog is a OptionParser built-in.  Use it!
        s/%prog -c CASENUMBER -u ATTACHMENTUUID [options](R(tcls((sN/usr/lib/python2.7/site-packages/redhat_support_tool/plugins/get_attachment.pyt	get_usage's	cCstd|jS(s
        The description statement that will be printed by OptionParser.

        Example:
            - 'Use the '%s' command to add a comment to a case.'             % cls.plugin_name
        s=Use the '%s' command to find a specific attachment by number.(Rtplugin_name(R((sN/usr/lib/python2.7/site-packages/redhat_support_tool/plugins/get_attachment.pytget_desc2s		cCstd|j|jfS(s
        The epilog string that will be printed by OptionParser.  Usually
        used to print an example of how to use the program.

        Example:
         Examples:
          - %s -c 12345678 Lorem ipsum dolor sit amet, consectetur adipisicing
          - %s -c 12345678
        seExamples:
- %s -c 12345678 -u AAABBBCCCDDDEEE -d ~/Downloads
- %s -c 12345678 -a -s -m -d ~/Downloads(RR
(R((sN/usr/lib/python2.7/site-packages/redhat_support_tool/plugins/get_attachment.pyt
get_epilog>scCsftdddddtddd.tdd	dd
dtddd.tdd
dddtddddttdddddtddd.tdddddtddd.tdddddtddddttdddd dtd!dddttd"d#dd$dtd%dd&d'd(dd)td*d+dd,dtd-dd.g	S(/sO
        Subclasses that need command line options should override this method
        and return an array of optparse.Option(s) to be used by the
        OptionParser.

        Example:
         return [Option("-f", "--file", action="store",
                        dest="filename", help='Some file'),
                 Option("-c", "--case",
                        action="store", dest="casenumber",
                        help='A case')]

         Would produce the following:
         Command (? for help): help mycommand

         Usage: mycommand [options]

         Use the 'mycommand' command to find a knowledge base solution by ID
         Options:
           -h, --help  show this help message and exit
           -f, --file  Some file
           -c, --case  A case
         Example:
          - mycommand -c 12345 -f abc.txt

        s-cs--casenumbertdestt
casenumberthelpsHThe case number from which the attachment will be downloaded. (required)tdefaults-us--attachmentuuidtattachmentuuids(UUID of the attachment to be downloaded.s-as--alltdownloadalls'Download all attachments for this case.tactiont
store_trues-is	--includetincludesFLimit download all attachments to those matching regex. (only with -a)s-xs	--excludetexcludesJLimit download all attachments to those NOT matching regex. (only with -a)s-ss--sortedtsortedsDSort attachment filenames according to creation date. (only with -a)s-ms
--metadatatmetadatasGSave a JSON file with metadata for the given attachment. (only with -a)s-zs	--maxsizetmaxsizes=Maximum attachment size to download, in bytes. (only with -a)tstorettypetintis-ds	--destdirtdestdirs3Destination directory the attachment will be saved.N(RRtNonetFalse(R((sN/usr/lib/python2.7/site-packages/redhat_support_tool/plugins/get_attachment.pytget_optionsNs>cCstd|j}|jdstjrttd}t|j}|dkrhtnt|jr||jd<q|GHt|q|GHt|ndS(Ns!ERROR: %s requires a case number.Rs/Please provide a case number (or 'q' to exit): tq(	RR
t_optionstcommontis_interactivet	raw_inputtstrtstript	Exception(tselftmsgtline((sN/usr/lib/python2.7/site-packages/redhat_support_tool/plugins/get_attachment.pyt_check_case_numbers	

cCs]t}|jdstjrxtrttd}t|jdkr^t	nt|j}t
jj|}t
|st
j}nt
jj|std|GHq"||jd<t}Pq"Wqt
j|jd<n|sYt
jj|jd|jd<t
jj|jdsYtd|jd}|GHt	|qYndS(NRsbPlease provide a download directory or press enter to use the current directory (or 'q' to exit): R!s%s is not a valid directory.s#ERROR: %s is not a valid directory.(RR"R#R$tTrueR%RR&R'R(tostpatht
expandusertlentcurdirtisdir(R)tbeenVerifiedR+tdestDirR*((sN/usr/lib/python2.7/site-packages/redhat_support_tool/plugins/get_attachment.pyt_check_destdirs2
	
		cCs|jdr>|jdr:td}|GHt|ndS|jdrotdd}|GHt|n|jdrtdd}|GHt|n|jdstj|j|jdrtd
|j}tjrqt	td}t
|j}|dkr&tnt
|jr]tj|j|r]||jd<q|GHt|q|GHt|nx`id
d6dd6dd6jD]=\}}|j|rtd|}|GHt|qqWdS(NRRs'ERROR: -a cannot be used with -u optionRs)ERROR: %s is only effective when using %ss-is-aRs-xswERROR: %s requires the UUID of the attachment to be downloaded.  Try listattachments to see the attachment UUID values.s7Please provide the UUID of an attachment('q' to exit): R!s-sRs-mRs-zRs)ERROR: %s is only supported when using -a(s-is-a(s-xs-a(
R"RR(tretmatcht
uuid_regexR
R#R$R%R&R'titems(R)R*R+tvaluetopt((sN/usr/lib/python2.7/site-packages/redhat_support_tool/plugins/get_attachment.pyt_check_modesD



	
'.
cCs"|j|j|jdS(N(R,R=R6(R)((sN/usr/lib/python2.7/site-packages/redhat_support_tool/plugins/get_attachment.pyt
validate_argss

cCs3|jdr|jdS|j|jddS(NRR(R"t_downloadalltdownloaduuid(R)((sN/usr/lib/python2.7/site-packages/redhat_support_tool/plugins/get_attachment.pytnon_interactive_actions

c

Csj|j}|jdd|jdt|d}d}|jdritj|jd}nd}|jdrtj|jd}nx|D]}|jrqn|d8}|j	}|j
}|r|j|rtd|GHqn|r+|j|r+td|GHqn|jd	rf|jd	|krftd
||fGHqn|jdrd||f}nt
jtjj|jd
||rqntd|G|jdr=d|d|j	f}tjj|jd
|}t|d}	|	jtj|j|	jn|j|j||d|jqWdS(NtkeycSs
|jS(N(tget_createdDate(tx((sN/usr/lib/python2.7/site-packages/redhat_support_tool/plugins/get_attachment.pyt<lambda>si
iRRs*Skipping %s (does not match include regex)s#Skipping %s (matches exclude regex)Rs)Skipping %s (%d bytes exceeds size limit)Rs%d-%sRsDownloading %s ...     Rs
%d-%s.jsontwtlink(t_listattachstsorttreverseR1RR"R7tcompiletget_isDeprecatedtget_fileNametget_sizeR8RR#tattachment_exists_locallyR.R/tjointopentwritetjsontdumpstto_dicttcloseR@tget_uuidtget_link(
R)tattachstcountRRtattachtfileNametattachmentLengthtfmetatfp((sN/usr/lib/python2.7/site-packages/redhat_support_tool/plugins/get_attachment.pyR?sN





	
(

cCsd}y'tj}|jj|jdSWntk
rs}tdt|}|GHt	j
tj|nt
k
r}td|j}|GHt	j
tj|nXtk
r
}td}|GHt|jd}|dGHt	j
tj|nXdS(NRs	ERROR: %ss?Unable to fulfill request with support services API. Reason: %ssZProblem connecting to the support services API.  Is the service accessible from this host?s, i(Rt	apihelpertget_apitattachmentstlistR"RRR&tloggertlogtloggingtWARNINGRtreasonRtsplit(R)tapiteveR*treqeterrmsgtemg((sN/usr/lib/python2.7/site-packages/redhat_support_tool/plugins/get_attachment.pyRH/s,	
	c
Csd}yJtj}|o|sd}tjd|jj|jd}x|D]}|j|krT|j	}tjd||j
}|j}tj
tjj|jd||rdStd|GtjjPqTqTWn|jjd|jdd|d|d	|d
|jdd|}tdtjj|GHWnftk
r}td
t|}	|	GHtjtj|	n#tk
r*}
td|
j}	|
jdkrtj |j!|r|	td7}	n|	GHtjtj|	|
jdkr$tj"nnt#k
r}td}	|	GHt|j$d}|dGHtjtj|	n8t%k
rtd}	|	GHtjtj|	nXdS(NsGetting attachment length ...Rs... %d bytesRsDownloading %s ...     t
caseNumbertattachmentUUIDR\R]R5RGsFile downloaded to %ss	ERROR: %ss?Unable to fulfill request with support services API. Reason: %sis-  Did you specify the UUID of the attachment?tUnauthorizedsZProblem connecting to the support services API.  Is the service accessible from this host?s, isUnable to get attachment(&RR`RaRdtdebugRbRcR"RWRNRMRXR#ROR.R/RPRtsyststdouttflushtgettrealpathRR&ReRfRgRRhtstatusR7R8R9tremove_userRRiR((
R)tuuidtfilenametlengthRGRjtall_attachmentsR[RkR*RlRmRn((sN/usr/lib/python2.7/site-packages/redhat_support_tool/plugins/get_attachment.pyR@Hsj

(


		
%
	
N(t__name__t
__module__R
R7RKR9tclassmethodR	RRR R,R6R=R>RAR?RHRR@(((sN/usr/lib/python2.7/site-packages/redhat_support_tool/plugins/get_attachment.pyR#sA		 	/			1	(toptparseRt(redhat_support_lib.infrastructure.errorsRRt(redhat_support_tool.helpers.confighelperRRtredhat_support_tool.pluginsRRSRfR.t%redhat_support_tool.helpers.apihelperthelpersR`t"redhat_support_tool.helpers.commonR#R7Rst
__author__t	getLoggerRdR(((sN/usr/lib/python2.7/site-packages/redhat_support_tool/plugins/get_attachment.pyt<module>s