Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/apport/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/apport/fileutils.pyc


Yc@s|dZddlZddlZddlZddlZddlZy ddlmZmZm	Z	Wn-e
k
rddlmZmZm	Z	nXddlmZddl
mZejjddZdZd	Zd
ZdZdZd
ZdZdZdZdZdZdZdZdZ dZ!ddZ#dZ$dde%dZ&de&_'dS(s0Functions to manage apport problem report files.iN(tConfigParsert
NoOptionErrortNoSectionError(t
ProblemReport(timpltAPPORT_REPORT_DIRs
/var/crashs~/.config/apport/settingss/etc/default/whoopsiec	CstdddtdtdtS(s)Check whether crash reporting is enabled.tGeneraltreport_crashestdefaulttpathtbool(t
get_configtTruet_whoopsie_config_file(((s4/usr/lib/python2.7/dist-packages/apport/fileutils.pytallowed_to_reportscCsV|dkrdSd}x9tj|D](}|jdr&|rEdS|}q&q&W|S(sReturn a package's .desktop file.

    If given package is installed and has a single .desktop file, return the
    path to it, otherwise return None.
    s.desktopN(tNonet	packagingt	get_filestendswith(tpackagetdesktopfiletline((s4/usr/lib/python2.7/dist-packages/apport/fileutils.pytfind_package_desktopfile#s
cCsrddddddddg}t}x'|D]}|j|r+t}Pq+q+W|oq|jd	oq|jd
S(s2Check whether the given file is likely to belong to a package.

    This is semi-decidable: A return value of False is definitive, a True value
    is only a guess which needs to be checked with find_file_package().
    However, this function is very fast and does not access the package
    database.
    s/bin/s/boots/etc/s/initrds/libs/sbin/s/usr/s/vars/usr/local/s	/var/lib/(tFalset
startswithR(tfilet
pkg_whitelisttwhitelist_matchti((s4/usr/lib/python2.7/dist-packages/apport/fileutils.pytlikely_packaged7s
cCsqtjj|\}}tjj|}tjj|rTtjj||}nt|sddStj	|S(s[Return the package that ships the given file.

    Return None if no package ships it.
    N(
tosR	tsplittrealpathtisdirtjoinRRRtget_file_package(Rtdirtnametresolved_dir((s4/usr/lib/python2.7/dist-packages/apport/fileutils.pytfind_file_packageJscCs.tj|}|j|jkp-|jdkS(sACheck whether the report file has already been processed earlier.i(Rtstattst_atimetst_mtimetst_size(treporttst((s4/usr/lib/python2.7/dist-packages/apport/fileutils.pytseen_reportZscCsd|jddd}d|jddd}tjj|rtjj|rtj|}tj|}|j|jkrtj|qnt|dWdQXdS(Ns	%s.uploadt.iis%s.uploadedta(trsplitRR	texistsR(R*tunlinktopen(R,tuploadtuploadedt	report_stt	upload_st((s4/usr/lib/python2.7/dist-packages/apport/fileutils.pytmark_report_upload`s$cCstj|}y$tj||j|jdfWntk
rd}x|dkrt|}|jd|jytj|}Wntk
rdSX|j|jkrPnt	j
d|d8}qLW|dkrt|qnXdS(sMark given report file as seen.iiiNg?(RR(tutimeR*tOSErrorR4treadtcloseR)ttimetsleept
delete_report(R,R-ttimeouttf((s4/usr/lib/python2.7/dist-packages/apport/fileutils.pytmark_report_seenls&$




cCsg}x{tjtjjtdD][}yAtjj|dkrktj|tjrk|j|nWq%t	k
rq%Xq%W|S(sCReturn a list with all report files accessible to the calling user.s*.crashi(
tglobRR	R"t
report_dirtgetsizetaccesstR_OKtappendR;(treportstr((s4/usr/lib/python2.7/dist-packages/apport/fileutils.pytget_all_reportss%-
cCsRg}xEtD]:}y t|s5|j|nWqtk
rIqXqW|S(sGet new reports for calling user.

    Return a list with all report files which have not yet been processed
    and are accessible to the calling user.
    (RLR.RIR;(RJRK((s4/usr/lib/python2.7/dist-packages/apport/fileutils.pytget_new_reportss
cCsg}x~tjtjjtdD]^}yDtjj|dkrntj|jdkrn|j|nWq%t	k
rq%Xq%W|S(sGet all system reports.

    Return a list with all report files which belong to a system user (i. e.
    uid < 500 according to LSB).
    s*.crashii(
RDRR	R"RERFR(tst_uidRIR;(RJRK((s4/usr/lib/python2.7/dist-packages/apport/fileutils.pytget_all_system_reportss%0
cCs&gtD]}t|s
|^q
S(sGet new system reports.

    Return a list with all report files which have not yet been processed
    and belong to a system user (i. e. uid < 500 according to LSB).
    (ROR.(RK((s4/usr/lib/python2.7/dist-packages/apport/fileutils.pytget_new_system_reportsscCs?ytj|Wn'tk
r:t|djdnXdS(sDelete the given report file.

    If unlinking the file fails due to a permission error (if report_dir is not
    writable to normal users), the file will be truncated to 0 bytes instead.
    twiN(RR3R;R4ttruncate(R,((s4/usr/lib/python2.7/dist-packages/apport/fileutils.pyR@s
cCst}|j|ty]t|d}tjtj|d}tjtj}||dkrqdS|SWntt	fk
rdSXdS(sReturn the number of recent crashes for the given report file.

    Return the number of recent crashes (currently, crashes which happened more
    than 24 hours ago are discarded).
    tCrashCountertDateiiiNiQ(
RtloadRtintR>tmktimetstrptimet	localtimet
ValueErrortKeyError(R,tprtcounttreport_timetcur_time((s4/usr/lib/python2.7/dist-packages/apport/fileutils.pytget_recent_crashess	cCsd|kr%|djdd}n5d|krN|djddd}ntd|sotj}ntjjtd|t	|f}tj
tj|tjtj
BtjBd	d
S(s,Construct a canonical pathname for a report and open it for writing

    If uid is not given, it defaults to the uid of the current process.
    The report file must not exist already, to prevent losing previous reports
    or symlink attacks.

    Return an open file object for binary writing.
    tExecutablePatht/t_tPackageiis7report has neither ExecutablePath nor Package attributes%s.%s.crashitwbN(treplaceRRRZRtgetuidR	R"REtstrtfdopenR4tO_WRONLYtO_CREATtO_EXCL(R,tuidtsubjectR	((s4/usr/lib/python2.7/dist-packages/apport/fileutils.pytmake_report_files	%cCstjj|sttjdd|gdtjdtjdtdddi}|jd	j	}|j
d	kr}gSg}xC|jD]5}|jd
r|j
|jddd	qqW|S(
sCheck file integrity against md5 sum file.

    sumfile must be md5sum(1) format (relative to /).

    Return a list of files that don't match.
    s/usr/bin/md5sums-ctstdouttstderrt	close_fdstcwdRbtenvitFAILEDt:i(RR	R2tAssertionErrort
subprocesstPopentPIPERtcommunicatetdecodet
returncodet
splitlinesRRIR1(tsumfiletmtoutt
mismatchestl((s4/usr/lib/python2.7/dist-packages/apport/fileutils.pytcheck_files_md5s$cCstjsMtt_|r.tjj|qMtjjtjjtny0|ritjj||Stjj	||SWnt
tfk
r|SXdS(sReturn a setting from user configuration.

    This is read from ~/.config/apport/settings or path. If bool is True, the
    value is interpreted as a boolean.
    N(RtconfigRR<RR	t
expandusert_config_filet
getbooleantgetRR(tsectiontsettingRR	R
((s4/usr/lib/python2.7/dist-packages/apport/fileutils.pyRs	((t__doc__RRDRxtos.pathR>tconfigparserRRRtImportErrortproblem_reportRtapport.packaging_implRRtenvironRRERR
RRRR'R.R9RCRLRMRORPR@R`RRoRRRR(((s4/usr/lib/python2.7/dist-packages/apport/fileutils.pyt<module>s6<