ó
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 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 d „  Z e d k r<d d l Z e e j ƒ d k r@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 |  ƒ y t j j d ƒ |  d <Wn t k
 rU n X|  j d ƒ d k rÇ t	 |  ƒ d |  k rÇ t
 j d ƒ } | j | j d } | d k  rÄ d	 | |  d
 <qÄ qÇ n  t |  ƒ xº d d g D]¬ } | |  k rÞ |  | } t |  | ƒ |  d j d ƒ } g  } xU | j d ƒ j ƒ  D]> } | | k rX| j | ƒ q6| | k r6| j | ƒ q6q6Wd j | ƒ }	 qÞ qÞ Wt d ƒ }
 d |  k rËt j d |  d t j ƒ rËt } n t } xB d9 D]: } | |  k rØ|  | j d ƒ rØ|  | d |  | <qØqØW|  j d d ƒ j d ƒ rA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 r<|  d j ƒ  d } | r<t  |  | ƒ q<n  |  j d ƒ d k rÚd" |  k rÚd |  k rÚ|  d j d  d ƒ \ } } d# | | |  d" f } | |  d$ <d |  k r¿|  d } n d |  k rØ|  d } n d  } | rÚd% d& d' d( g } d) } d* } t j | | ƒ s&t j | | ƒ rI|  d+ | k rIt" |  d, ƒ qIn  d- | k r¬t j d. | ƒ } | rœt j j# | j$ d ƒ ƒ rœt d/ ƒ |  d
 <n  t% |  d0 ƒ n  | r×| |	 k rÔt d1 ƒ |  d
 <qÔq×qÚn  t& j' t
 j( ƒ  ƒ j) } t* j+ d2 d3 d4 | d5 g d6 t* j, d7 t* j- ƒd k r8t% |  d8 ƒ n  d  S(:   Nt   apportt   ApportVersiont   ProblemTypet   Packaget   LiveMediaBuilds   /cdromi@B i
   s   Your system partition has less than %s MB of free space available, which leads to problems using applications and installing updates. Please free some space.t   UnreportableReasont   DpkgTerminalLogt   VarLogDistupgradeApttermlogs   
s   UTF-8s  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   ErrorMessages   package:%s:%s:%st   DuplicateSignatures
   memtest86+t   linuxs   ubuntu-metas   virtualbox-osesJ   /etc/kernel/post(inst|rm)\.d/zz-update-grub exited with return code [1-9]+s8   /usr/sbin/grub-mkconfig.*/etc/default/grub: Syntax errort   SourcePackaget   EtcDefaultGrubs   trying to overwrites   in package (.*) sY   An Ubuntu package has a file conflict with a package that is not a genuine Ubuntu packages   package-conflicts?   You have already encountered this package installation failure.t   killalls   -s0s   -us   unity-panel-servicet   stdoutt   stderrs   running-unity(   s   ExecutablePathR   (.   t   add_release_infot   add_kernel_infot   add_cloud_infot   add_proposed_infoR   t	   packagingt   get_versiont
   ValueErrort   gett   check_for_disk_errort   ost   statvfst   f_bavailt   f_frsizet   match_error_messagest   check_attachment_for_errorst   splitt   decodet
   splitlinest   appendt   removet   joint   _t   ret   searcht	   MULTILINEt   Truet   Falset
   startswitht   environt   get_oem_projectt   attach_conffilest   attach_upstart_overridest   Nonet   attach_default_grubt   is_distro_packaget   groupt   add_tagt   pwdt   getpwuidt   geteuidt   pw_namet
   subprocesst   callt   PIPEt   STDOUT(   t   reportR   t   stt   free_mbt   logt   untrimmed_dpkg_logt   trimmed_logt   linest   linet   dpkg_log_without_errort   wrong_grub_msgt   grub_hook_failuret   ft   vt   oem_projectt   packaget   versiont   dupe_sigt   termlogt   UPDATE_BOOTt
   ug_failuret   mkconfig_failuret   conflict_pkgt   username(    (    s)   /usr/share/apport/general-hooks/ubuntu.pyt   add_info   s¨    






		-
		$"c         C   sf   |  j  d ƒ d k rb d |  j  d d ƒ k r: d |  d <n  d |  j  d	 d ƒ k rb d
 |  d <qb 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 configuredR   t   dpkgR   (   R#   (   RI   (    (    s)   /usr/share/apport/general-hooks/ubuntu.pyR)      s
    c   
   	   C   s  |  j  d ƒ d k rt |  ƒ |  d d$ k ró d d d g } x² | D]§ } | |  k rE t j | |  | t j ƒ rE 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
 <qE qE Wn  |  d d k r;| |  k r;t j d |  | t j ƒ r;d |  d
 <q;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 | ƒ }	 |	 r{|	 |  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  | |  k råt j d! |  | t j ƒ 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-probeR   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    R   s   grub-pcsH   This failure was caused by a program which did not originate from Ubuntus7   failed to install/upgrade: corrupted filesystem tarfileRa   R   sR   This failure was caused by a corrupted package download or file system corruption.s/   dpkg-deb: error.*is not a debian format archives#   is already installed and configuredRb   (   Rc   Rd   (   Re   Rf   s   emacs-snapshotRg   (   R#   t   trim_dpkg_logR2   R3   R4   R   R    t   get_file_packageR<   R%   t   patht   existsRS   RR   R+   R?   t   attach_file_if_existsR7   (
   RI   t
   attachmentt   grub_errorst
   grub_errort   grub_packaget   regexRP   t   mRj   RW   (    (    s)   /usr/share/apport/general-hooks/ubuntu.pyR*   ˜   sV    
	((
((
(c   	      C   sr  g  } d |  k r" d |  k r" d  Sd |  k r2 d  S|  d } t  } xˆ | D]€ } | j d ƒ } | j d ƒ s‹ | j d ƒ s‹ | j d ƒ rI | j d ƒ d	 j d
 ƒ } | j d d ƒ } | j | ƒ qI qI W|  j d |  d ƒ } xq | D]i } | j d ƒ } d | k rê d | k rqê n  x3 | D]( } t j | | ƒ r$| } t	 } Pq$q$Wqê qê W| rnd | |  d <n  d  S(   Ns	   Dmesg.txts   CurrentDmesg.txts   Df.txts   
t   /s   /usrs   /vart    i    t
   0123456789s   /dev/R   s	   I/O errors   journal commit I/O errors6   This failure was caused by a hardware error on /dev/%sR	   (
   R6   t   stript   endswithR+   t   replaceR.   R#   R2   R3   R5   (	   RI   t   devs_to_checkt   dft   device_errorRP   t   devicet   dmesgt   devt   error_device(    (    s)   /usr/share/apport/general-hooks/ubuntu.pyR$   Ù   s4    
-c         C   s   t  |  d d ƒ d  S(   Ns   /proc/version_signaturet   ProcVersionSignature(   Rl   (   RI   (    (    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 d d  ƒ} | 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/infoR   t   caspert   CasperVersions   /var/lib/ubuntu_dist_channelt   DistributionChannelDescriptort   lsb_releases   -scR   t   Errors   /var/log/dist-upgrade/main.logs   %Y-%m-%ds"   Upgraded to %s on %s (%d days ago)i€Q t   UpgradeStatuss/   No upgrade log present (probably fresh install)(   Rl   R%   Rj   Rk   R   R    R!   t   command_outputR<   R7   R@   t   statt   st_mtimet   timet   strftimet   gmtime(   RI   t   release_codenameRL   t   mtimet   human_mtimet   delta(    (    s)   /usr/share/apport/general-hooks/ubuntu.pyR   û   s$    			c   	      C   sI  d |  k r d Sy |  d j  ƒ  d  \ } } Wn t k
 rO d |  d GHd SXt j d d | g d t j d t ƒ} | j ƒ  d	 } | j d	 k r£ d
 | GHd St } t } t } xi | j	 ƒ  D][ } | j
 | d ƒ rÂ d | k rð t } n  d | k rt } n  d | k rt } qqÂ qÂ W| rE| rE| rEt |  d ƒ n  d S(   s#   Tag if package comes from -proposedR   Ni   s"   WARNING: malformed Package field: s	   apt-cachet   showpkgR   t   universal_newlinesi    s$   WARNING: apt-cache showpkg %s faileds    (s
   -proposed_s	   -updates_s	   -securitys   package-from-proposed(   R+   R"   RE   t   PopenRG   R5   t   communicatet
   returncodeR6   R-   R7   R@   (	   RI   RW   RX   t	   apt_cachet   outt   found_proposedt   found_updatest   found_securityRP   (    (    s)   /usr/share/apport/general-hooks/ubuntu.pyR     s6    					c   
      C   ss  t  } xB d D]: } y  t j j | ƒ r2 t } Pn  Wq t k
 rF q Xq W| rod } t | d ƒ } y t | d d ƒj ƒ  } Wn d  } n X| d  k r§ d  } qo| j
 d ƒ rYd } t |  d	 ƒ i d
 d 6d d 6d d 6d d 6d d 6} | |  d <xm | j ƒ  D]I \ } }	 y) t t | |	 ƒ d d ƒj ƒ  |  | <Wq	d |  | <q	Xq	Wqod } t |  d ƒ n  d  S(   Ns   ec2-inits
   cloud-inits(   http://169.254.169.254/latest/meta-data/s   ami-idt   timeouti   t   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(   R6   R   R    R!   R5   R"   R    R   t   readR<   R7   R@   t   items(
   RI   t   ec2_instancet   pkgt   metadata_urlt
   ami_id_urlR   t   cloudt   fieldst   keyt   value(    (    s)   /usr/share/apport/general-hooks/ubuntu.pyR   =  sD    
	


c         C   s(   |  j  d d ƒ |  d c d | 7<d  S(   Nt   TagsR   Rt   (   t
   setdefault(   RI   t   tag(    (    s)   /usr/share/apport/general-hooks/ubuntu.pyR@   f  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.
    R„   s   canonical-oem-t   -i   N(   R#   R<   R7   R+   (   RI   t   dcd(    (    s)   /usr/share/apport/general-hooks/ubuntu.pyR9   j  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	   (   R2   t   compileR-   R7   t   matchR.   R0   Rv   (   RI   RO   t   trim_reRP   (    (    s)   /usr/share/apport/general-hooks/ubuntu.pyRh   t  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   R2   R%   t   os.pathRA   R‹   t   urlparseR    t   urllib2R   t   apport.hookutilsR   R1   R`   R)   R*   R$   R   R   R   R   R@   R9   Rh   t   __name__t   syst   lent   argvR   t   exitt   report_filet   ReportRI   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>   sL   <
	x		A			 	"	)		
		