o vf(@s,dZddlZddlZGdddejjZdS)zISimple in-memory CrashDatabase implementation, mainly useful for testing.Nc@seZdZdZddZd.ddZddZd d Zd d Zd dZ ddZ ddZ  d/ddZ ddZ ddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-ZdS)0 CrashDatabasezSimple implementation of crash database interface which keeps everything in memory. This is mainly useful for testing and debugging.cCs@tjj|||g|_t|_t|_d|vr|dSdS)zkInitialize crash database connection. This class does not support bug patterns and authentication. dummy_dataN) apportcrashdbr__init__reportsset unretraced dup_uncheckedadd_dummy_data)self auth_fileoptionsr.bugs.example.com/ for package bugs or http://bugs.example.com/ for reports without a SourcePackage. SourcePackagezhttp://%s.bugs.example.com/%izhttp://bugs.example.com/%ir)r rhandlerrrget_comment_url4szCrashDatabase.get_comment_urlcCs |||S)zReturn URL for a given report ID. The report is passed in case building the URL needs additional information from it, such as the SourcePackage name. Return None if URL is not available or cannot be determined. )r!)r rrrrr get_id_url=s zCrashDatabase.get_id_urlcC|j|dS)z>Download the problem report from given ID and return a Report.rrr rrrrdownloadGzCrashDatabase.downloadcCs|j|ddgS)z5Return list of affected source packages for given ID.rrr$r%rrrget_affected_packagesLsz#CrashDatabase.get_affected_packagescCsdS)z3Check whether the user is the reporter of given ID.Trr%rrr is_reporterQszCrashDatabase.is_reportercCs ||S)aBCheck whether the user is eligible to update a report. A user should add additional information to an existing ID if (s)he is the reporter or subscribed, the bug is open, not a duplicate, etc. The exact policy and checks should be done according to the particular implementation. )r)r%rrr can_updateVs zCrashDatabase.can_updateFc CsN|j|}||d<|r|D]}||vr|||d|<q dS|d|dS)ahUpdate the given report ID with all data from report. This creates a text comment with the "short" data (see ProblemReport.write_mime()), and creates attachments for all the bulk/binary data. If change_description is True, and the crash db implementation supports it, the short data will be put into the description instead (like in a new bug). comment will be added to the "short" data. If attachment_comment is given, it will be added to the attachment uploads. If key_filter is a list or set, then only those keys will be added. rrN)rupdate) r rrrchange_descriptionattachment_comment key_filterrfrrrr+`s zCrashDatabase.updatecCs|j|ddS)zNGet 'DistroRelease: ' from the given report ID and return it.r DistroReleaser$r%rrrget_distro_release{sz CrashDatabase.get_distro_releasecCsLt}tt|jD]}|j|ddur#|j|ddur#||q |S)aOReturn an ID set of all crashes which are not yet fixed. The list must not contain bugs which were rejected or duplicate. This function should make sure that the returned list is correct. If there are any errors with connecting to the crash database, it should raise an exception (preferably IOError).rNr)rrangerrr)r resultirrr get_unfixeds  $ zCrashDatabase.get_unfixedcCs>z|j|ddur WdS|j|dWStyYdSw)aReturn the package version that fixes a given crash. Return None if the crash is not yet fixed, or an empty string if the crash is fixed, but it cannot be determined by which version. Return 'invalid' if the crash report got invalidated, such as closed a duplicate or rejected. This function should make sure that the returned result is correct. If there are any errors with connecting to the crash database, it should raise an exception (preferably IOError).rNinvalidr)r IndexErrorr%rrrget_fixed_versions  zCrashDatabase.get_fixed_versioncCr#)zcReturn master ID for a duplicate bug. If the bug is not a duplicate, return None. rr$r%rrr duplicate_ofszCrashDatabase.duplicate_ofcCs||j|d<dS)zlMark a crash id as duplicate of given master ID. If master is None, id gets un-duplicated. rNr$)r rrmasterrrrclose_duplicateszCrashDatabase.close_duplicatecCs,|j|ddus Jd||j|d<dS)zpMark a crash id as reintroducing an earlier crash which is already marked as fixed (having ID 'master').rNz regression, already fixed in #%irr$)r rr;rrrmark_regressionszCrashDatabase.mark_regressioncCs(z |j|WdStyYdSw)z/Mark crash id as checked for being a duplicate.N)r removeKeyError)r rrrrr_mark_dup_checkeds  zCrashDatabase._mark_dup_checkedcCs|j|dS)zMark crash id as retraced.N)r r>r%rrr mark_retracedszCrashDatabase.mark_retracedcC|jS)z}Return an ID set of all crashes which have not been retraced yet and which happened on the current host architecture.)r r rrrget_unretracedszCrashDatabase.get_unretracedcCrB)a#Return an ID set of all crashes which have not been checked for being a duplicate. This is mainly useful for crashes of scripting languages such as Python, since they do not need to be retraced. It should not return bugs that are covered by get_unretraced().)r rCrrrget_dup_uncheckedszCrashDatabase.get_dup_uncheckedcCst|jdS)z0Return the ID of the most recently filed report.r)rrrCrrr latest_idr'zCrashDatabase.latest_idcCs>t}d|d<d|d<d|d<d|d<d |d <d |d <||t}d |d<d|d<d|d<d|d<d |d <d|d <||t}d|d<d|d<d|d<d|d<d|d <d|d <||t}d|d<d|d<d|d<d|d <d|d<||t}d|d<d|d<d|d<d|d <d|d<||dS)zMAdd some dummy crash reports. This is mostly useful for test suites.z libfoo1 1.2-3Packagefoorz FooLinux Pi/2r111Signalz /bin/crashExecutablePathzfoo_bar (x=1) at crash.c:28 d01 (x=1) at crash.c:29 raise () from /lib/libpthread.so.0 __frob (x=1) at crash.c:30 StacktraceTopz libfoo1 1.2-4z Testux 1.0zfoo_bar (x=2) at crash.c:28 d01 (x=3) at crash.c:29 raise () from /lib/libpthread.so.0 __frob (x=4) at crash.c:30zbar 42-4barz/usr/bin/brokenzuh (p=0x0) at crash.c:25 g (x=1, y=42) at crash.c:26 f (x=1) at crash.c:27 e (x=1) at crash.c:28 d (x=1) at crash.c:29zpython-goo 3epsilon1pygooz Testux 2.2z/usr/bin/pygoozTraceback (most recent call last): File "test.py", line 7, in print(_f(5)) File "test.py", line 5, in _f return g_foo00(x+1) File "test.py", line 2, in g_foo00 return x/0 ZeroDivisionError: integer division or modulo by zerorz python-goo 5N)rReportr)r r/rrrr sL    zCrashDatabase.add_dummy_data)N)FNN)__name__ __module__ __qualname____doc__rrr!r"r&r(r)r*r+r2r6r9r:r<r=r@rArDrErFr rrrrrs2      r)rSapport.crashdbrrrrrrrs