!f{-^dZddlZddlZddlZGddej j Zy)zISimple in-memory CrashDatabase implementation, mainly useful for testing.NceZdZdZdZddZdZdZdZdZ d Z d Z dd Z d Z d ZdZdZdZdZdZdZddZdZdZdZdZy) CrashDatabasezSimple implementation of crash database interface which keeps everything in memory. This is mainly useful for testing and debugging. ctjjj|||g|_t |_t |_d|_d|_ d|vr|jyy)ztInitialize crash database connection. This class does not support bug patterns and authentication. rN sample_data) apportcrashdbr__init__reportsset unretraced dup_unchecked upload_delay upload_msgadd_sample_data)self auth_fileoptionss .bugs.example.com/ for package bugs or http://bugs.example.com/ for reports without a SourcePackage. SourcePackagezhttp://z.bugs.example.com/zhttp://bugs.example.com/)rrhandles rget_comment_urlzCrashDatabase.get_comment_urlLs3 f $VO455GxP P)&22rc&|j||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-)rrr's r get_id_urlzCrashDatabase.get_id_urlUs##FH55rc&|j|dS)z>Download the problem report from given ID and return a Report.rr rr's rdownloadzCrashDatabase.download_s||H%h//rc.|j|ddgS)z5Return list of affected source packages for given ID.rr*r1r2s rget_affected_packagesz#CrashDatabase.get_affected_packagescs X&x0ABBrcy)z3Check whether the user is the reporter of given ID.Tr+r2s r is_reporterzCrashDatabase.is_reportergsrc$|j|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. )r7r2s r can_updatezCrashDatabase.can_updateks))rc|j|}||d<|r|D]}||vs|||d|<y|dj|y)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)r update) rr'rrchange_descriptionattachment_comment key_filterrfs rr;zCrashDatabase.updateusY0 LL ")  /;%+AYAhKN / hK  v &rc,|j|ddS)zNGet 'DistroRelease: ' from the given report ID and return it.r DistroReleaser1r2s rget_distro_releasez CrashDatabase.get_distro_releases||H%h/@@rct}t|jD]"\}}|d |d|j|$|S)aXReturn 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 OSError). rr)r enumerater r")rresultirs r get_unfixedzCrashDatabase.get_unfixedsN"4<<0 IAvh'F?,C,K 1   rcl |j|dy|j|dS#t$rYywxYw)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 OSError). rinvalidr)r IndexErrorr2s rget_fixed_versionzCrashDatabase.get_fixed_versionsD ||H%h/; <<)/: :  s'' 33c&|j|dS)zcReturn master ID for a duplicate bug. If the bug is not a duplicate, return None. rr1r2s r duplicate_ofzCrashDatabase.duplicate_ofs ||H%h//rc(||j|d<y)zlMark a crash id as duplicate of given master ID. If master is None, id gets un-duplicated. rNr1)rrr' master_ids rclose_duplicatezCrashDatabase.close_duplicates ,5 Xx(rcV|j|dJd||j|d<y)zyMark a crash id as reintroducing an earlier crash which is already marked as fixed (having ID 'master'). rNzregression, already fixed in #rr1)rr'masters rmark_regressionzCrashDatabase.mark_regressions8||F#O4@@@.LVH,U Xy)rcZ |jj|y#t$rYywxYw)z/Mark crash id as checked for being a duplicate.N)r removeKeyError)rr'rs r_mark_dup_checkedzCrashDatabase._mark_dup_checkeds-     % %h /   s  **c:|jj|y)zMark crash id as retraced.N)r rVr2s r mark_retracedzCrashDatabase.mark_retraceds x(rcy)ztMark crash id as 'failed to retrace'. This is a no-op since this crash DB is not interested in it. Nr+)rr' invalid_msgs rmark_retrace_failedz!CrashDatabase.mark_retrace_failedsrc|jS)z}Return an ID set of all crashes which have not been retraced yet and which happened on the current host architecture.)r rs rget_unretracedzCrashDatabase.get_unretracedsrc|jS)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 r_s rget_dup_uncheckedzCrashDatabase.get_dup_uncheckeds!!!rc2t|jdz S)z0Return the ID of the most recently filed report.r)r!r r_s r latest_idzCrashDatabase.latest_ids4<< 1$$rctjj}d|d<d|d<d|d<d|d<d |d <d |d <|j|tjj}d |d<d|d<d|d<d|d<d |d <d|d <|j|tjj}d|d<d|d<d|d<d|d<d|d <d|d <|j|tjj}d|d<d|d<d|d<d|d <d|d<|j|tjj}d|d<d|d<d|d<d|d <d|d<|j|y)zWAdd some sample crash reports. This is mostly useful for test suites. z libfoo1 1.2-3Packagefoor*z FooLinux Pi/2rB11Signalz /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)rrReportr()rr?s rrzCrashDatabase.add_sample_datas MM "&) "/,/( *     A MM "&) "/)/( *     A MM "!) "/)/( /     A MM "-) $/)/.  9   A MM "%) $/)/.  9   Ar)NN)FNN)N)__name__ __module__ __qualname____doc__r r(r-r/r3r5r7r9r;rCrHrLrNrQrTrXrZr]r`rbrdrr+rrrrs #&:360C*! 'DA  &05V)  "%\rr)rrr#apport.crashdbr apport.reportrrr+rrrus+O FNN00r