
qxPXc           @   s  d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l	 Z	 d d l
 Z
 d d l Z d d l Z d d l Z d d l m Z m Z d d l m Z d d l Z y d j d d  Z Wn/ e k
 rd d l Z e j d d  Z n Xd   Z d e d	  Z d
   Z d e d  Z d d d  Z d   Z  d   Z! d   Z" d   Z# d   Z$ d   Z% d e j& e' d  Z( d   Z) d e j& d  Z* d   Z+ d   Z, d d  Z- d d  Z. d Z/ d Z0 d Z1 d Z2 d Z3 d  Z4 d! Z5 d" Z6 d# Z7 d$ Z8 d% Z9 d& Z: d'   Z; d(   Z< d d)  Z= d*   Z> d+   Z? d,   Z@ d-   ZA d.   ZB d/   ZC d0   ZD d1   ZE d2   ZF d3   ZG d4   ZH d5   ZI d6 d7  ZJ d8   ZK d9   ZL d:   ZM d d;  ZN d S(<   s/   Convenience functions for use in package hooks.iN(   t   Giot   GLib(   t   implt    s   #/-_+ s   ....._c         C   sw   t  j d d k r@ t |   t d  k rj |  j d  }  qj n* t |   t d  k rj |  j d  }  n  |  j t  S(   s{   Generate a valid report key name from a file path.

    This will replace invalid punctuation symbols with valid ones.
    i    t   3R   s   UTF-8(   t   syst   versiont   typet   decodet   encodet	   translatet   _path_key_trans(   t   path(    (    s4   /usr/lib/python2.7/dist-packages/apport/hookutils.pyt   path_to_key*   s    c         C   sA   | s t  |  } n  t j j |  r= t |  | | |  n  d S(   s  Attach file contents if file exists.

    If key is not specified, the key name will be derived from the file
    name with path_to_key().

    If overwrite is True, an existing key will be updated. If it is False, a
    new key with '_' appended will be added instead.
    N(   R   t   osR   t   existst   attach_file(   t   reportR   t   keyt	   overwrite(    (    s4   /usr/lib/python2.7/dist-packages/apport/hookutils.pyt   attach_file_if_exists7   s    	c         C   sQ   y, t  |  d   } | j   j   SWd QXWn t k
 rL } d t |  SXd S(   s   Return the contents of the specified path.

    Upon error, this will deliver a text representation of the error,
    instead of failing.
    t   rbNs   Error: (   t   opent   readt   stript	   Exceptiont   str(   R   t   ft   e(    (    s4   /usr/lib/python2.7/dist-packages/apport/hookutils.pyt	   read_fileF   s
    c         C   sO   | s t  |  } n  | s; x | |  k r7 | d 7} q Wn  t |  |  | <d S(   s
  Attach a file to the report.

    If key is not specified, the key name will be derived from the file
    name with path_to_key().

    If overwrite is True, an existing key will be updated. If it is False, a
    new key with '_' appended will be added instead.
    t   _N(   R   R   (   R   R   R   R   (    (    s4   /usr/lib/python2.7/dist-packages/apport/hookutils.pyR   R   s    	c   
      C   s   t  j |  } x | j   D] \ } } | r@ | | k r@ q n  d t |  } | d k rl | |  | <q n  | r | j d |  } | r | |  | <q d |  | <n
 d |  | <t j j t j |  j	  }	 |	 j
   |  d t |  <q Wd S(   s(  Attach information about any modified or deleted conffiles.

    If conffiles is given, only this subset will be attached. If ui is given,
    ask whether the contents of the file may be added to the report; if this is
    denied, or there is no UI, just mark it as "modified" in the report.
    s   modified.conffile.s	   [deleted]sn   It seems you have modified the contents of "%s".  Would you like to add the contents of it to your bug report?s
   [modified]s   mtime.conffile.N(   t	   packagingt   get_modified_conffilest   itemsR   t   yesnot   datetimet   fromtimestampR   t   statt   st_mtimet	   isoformat(
   R   t   packaget	   conffilest   uit   modifiedR   t   contentsR   t   responset   mtime(    (    s4   /usr/lib/python2.7/dist-packages/apport/hookutils.pyt   attach_conffilesd   s     

c         C   s   y t  j j |  } Wn t k
 r* d SXxj | D]b } t j j |  r2 | j d  r2 | j d d  } d | j d d  } t	 |  | |  q2 q2 Wd S(   s3   Attach information about any Upstart override filesNs
   /etc/init/s   .confs	   .overrides   upstart.R   (
   t   apportR   t	   get_filest
   ValueErrorR   R   R   t
   startswitht   replaceR   (   R   R(   t   filest   filet   overrideR   (    (    s4   /usr/lib/python2.7/dist-packages/apport/hookutils.pyt   attach_upstart_overrides   s    !c         C   s   yD |  j  d d  j   sC t d   } | j   |  d <Wd QXn  Wn t k
 rW n X|  j  d d  j   s t d d d g  } | j d	  } | d
 k r | | d } n  | |  d <n  d S(   sw   Attach information from the kernel ring buffer (dmesg).

    This will not overwrite already existing information.
    t	   BootDmesgR   s   /var/log/dmesgNt   CurrentDmesgt   shs   -cs1   dmesg | comm -13 --nocheck-order /var/log/dmesg -s   
[ii   (   t   getR   R   R   t   IOErrort   command_outputt   find(   R   R   t   dmesgt   first_newline(    (    s4   /usr/lib/python2.7/dist-packages/apport/hookutils.pyt   attach_dmesg   s    c      	   C   s  d } t  j j |  r x t  j |  D] } d | | f } t  j |  } t j | j  s( | j d @d k ry q( n  | d
 k r q( n  y+ t |   } | j   j	   } Wd  QXWn t
 t f k
 r q( n X| r( | |  d | j d d	  <q( q( Wn  d  S(   Ns   /sys/class/dmi/ids   %s/%si   i    t	   subsystemt   uevents   dmi.R   t   .(   RC   RD   (   R   R   t   isdirt   listdirR%   t   S_ISREGt   st_modeR   R   R   t   OSErrorR=   R4   (   R   t   dmi_dirR   t   pt   stt   fdt   value(    (    s4   /usr/lib/python2.7/dist-packages/apport/hookutils.pyt
   attach_dmi   s     &c         C   s-  t  |   t |  d d  t |  d d  t |  d d  t |  d d  t j j d	  ru t d
 d g  |  d <n  t d g  |  d <t d d g  |  d <t d d d g  |  d <|  d j d d d } t j d d |  } t j d d |  } t j d d |  } t j d d |  } t j d d |  } t j d d |  } | j	 d  |  d <t
 |   d |  k rd  |  k rd! |  d |  d  f |  d" <n  t d#  rt d# g  |  d$ <n  t d%  r)t d% d& g  j   } | r| |  d' <n  t d% d( g  j   } | r)| |  d) <q)n  d* S(+   sP  Attach a standard set of hardware-related data to the report, including:

    - kernel dmesg (boot and current)
    - /proc/interrupts
    - /proc/cpuinfo
    - /proc/cmdline
    - /proc/modules
    - lspci -vvnn
    - lsusb
    - devices from udev
    - DMI information from /sys
    - prtconf (sparc)
    - pccardctl status/ident
    s   /proc/interruptst   ProcInterruptss   /proc/cpuinfot   ProcCpuinfos   /proc/cmdlinet   ProcKernelCmdLines   /var/log/udevt   UdevLogs   /sys/bus/pcit   lspcis   -vvnnt   Lspcit   lsusbt   Lsusbt   sorts   /proc/modulest   ProcModulest   udevadmt   infos   --export-dbt   UdevDbs   UTF-8t   errorsR4   s   ID_FS_LABEL=(.*)s   ID_FS_LABEL=<hidden>s   ID_FS_LABEL_ENC=(.*)s   ID_FS_LABEL_ENC=<hidden>s   by-label/(.*)s   by-label/<hidden>s   dmi.sys.vendors   dmi.product.names   %s %st   MachineTypet   prtconft   Prtconft	   pccardctlt   statust   PccardctlStatust   identt   PccardctlIdentN(   RB   R   R   R   R   R>   R   t   ret   subR	   RP   t   command_availableR   (   R   t   lt   out(    (    s4   /usr/lib/python2.7/dist-packages/apport/hookutils.pyt   attach_hardware   s>    


c      	   C   s  t  |  t j j d  d  t  |  t j j d  d  t  |  d  t  |  d d  t |  d d	  t d
 d d g  |  d <t d d g  |  d <t d d g  |  d <t t  |  d <g  } t j j d  r3t	 d  P } xF | D]> } d | k r | j
   j   } | j t | d   q q WWd QXn  xV| D]N} d | } t d d t |  d g  |  | <d | } t d d t |  g  |  | <x t j d |  D] } t j j |  rt j j |  } d | t |  f } t |  | d | qt j j |  rt j j |  } x^ t j |  D]J }	 t j j | |	  }
 d | t |  t |	  f } t |  |
 |  q3WqqWq:Wt d  d! g t j d"  t j d#  t j d$   |  d% <t j j d&  rt d' d( g  |  d) <n  t |   t |   d S(*   sv   Attach ALSA subsystem information to the report.

    (loosely based on http://www.alsa-project.org/alsa-info.sh)
    s   ~/.asoundrct   UserAsoundrcs   ~/.asoundrc.asoundconft   UserAsoundrcAsoundconfs   /etc/asound.confs   /proc/asound/versiont   AlsaVersions   /proc/cpuinfoRR   t   lss   -ls	   /dev/snd/t   AlsaDevicest   aplayt   AplayDevicest   arecordt   ArecordDevicest   PciMultimedias   /proc/asound/cardss   ]:i    Ns   Card%d.Amixer.infot   amixers   -cR\   s   Card%d.Amixer.valuess   /proc/asound/card%d/codec*s   Card%d.Codecs.%sR   s   Card%d.Codecs.%s.%st   fusers   -vs	   /dev/dsp*s
   /dev/snd/*s	   /dev/seq*t   AudioDevicesInUses   /usr/bin/pacmdt   pacmdt   listt	   PulseList(   R   R   R   t
   expanduserR   R>   t   pci_devicest   PCI_MULTIMEDIAR   R   t   lstript   splitt   appendt   intR   t   globt   isfilet   basenameR   RF   RG   t   joinRP   RB   (   R   t   cardsRN   t   linet   fieldst   cardR   t	   codecpatht   codect   nameR   (    (    s4   /usr/lib/python2.7/dist-packages/apport/hookutils.pyt   attach_alsa   sP    '
"
:
c         C   s   d t  j k r t St  j d } xf | j t  j  D]R } | sE q3 n  t  j j | |   } t  j j |  r3 t  j | t  j	  r3 t
 Sq3 Wt S(   s/   Is given command on the executable search path?t   PATH(   R   t   environt   FalseR   t   pathsepR   R   R   t   accesst   X_OKt   True(   t   commandR   t   elementt   filename(    (    s4   /usr/lib/python2.7/dist-packages/apport/hookutils.pyRi   *  s    'c         C   s   t  j j   } | s" d | d <n  yC t j |  d t j d | d | rO t j pR d d t d | } Wn t k
 r } d t	 |  SX| j
 |  d	 } | j d	 k r | j   Sd
 t	 |   | j | f Sd S(   s   Try to execute given command (array) and return its stdout.

    In case of failure, a textual error gets returned. This function forces
    LC_MESSAGES to C, to avoid translated output in bug reports.
    t   Ct   LC_MESSAGESt   stdoutt   stderrt   stdint	   close_fdst   envs   Error: i    s.   Error: command %s failed with exit code %i: %sN(   R   R   t   copyt
   subprocesst   Popent   PIPEt   NoneR   RJ   R   t   communicatet
   returncodeR   (   R   t   inputR   t   keep_localeR   t   spR   Rk   (    (    s4   /usr/lib/python2.7/dist-packages/apport/hookutils.pyR>   7  s    
c          C   sl  t  j   d k r g  }  nMt  j d  r t j d d g d t j d t j d k r t j d d d	 t t  j    d
 g d t j d t j d k r d d d d d d	 d d g }  n t  j d  rYt j d d g d t j d t j d k rYt j d d d	 t t  j    d g d t j d t j d k rYd d d d d d	 d d g }  n d d d g }  |  S(   Ni    t   DISPLAYt   whicht   kdesudoR   R   t   pgreps   -xs   -ut	   ksmservers	   --desktops/   /usr/share/applications/apport-kde-mime.desktops   --R   t   LANGUAGEs   LC_MESSAGES=Ct   gksus   gnome-panel|gconfd-2s   -Dt   Apportt   sudos	   LANGUAGE=(   R   t   getuidt   getenvR   t   callR   R   (   t   prefix(    (    s4   /usr/lib/python2.7/dist-packages/apport/hookutils.pyt   _root_command_prefixO  s"    	'	'!c         C   sA   t  |   t  g   k s$ t d   t t   |  | | d t S(   s   Try to execute given command (array) as root and return its stdout.

    This passes the command through gksu, kdesudo, or sudo, depending on the
    running desktop environment.

    In case of failure, a textual error gets returned.
    s   command must be a listR   (   R   t   AssertionErrorR>   R   R   (   R   R   R   (    (    s4   /usr/lib/python2.7/dist-packages/apport/hookutils.pyt   root_command_outputd  s    $c   
      C   s8  t  j   } zt j j | d  } t | d  } x[ | j   D]M \ } } t | d  sg t d   | j	 d | t j j | |  f  q@ W| j
   t j t   d | g d t } | j   xX | D]P } t t j j | |   } | j   j   }	 |	 r|	 |  | <n  | j
   q WWd t j |  Xd S(	   sP  Execute multiple commands as root and put their outputs into report.

    command_map is a keyname -> 'shell command' dictionary with the commands to
    run. They are all run through /bin/sh, so you need to take care of shell
    escaping yourself. To include stderr output of a command, end it with
    "2>&1".

    Just like root_command_output() this will use gksu, kdesudo, or sudo for
    gaining root privileges, depending on the running desktop environment.

    This is preferrable to using root_command_output() multiple times, as that
    will ask for the password every time.
    s   :script:t   wR   s(   command must be a string (shell command)s   %s | cat > %s
s   /bin/shR   N(   t   tempfilet   mkdtempR   R   R   R   R!   t   hasattrR   t   writet   closeR   R   R   R   t   waitR   R   t   shutilt   rmtree(
   R   t   command_mapt   workdirt   script_patht   scriptt   keynameR   R   R   t   buf(    (    s4   /usr/lib/python2.7/dist-packages/apport/hookutils.pyt   attach_root_command_outputsp  s$    *
	
c         C   s   t  d |   S(   sc   Extract recent messages from syslog which match a regex.

    pattern should be a "re" object.
    s   /var/log/syslog(   t   recent_logfile(   t   pattern(    (    s4   /usr/lib/python2.7/dist-packages/apport/hookutils.pyt   recent_syslog  s    i'  c         C   s   d } y t  j d d t |  |  g d t  j } xF | j   d k r{ x- | j D]" } | j |  rR | | 7} qR qR Wq6 W| j   Wn t	 k
 r d SX| S(   s   Extract recent messages from a logfile which match a regex.

    pattern should be a "re" object. By default this catches at most the last
    1000 lines, but this can be modified with a different maxlines argument.
    R   t   tails   -nR   N(
   R   R   R   R   t   pollR   R   t   searchR   R=   (   t   logfileR   t   maxlinest   linesR   R   (    (    s4   /usr/lib/python2.7/dist-packages/apport/hookutils.pyR     s    c         C   s}   t  j j d  } t  j j |  s( d S|  s@ t j d  }  n  d } x0 t |  D]" } |  j |  rS | | 7} qS qS W| S(   sl  Extract messages from ~/.xsession-errors.

    By default this parses out glib-style warnings, errors, criticals etc. and
    X window errors.  You can specify a "re" object as pattern to customize the
    filtering.

    Please note that you should avoid attaching the whole file to reports, as
    it can, and often does, contain sensitive and private data.
    s   ~/.xsession-errorsR   s   ^(\(.*:\d+\): \w+-(WARNING|CRITICAL|ERROR))|(Error: .*No Symbols named)|([^ ]+\[\d+\]: ([A-Z]+):)|([^ ]-[A-Z]+ \*\*:)|(received an X Window System error)|(^The error was ')|(^  \(Details: serial \d+ error_code)(   R   R   R}   R   Rg   t   compileR   R   (   R   R   R   R   (    (    s4   /usr/lib/python2.7/dist-packages/apport/hookutils.pyt   xsession_errors  s    
i   i   i   i   i   i   i   i   i	   i
   i   i   c    
      G   sR  |  s t  d d g  Sd } t  d d g  } x| j d  D]} d } d } x | j d  D] } y | j d d  \ } } Wn t k
 r q` n X| j   } | j   } | d	 k r t | d
 d !d  }	 |	 d @d ?} q` | d k r` | } q` q` W| r> | r> | |  k r> | r(| d 7} n  | t  d d | g  j   7} q> q> W| S(   s9   Return a text dump of PCI devices attached to the system.RU   s   -vvnnR   s   -vvmmnns   

s   
t   :i   t   Classiii   i   i   t   Slots   -vvnnsN(   R>   R   R   R2   R   R   (
   t   pci_classest   resultt   outputt	   paragrapht	   pci_classt   slotR   R   RO   t   n(    (    s4   /usr/lib/python2.7/dist-packages/apport/hookutils.pyR~     s0    &c           C   s   t  d d g  S(   s9   Return a text dump of USB devices attached to the system.RW   s   -v(   R>   (    (    (    s4   /usr/lib/python2.7/dist-packages/apport/hookutils.pyt   usb_devices  s    c         C   sP   t  j |   } | rF g  | D]! } t j j | |  r | ^ q } n | } | S(   sF   Retrieve a list of files owned by package, optionally matching globpat(   R   R1   R   t   fnmatch(   R(   t   globpatR5   R   R   (    (    s4   /usr/lib/python2.7/dist-packages/apport/hookutils.pyt   files_in_package  s
    1c         C   s   d S(   t   ObsoleteN(    (   R   R(   (    (    s4   /usr/lib/python2.7/dist-packages/apport/hookutils.pyt   attach_gconf  s    c   	      C   s  |  j  d d  } i  } t j j   } d | d <t j d d | g d | d t j } xi | j D]^ } y+ | j d d	  \ } } } | j
   } Wn t k
 r qb n X| | j | i   | <qb Wt j d d | g d t j } x | j D] } y+ | j d d	  \ } } } | j
   } Wn t k
 r6q n X| | j  | i   j  | d  k r | d
 | | | f 7} q q W| |  d <d S(   s/   Attach user-modified gsttings keys of a schema.t   GsettingsChangesR   s   /nonexistingt   XDG_CONFIG_HOMEt	   gsettingss   list-recursivelyR   R   i   s	   %s %s %s
N(   R<   R   R   R   R   R   R   R   R   R   t   rstripR2   t
   setdefault(	   R   t   schemat	   cur_valuet   defaultsR   R   Rj   R   RO   (    (    s4   /usr/lib/python2.7/dist-packages/apport/hookutils.pyt   attach_gsettings_schema  s0    
$c         C   sA   x: t  | d  D]) } t j j |  d  } t |  |  q Wd S(   s@   Attach user-modified gsettings keys of all schemas in a package.s)   /usr/share/glib-2.0/schemas/*.gschema.xmliN(   R   R   R   R   R   (   R   R(   t   schema_fileR   (    (    s4   /usr/lib/python2.7/dist-packages/apport/hookutils.pyt   attach_gsettings_package-  s    	c         C   s   t  d d g  |  d <t  d d g  |  d <t t  |  d <t |  d d d	 x1 d D]) } | t j k rV t j | |  | <qV qV Wd S(   s5   Attach generic network-related information to report.t   ipt   routet   IpRoutet   addrt   IpAddrt
   PciNetworks   /etc/network/interfacesR   t   IfupdownConfigt
   http_proxyt	   ftp_proxyt   no_proxyN(   R   R   R   (   R>   R~   t   PCI_NETWORKR   R   R   (   R   t   var(    (    s4   /usr/lib/python2.7/dist-packages/apport/hookutils.pyt   attach_network5  s    c         C   s   t  t j d   |  d <t j d d t j d d t j d d t d	 g  j d
 d d    |  d <t d d g  |  d <t d d d g  |  d <t |  d d d d S(   s5   Attach wireless (WiFi) network information to report.sH   (NetworkManager|modem-manager|dhclient|kernel|wpa_supplicant)(\[\d+\])?:t
   WifiSyslogs
   ESSID:(.*)s   ESSID:<hidden>s   Encryption key:(.*)s   Encryption key: <hidden>s   Access Point: (.*)s   Access Point: <hidden>t   iwconfigs   UTF-8R^   t   ignoret   IwConfigt   rfkillR{   t   RfKillt   iwt   regR<   t   CRDAs   /var/log/wpa_supplicant.logR   t   WpaSupplicantLogN(   R   Rg   R   Rh   R>   R   R   (   R   (    (    s4   /usr/lib/python2.7/dist-packages/apport/hookutils.pyt   attach_wifiA  s    +c      !   C   s  t  |  d d  t  |  d d  t d g  |  d <t d d g  |  d	 <t j d
  } | r t d d d g |  } t j d d |  |  d <n  t d d d d d d d d d d d d d d d d  d! d" d# d$ d% d& d' d( d d) d* d+ d, d- d. d/   |  d0 <d1 S(2   sk   Attach printing information to the report.

    Based on http://wiki.ubuntu.com/PrintingBugInfoScript.
    s   /etc/papersizet	   Papersizes   /var/log/cups/error_logt   CupsErrorLogt   localet   Localet   lpstats   -vt   Lpstats   /etc/cups/ppd/*.ppdt   fgreps   -Hs	   *NickNames*   /etc/cups/ppd/(.*).ppd:\*NickName: *"(.*)"s   \g<1>: \g<2>t   PpdFilest   foo2zjss   foomatic-dbs   foomatic-db-engines   foomatic-db-gutenprints   foomatic-db-hpijss   foomatic-filterss   foomatic-guit   hpijst   hplipt   m2300wt   min12xxwt   c2050t   hpojt   pxljrt   pnm2ppat   splixs   hp-ppds
   hpijs-ppdss   linuxprinting.org-ppdss   openprinting-ppdss   openprinting-ppds-extrat   ghostscriptt   cupss   cups-driver-gutenprintt   ijsgutenprints   cupsys-driver-gutenprints   gimp-gutenprints   gutenprint-docs   gutenprint-localess   system-config-printer-commont   kdeprintt   PrintingPackagesN(   R   R>   R   Rg   Rh   t   package_versions(   R   t   ppdst	   nicknames(    (    s4   /usr/lib/python2.7/dist-packages/apport/hookutils.pyt   attach_printingN  s$    					c         C   sM  d } t  j | t  j  } d } t  j | t  j  } t j j d  r^ t d |  |  d <n( t j j d  r t d |  |  d <n  t j j d  r t |  i d | d d	 6 n  t |  d
 d  t |  d d  t  j	 | |  j
 d d   st  j	 | |  j
 d	 d   rI|  j
 d d  } | r8| d 7} n  | d |  d <n  d S(   s0   Attach MAC information and events to the report.s!   audit\(|apparmor|selinux|securitys   apparmor="DENIED"s   /var/log/kern.logt   KernLogs   /var/log/messagess   /var/run/auditd.pids   egrep "s   " /var/log/audit/audit.logt   AuditLogs   /proc/version_signaturet   ProcVersionSignatures   /proc/cmdlinet   ProcCmdlineR   t   Tagst    t   apparmorN(   Rg   R   t
   IGNORECASER   R   R   R   R   R   R   R<   (   R   t	   mac_regext   mac_ret   aa_denied_regext   aa_denied_ret   tags(    (    s4   /usr/lib/python2.7/dist-packages/apport/hookutils.pyt   attach_mac_eventsh  s"    <c         C   s   t  |   |  d <d S(   si   Attach version information for related packages

    In the future, this might also run their hooks.
    t   RelatedPackageVersionsN(   R   (   R   t   packages(    (    s4   /usr/lib/python2.7/dist-packages/apport/hookutils.pyt   attach_related_packages  s    c          G   s  g  } x |  D] } | s q n  t  j |  } | sJ | j | d f  n  xi t |  D][ } y t  j |  } Wn t k
 r d } n X| d k r d } n  | j | | f  qW Wq Wt t g  t	 |   D] } t t
 |  ^ q  \ } } d | }	 d j g  | D] }
 |	 |
 ^ q S(   st   Return a text listing of package names and versions.

    Arguments may be package names or globs, e. g. "foo*"
    s   N/As
   %%-%ds %%ss   
N(   R   t   package_name_globR   t   sortedt   get_versionR2   R   t   mapt   maxt   zipt   lenR   (   R3  t   versionst   package_patternt   matching_packagesR(   R   t   tt   package_widtht   version_widtht   fmtt   v(    (    s4   /usr/lib/python2.7/dist-packages/apport/hookutils.pyR     s$    
	7
c         C   s   t    } xo t d |  g  j d  D]R } y | j d d  \ } } Wn t k
 r] q% n X| j   } | j |  q% W| S(   ss   Returns a list of strings containing the sonames of shared libraries
    with which the specified binary is linked.t   ldds   
s   =>i   (   t   setR>   R   R2   R   t   add(   R   t   libsR   t   libt   rest(    (    s4   /usr/lib/python2.7/dist-packages/apport/hookutils.pyt   shared_libraries  s    	"c         C   sH   t  |   } | | k r t Sx% | D] } | j | d  r# t Sq# Wt S(   s   Returns True if the binary at path links with the library named lib.

    path should be a fully qualified path (e.g. report['ExecutablePath'])
    lib may be of the form 'lib<name>' or 'lib<name>.so.<version>'
    s   .so.(   RJ  R   R3   R   (   R   RH  RG  t
   linked_lib(    (    s4   /usr/lib/python2.7/dist-packages/apport/hookutils.pyt   links_with_shared_library  s      c         C   s   yW t  j d |  g d t  j d t  j } | j   d j d  } | j d k rV d SWn t k
 rk d SXx\ | j   D]N } | j	 d d  } t
 |  d	 k  r qy n  | d d
 k ry | d j   Sqy Wd S(   s-   Return the license for a given kernel module.s   /sbin/modinfoR   R   i    s   UTF-8t   invalidR   i   i   t   licenseN(   R   R   R   R   R   R   RJ   R   t
   splitlinesR   R;  R   (   t   modulet   modinfoRk   Rj   R   (    (    s4   /usr/lib/python2.7/dist-packages/apport/hookutils.pyt   _get_module_license  s    s   /proc/modulesc         C   s   y< t  |   * } g  | D] } | j   d ^ q } Wd QXWn t k
 rP g  SXg  } xa | D]Y } t |  } | r^ d | k p d | k p d | k p d | k r^ | j |  q^ q^ W| S(   sC   Check loaded modules and return a list of those which are not free.i    Nt   GPLt   BSDt   MPLt   MIT(   R   R   R=   RR  R   (   t   module_listR   Rj   t   modst   nonfreet   m(    (    s4   /usr/lib/python2.7/dist-packages/apport/hookutils.pyt   nonfree_kernel_modules  s    -7c         C   s   d } x t  j |   D] } t  j j |  |  } | d k s t  j j |  rV q n  t |  j   j   } | d k r | j d d  } n  | d k r t	 j
 |  } | d 7} n  | d | | f 7} q W| S(	   NR   RD   t   modess   
R)  t   edids   -base64s   %s: %s
(   R   RG   R   R   R   R   R   R   R4   t   base64t	   b64encode(   t   conR\   R   R   t   val(    (    s4   /usr/lib/python2.7/dist-packages/apport/hookutils.pyt   __drm_con_info  s    c         C   s   d } t  j j |  s d Sxj t  j |  D]Y } t  j j | |  } t  j j t  j j | d   r, t |  |  d t |  <q, q, Wd S(   sW   Add information about DRM hardware.

    Collect information from /sys/class/drm/.
    s   /sys/class/drmNt   enableds   DRM.(   R   R   RF   RG   R   R   Rb  R   (   R   t   drm_dirR   R`  (    (    s4   /usr/lib/python2.7/dist-packages/apport/hookutils.pyt   attach_drm_info  s    !c   
      C   s  t  j t  j  } zL y3 t  j t  j d  t j t j |  d   } Wn t k
 r\ d SXWd t  j t  j |  Xy t	 j
 t	 j j d  } t	 j j | t	 j j d d d d d  } | j   } t	 j j | t	 j j d d | d d  } | j   } Wn1 t j k
 r0} t j j d t |   d SXt j d	 |  }	 |	 rpt j t j |	 j d
  d   } n t j j d |  d S| | k S(   s  Check if the problem happened in the currently running XDG session.

    This can be used to determine if e. g. ~/.xsession-errors is relevant and
    should be attached.

    Return None if this cannot be determined due to not being able to talk to
    ConsoleKit.
    R   t   DateNs   org.freedesktop.ConsoleKits#   /org/freedesktop/ConsoleKit/Managers"   org.freedesktop.ConsoleKit.Managers"   org.freedesktop.ConsoleKit.Sessions#   Error connecting to ConsoleKit: %s
s+   (\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d)(?:\.\d+Z)$i   s   %Y-%m-%dT%H:%M:%Ss%   cannot parse time returned by CK: %s
(   R  t	   getlocalet   LC_TIMEt	   setlocalet   timet   mktimet   strptimet   KeyErrorR   R    t   bus_get_synct   BusTypet   SYSTEMt	   DBusProxyt   new_synct   DBusProxyFlagst   NONEt   GetCurrentSessiont   GetCreationTimeR   t   GErrorR   R   R   R   Rg   t   matcht   calendart   timegmt   group(
   R   t
   orig_ctimet   report_timet   bust
   ck_managert   cur_sessiont
   ck_sessiont   session_start_timeR   RZ  (    (    s4   /usr/lib/python2.7/dist-packages/apport/hookutils.pyt   in_session_of_problem
  s8    
  			'c         C   s   d } | s t  |  } n  t j j |  r t | d  N } g  | j   D]! } | j d  sg | n d ^ qL } d j |  |  | <Wd QXn  d S(   s;   attach /etc/default/grub after filtering out password liness   /etc/default/grubt   rt   passwords   ### PASSWORD LINE REMOVED ###R   N(   R   R   R   R   R   t	   readlinesR3   R   (   R   R   R   R   Rj   t   filtered(    (    s4   /usr/lib/python2.7/dist-packages/apport/hookutils.pyt   attach_default_grub:  s    1(O   t   __doc__R   R   R   Rj  Ry  R#   R   Rg   R%   R^  R   R   R  t   gi.repositoryR    R   t   apport.packaging_implR   R   R0   t	   maketransR   t   AttributeErrort   stringR   R   R   R   R   R   R/   R8   RB   RP   Rl   R   Ri   t   STDOUTR   R>   R   R   R   R   R   R   t   PCI_MASS_STORAGER   t   PCI_DISPLAYR   t
   PCI_MEMORYt
   PCI_BRIDGEt   PCI_SIMPLE_COMMUNICATIONSt   PCI_BASE_SYSTEM_PERIPHERALSt   PCI_INPUT_DEVICESt   PCI_DOCKING_STATIONSt   PCI_PROCESSORSt   PCI_SERIAL_BUSR~   R   R   R   R   R   R   R  R#  R1  R4  R   RJ  RL  RR  R[  Rb  Re  R  R  (    (    (    s4   /usr/lib/python2.7/dist-packages/apport/hookutils.pyt   <module>   s   						8	;			)		 	
		 													0