ó ‰P[c@sÎddlZddlZddlZddlZddlZddlZddlZddlZddlZ ddl Z ddl m Z ddl mZdejfd„ƒYZedkrÊejƒndS(iÿÿÿÿN(tBytesIO(tpatchtTcBsìeZd„Zd„Zed„Zd„Zd„Zd„Zd„Z d„Z d„Z d „Z d „Z d „Zejed ƒejed ƒd„ƒƒZd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„ZRS(cCs4tjj|_tjƒtj_tjj|_dS(N(tapportt fileutilst report_dirtorig_report_dirttempfiletmkdtempt _config_filetorig_config_file(tself((s-/usr/share/apport/testsuite/test_fileutils.pytsetUp scCs>tjtjjƒ|jtj_d|_|jtj_dS(N( tshutiltrmtreeRRRRtNoneR R (R ((s-/usr/share/apport/testsuite/test_fileutils.pyttearDowns cCstjjtjjdƒ}tjjtjjdƒ}t|dƒ}|jdƒWdQXt|dƒ}|jdƒWdQXtj|dƒtj|dƒ|rtjjtjjdƒ}t|dƒ}|jd ƒWdQXtj|d ƒ|||gS||gSdS( sCreate some test reportss rep1.crashs rep2.crashtwsreport 1Nsreport 2i€sinaccessible.crasht inaccessiblei( tostpathtjoinRRRtopentwritetchmod(R tcreate_inaccessibletr1tr2tfdtri((s-/usr/share/apport/testsuite/test_fileutils.pyt_create_reportss c Csqd}tgtjj|ƒD]}|jdƒr|^qƒdksLt‚d}d}d}x'tjdƒD]}|jdƒs‰qnntj j d|ƒ}tjj |ƒ}tgtjj|ƒD]}|jdƒrÆ|^qƃ} t |dƒ;}d|j ƒkr0| r*| dkr*|}nwnnWdQX| rR| dkrR|}n| rn| dkrn|}n|rn|rn|rnPqnqnW|r´|jtjj|ƒdd |ƒn|rà|jtjj|ƒdd |ƒn|rAtjj|ƒ}|j|dd |ƒ|jtj j|ƒƒ|j|jdƒƒn|rm|jtjj|ƒdd |ƒndS( sfind_package_desktopfile()tbashs.desktopis/usr/share/applications/trbsNoDisplay=trueiNsno-desktop package %ssmulti-desktop package %ssone-desktop package %ssNoDisplay package %s(tlenRt packagingt get_filestendswithtAssertionErrorRRtlistdirRRtget_file_packageRtreadt assertEqualRtfind_package_desktopfiletassertNotEqualt assertTruetexists( R t nodesktoptft onedesktopt multidesktopt nodisplaytdRtpkgtnum((s-/usr/share/apport/testsuite/test_fileutils.pyttest_find_package_desktopfile-sL*    cCs¬|jtjjdƒtƒ|jtjjdƒtƒ|jtjjdƒtƒ|jtjjdƒtƒ|jtjjdƒtƒ|jtjjdƒtƒdS(slikely_packaged()s /bin/bashs /usr/bin/foos/usr/local/bin/foos/home/test/bin/foos/tmp/foos /var/lib/fooN(R)RRtlikely_packagedtTruetFalse(R ((s-/usr/share/apport/testsuite/test_fileutils.pyttest_likely_packaged]s cCsX|jtjjdƒdƒ|jtjjdƒdƒ|jtjjdƒdƒdS(sfind_file_package()s /bin/bashRs/bin/catt coreutilss /nonexistingN(R)RRtfind_file_packageR(R ((s-/usr/share/apport/testsuite/test_fileutils.pyttest_find_file_packagehscCs%|jtjjƒgƒtjƒdkr=|jtƒ}n.g|jtƒD]}d|krM|^qM}|jttjjƒƒt|ƒƒt|ƒ}x‚|D]z}|jtjj |ƒt ƒ|j |ƒtjj |ƒ|jtjj |ƒtƒ|jttjjƒƒ|ƒq£WdS(s#get_new_reports() and seen_report()iRN( R)RRtget_new_reportsRtgetuidRR8tsett seen_reportR9tremovetmark_report_seen(R ttrtrtnr((s-/usr/share/apport/testsuite/test_fileutils.pyt test_seenos.%   cCs}tjƒ}d|d(R RER((s-/usr/share/apport/testsuite/test_fileutils.pyttest_unwritable_reportÖs(+"cCsX|jƒ}xE|rS|jttjjƒƒt|ƒƒtjj|jƒƒqWdS(sdelete_report()N(RR)R@RRR_t delete_reporttpop(R RD((s-/usr/share/apport/testsuite/test_fileutils.pyttest_delete_reportès  %cCs,tdƒ}|jtjj|ƒdƒtdƒ}|jtjj|ƒdƒtdƒ}|jtjj|ƒdƒtjtjtjƒƒd ƒ}td|j ƒdƒ}|jtjj|ƒdƒtjtjtjƒƒdƒ}td|j ƒdƒ}|jtjj|ƒd ƒd S( sget_recent_crashes()sProblemType: Crashis1ProblemType: Crash Date: Wed Aug 01 00:00:01 1990sAProblemType: Crash Date: Wed Aug 01 00:00:01 1990 CrashCounter: 3iisProblemType: Crash Date: s CrashCounter: 3iNi_( RR)RRtget_recent_crashesRVtctimetmktimet localtimetencode(R REtdate((s-/usr/share/apport/testsuite/test_fileutils.pyttest_get_recent_crashesñs$   "  "  c Cs¼tjƒ}|jttjj|ƒd|dsT   ÿ~