ó
¨M‘Nc           @   s7  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 m	 Z	 d d l
 m Z d d l Td d l m Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e d k r3d d l Z e e j ƒ d k r7e j d e j d IJe j d ƒ n  e j d Z e j  ƒ  Z! e! j" e# e ƒ ƒ e$ e! j% ƒ  ƒ Z& e! j' ƒ  Z( e e( d ƒ e$ e( j% ƒ  ƒ Z* d Z+ x~ e, e& e* Bƒ D]l Z- e- e* k rõe- e& k rõd e- e( e- f GHe+ d 7Z+ q·e- e& k r·e- e* k r·d e- GHe+ d 7Z+ q·q·Wd e+ GHn  d S(   sø  Attach generally useful information, not specific to any package.

Copyright (C) 2009 Canonical Ltd.
Authors: Matt Zimmerman <mdz@canonical.com>,
         Brian Murray <brian@ubuntu.com>

This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.  See http://www.gnu.org/copyleft/gpl.html for
the full text of the license.
iÿÿÿÿN(   t   urljoin(   t   urlopen(   t   *(   t   unicode_gettextc         C   sÿ  t  |  ƒ t |  ƒ t |  ƒ t j j d ƒ |  d <|  j d ƒ d k rV t |  ƒ n  t |  ƒ x0 d d g D]" } | |  k rm t	 |  | ƒ qm qm Wt
 d ƒ } d |  k rÐ t j d |  d t j ƒ rÐ t } n t } xB d- D]: } | |  k rÝ |  | j d ƒ rÝ |  | d |  | <qÝ qÝ W|  j d d ƒ j d ƒ rFd t j d <n  d |  k r |  d j ƒ  d } t |  ƒ } | r d | k s| | k r d |  d <q n  d |  k r|  d j ƒ  d } | rÜt |  | d | ƒn  | d k rd |  d k rd |  d <qn  d |  k rA|  d j ƒ  d } | rAt |  | ƒ qAn  |  j d ƒ d k rd |  k ro|  d }	 n d |  k rˆ|  d }	 n d  }	 |	 rd }
 xý |	 j d ƒ D]é } | j d ƒ sÎ| j d ƒ rÞd | }
 qªn  |
 d | 7}
 d |
 k rª| j d  ƒ rªd! | k rjt j d" | ƒ } | rZt j j | j d ƒ ƒ rZt
 d# ƒ |  d <n  t |  d$ ƒ n  d |
 k s‚d |
 k r“|
 |  d% <Pq“qªqªWqn  t j t j ƒ  ƒ j } t j  d& d' d( | d) g d* t j! d+ t j" ƒd k rût |  d, ƒ n  d  S(.   Nt   apportt   ApportVersiont   ProblemTypet   Packaget   DpkgTerminalLogt   VarLogDistupgradeApttermlogs  Your system was initially configured with grub version 2, but you have removed it from your system in favor of grub 1 without configuring it.  To ensure your bootloader configuration is updated whenever a new kernel is available, open a terminal and run:

  sudo apt-get install grub-pc
s-   ^Not creating /boot/grub/menu.lst as you wisht   ExecutablePatht   InterpreterPaths   /target/i   t    s   update-managert   1t   APPORT_IGNORE_OBSOLETE_PACKAGESi   t   commons   canonical-oemt   CrashDBi    t   uis   upgrade-systems   not installeds¤   You do not have the upgrade-system package installed. Please report package upgrade failures against the package that failed to install, or against upgrade-manager.t   UnreportableReasons   
s
   Setting upt	   Unpackings   %s
s   dpkg: errort    s   trying to overwrites   in package (.*) sY   An Ubuntu package has a file conflict with a package that is not a genuine Ubuntu packages   package-conflictt   DuplicateSignaturet   killalls   -s0s   -us   unity-panel-servicet   stdoutt   stderrs   running-unity(   s   ExecutablePathR   (#   t   add_release_infot   add_kernel_infot   add_cloud_infoR   t	   packagingt   get_versiont   gett   check_for_disk_errort   match_error_messagest   check_attachment_for_errorst   _t   ret   searcht	   MULTILINEt   Truet   Falset
   startswitht   ost   environt   splitt   get_oem_projectt   attach_conffilest   attach_upstart_overridest   Nonet   is_distro_packaget   groupt   add_tagt   pwdt   getpwuidt   geteuidt   pw_namet
   subprocesst   callt   PIPEt   STDOUT(   t   reportR   t   logt   wrong_grub_msgt   grub_hook_failuret   ft   vt   oem_projectt   packaget   termlogt   dupe_sigt   linet   conflict_pkgt   username(    (    s)   /usr/share/apport/general-hooks/ubuntu.pyt   add_info   s~    



		
"
c         C   sa   |  d d k r] d |  j  d d ƒ k r5 d |  d <n  d |  j  d	 d ƒ k r] d
 |  d <q] n  d  S(   NR   R   s7   failed to install/upgrade: corrupted filesystem tarfilet   TitleR   sR   This failure was caused by a corrupted package download or file system corruption.R   s#   is already installed and configuredt   ErrorMessaget   dpkgt   SourcePackage(   R   (   R;   (    (    s)   /usr/share/apport/general-hooks/ubuntu.pyR    r   s
    c   
      C   s×  |  d d k rÓt  |  ƒ |  d d# k rî d d d g } x² | D]§ } | |  k r@ t j | |  | t j ƒ r@ t j j d ƒ } | d  k s¨ | d k rÚ d	 |  | k rÚ d |  d
 <t j	 j
 d ƒ rä t rä t |  d <qä qç d |  d
 <q@ q@ Wn  |  d d k r6| |  k r6t j d |  | t j ƒ r6d |  d
 <q6n  |  d d$ k rÏd } | |  k rÏt j | |  | t j ƒ rÏxU |  | j d ƒ D]= } t j d | ƒ } | rˆ| j d ƒ } t |  | ƒ qˆqˆWqÏn  |  d j d ƒ r†| |  k r†t j d |  | t j ƒ } | r†| j d ƒ } t j j | ƒ }	 |	 rv|	 |  d
 <| j d ƒ |  d <|	 d k r€t r€t |  d <q€qƒd |  d <q†n  d |  j d d ƒ k r«d  |  d <n  d! |  j d d ƒ k rÓd" |  d
 <qÓn  d  S(%   NR   R   t   grubt   grub2s>   ^User postinst hook script \[.*update-grub\] exited with valuesU   ^run-parts: /etc/kernel/post(inst|rm).d/zz-update-grub exited with return code [1-9]+s   ^/usr/sbin/grub-probe: errors   /usr/sbin/update-grubs
   grub-probeRL   s   /boot/grub/grub.cfgR   s   initramfs-toolss   ^update-initramfs: failed for t   emacs22t   emacs23s   emacs-snapshott   xemacs21s+   ^!! Byte-compilation for x?emacs\S+ failed!s   
s   ^!! and attach the file (\S+)i   s   linux-image-s@   ^run-parts: (/etc/kernel/\S+\.d/\S+) exited with return code \d+i    RJ   s   grub-pcsH   This failure was caused by a program which did not originate from Ubuntus7   failed to install/upgrade: corrupted filesystem tarfileRI   R   sR   This failure was caused by a corrupted package download or file system corruption.s#   is already installed and configuredRK   (   RM   RN   (   RO   RP   s   emacs-snapshotRQ   (   t   trim_dpkg_logR#   R$   R%   R   R   t   get_file_packageR/   R)   t   patht   existsR>   R=   R+   R1   t   attach_file_if_existsR(   R   (
   R;   t
   attachmentt   grub_errorst
   grub_errort   grub_packaget   regexRE   t   mRT   RB   (    (    s)   /usr/share/apport/general-hooks/ubuntu.pyR!   }   sR    
	((
((
c         C   s¨  g  } d |  k r" d |  k r" d  Sd |  k r2 d  S|  d } xˆ | D]€ } | j  d ƒ } | j d ƒ s… | j d ƒ s… | j d ƒ rC | j d ƒ d	 j  d
 ƒ } | j d d ƒ } | j | ƒ qC qC W|  j d |  d ƒ } xÄ | D]¼ } | j  d ƒ } d | k rä d | k rqä n  d | k rB| j d ƒ d j  d ƒ } n> d | k r€| j d ƒ d j d ƒ d	 } | j  d
 ƒ } n  | | k r d | |  d <q qä qä Wd  S(   Ns	   Dmesg.txts   CurrentDmesg.txts   Df.txts   
t   /s   /usrs   /varR   i    t
   0123456789s   /dev/R   s	   I/O errors   journal commit I/O errort   JBD2i   t   ,iÿÿÿÿt   -s6   This failure was caused by a hardware error on /dev/%sR   (   t   stript   endswithR+   t   replacet   appendR   (   R;   t   devs_to_checkt   dfRE   t   devicet   dmesgt   error_device(    (    s)   /usr/share/apport/general-hooks/ubuntu.pyR   »   s2    
- c         C   s   t  |  d d ƒ d  S(   Ns   /proc/version_signaturet   ProcVersionSignature(   RV   (   R;   (    (    s)   /usr/share/apport/general-hooks/ubuntu.pyR   Ù   s    c         C   s  t  |  d d ƒ t  |  d d ƒ t j j d ƒ rK t j j d ƒ |  d <n  t  |  d d ƒ t d	 d
 g ƒ } | j d ƒ r… d  } n t
 |  | ƒ d } t j j | ƒ rt j | ƒ j } t j d t j | ƒ ƒ } t j ƒ  | } d | | | d f |  d <n
 d |  d <d  S(   Ns   /var/log/installer/media-infot   InstallationMedias   /cdrom/.disk/infot   LiveMediaBuildt   caspert   CasperVersions   /var/lib/ubuntu_dist_channelt   DistributionChannelDescriptort   lsb_releases   -sct   Errors   /var/log/dist-upgrade/apt.logs   %Y-%m-%ds"   Upgraded to %s on %s (%d days ago)i€Q t   UpgradeStatuss/   No upgrade log present (probably fresh install)(   RV   R)   RT   RU   R   R   R   t   command_outputR(   R/   R2   t   statt   st_mtimet   timet   strftimet   gmtime(   R;   t   release_codenameR<   t   mtimet   human_mtimet   delta(    (    s)   /usr/share/apport/general-hooks/ubuntu.pyR   Ý   s$    			c   
      C   sg  t  } xB d D]: } y  t j j | ƒ r2 t } Pn  Wq t k
 rF q Xq W| rcd } t | d ƒ } y t | ƒ j ƒ  } Wn d  } n X| d  k r¡ d  } qc| j
 d ƒ rMd } t |  d ƒ i d d	 6d
 d 6d d 6d d 6d d 6} | |  d <xg | j ƒ  D]C \ } }	 y# t t | |	 ƒ ƒ j ƒ  |  | <Wqd |  | <qXqWqcd } t |  d ƒ n  d  S(   Ns   ec2-inits
   cloud-inits(   http://169.254.169.254/latest/meta-data/s   ami-idt   amit   ec2s
   ec2-imagess   ami-manifest-patht   Ec2AMIManifests	   kernel-idt	   Ec2Kernels
   ramdisk-idt
   Ec2Ramdisks   instance-typet   Ec2InstanceTypes   placement/availability-zonet   Ec2AvailabilityZonet   Ec2AMIt   unavailablet   uecs
   uec-images(   s   ec2-inits
   cloud-init(   R'   R   R   R   R&   t
   ValueErrorR    R   t   readR/   R(   R2   t   items(
   R;   t   ec2_instancet   pkgt   metadata_urlt
   ami_id_urlR~   t   cloudt   fieldst   keyt   value(    (    s)   /usr/share/apport/general-hooks/ubuntu.pyR   ý   sB    
	


#c         C   s(   |  j  d d ƒ |  d c d | 7<d  S(   Nt   TagsR   R   (   t
   setdefault(   R;   t   tag(    (    s)   /usr/share/apport/general-hooks/ubuntu.pyR2   %  s    c         C   s<   |  j  d d ƒ } | r8 | j d ƒ r8 | j d ƒ d Sd S(   s‡   Determine OEM project name from Distribution Channel Descriptor
    
    Return None if it cannot be determined or does not exist.
    Rp   s   canonical-oem-Ra   i   N(   R   R/   R(   R+   (   R;   t   dcd(    (    s)   /usr/share/apport/general-hooks/ubuntu.pyR,   )  s    c         C   s«   d |  k r d Sg  } t  j d ƒ } xO |  d j ƒ  D]= } | j d ƒ sZ | j | ƒ rf g  } q6 n  | j | ƒ q6 Wd j | ƒ |  d <|  d j ƒ  s§ d |  d <n  d S(   s=   Trim DpkgTerminalLog to the most recent installation session.R   Ns   ^\(.* ... \d+ .*\)$s   Log started: s   
s/   /var/log/apt/term.log does not contain any dataR   (   R#   t   compilet
   splitlinesR(   t   matchRe   t   joinRb   (   R;   t   linest   trim_reRE   (    (    s)   /usr/share/apport/general-hooks/ubuntu.pyRR   3  s    t   __main__i   s-   Usage for testing this hook: %s <report file>i    i   s   +%s: %ss   -%s: (deleted)s   %d items changed(.   t   __doc__t   apport.packagingR   R#   R)   t   os.pathR3   Rw   t   urlparseR    t   urllib2R   t   apport.hookutilsR   R"   RH   R    R!   R   R   R   R   R2   R,   RR   t   __name__t   syst   lent   argvR   t   exitt   report_filet   ReportR;   t   loadt   opent   sett   keyst   report_keyst   copyt
   new_reportR/   t   new_report_keyst   changedt   sortedR‘   (    (    (    s)   /usr/share/apport/general-hooks/ubuntu.pyt   <module>   sJ   <
	]		>			 	(		
		