
    !f@3                     <    d Z ddlZddlZddlZddlZ G d d      Zy)$Abstraction of packaging operations.    Nc                       e Zd ZdZdZd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Z	 ddZed        Zd Zd ZddZd Zd Zd Z	 	 	 	 	 	 	 ddZd Zd Zd ZdZed        Zd Zy)PackageInfor   z/etc/default/apportc                     t        d      )zhReturn the installed version of a package.

        Throw ValueError if package does not exist.
        6this method must be implemented by a concrete subclassNotImplementedErrorselfpackages     2/usr/lib/python3/dist-packages/apport/packaging.pyget_versionzPackageInfo.get_version       
 "D
 	
    c                     t        d      )zoReturn the latest available version of a package.

        Throw ValueError if package does not exist.
        r   r   r
   s     r   get_available_versionz!PackageInfo.get_available_version!   r   r   c                     t        d      )z/Return a list of packages a package depends on.r   r   r
   s     r   get_dependencieszPackageInfo.get_dependencies*       !D
 	
r   c                     t        d      )zkReturn the source package name for a package.

        Throw ValueError if package does not exist.
        r   r   r
   s     r   
get_sourcezPackageInfo.get_source0   r   r   c                     t        d      )zReturn package origin.

        Return the repository name from which a package was installed, or None
        if it cannot be determined.

        Throw ValueError if package is not installed.
        r   r   r
   s     r   get_package_originzPackageInfo.get_package_origin9        "D
 	
r   c                     t        d      )zCheck package origin.

        Return True if the package is a genuine distro package, or False if it
        comes from a third-party source.

        Throw ValueError if package does not exist.
        r   r   r
   s     r   is_distro_packagezPackageInfo.is_distro_packageE   r   r   c                     t        d      )zReturn the architecture of a package.

        This might differ on multiarch architectures (e. g. an i386 Firefox
        package on a x86_64 system)
        r   r   r
   s     r   get_architecturezPackageInfo.get_architectureQ        "D
 	
r   c                     t        d      )zhReturn list of files shipped by a package.

        Throw ValueError if package does not exist.
        r   r   r
   s     r   	get_fileszPackageInfo.get_files[   r   r   c                     t        d      )z/Return list of all modified files of a package.r   r   r
   s     r   get_modified_fileszPackageInfo.get_modified_filesd   r   r   c                     i S )a?  Return modified configuration files of a package.

        Return a file name -> file contents map of all configuration files of
        package. Please note that apport.hookutils.attach_conffiles() is the
        official user-facing API for this, which will ask for confirmation and
        allows filtering.
         r
   s     r   get_modified_conffilesz"PackageInfo.get_modified_conffilesj   s	     	r   Nc                     t        d      )ap  Return the package a file belongs to.

        Return None if the file is not shipped by any package.

        If uninstalled is True, this will also find files of uninstalled
        packages; this is very expensive, though, and needs network access and
        lots of CPU and I/O resources. In this case, map_cachedir can be set to
        an existing directory which will be used to permanently store the
        downloaded maps. If it is not set, a temporary directory will be used.
        Also, release and arch can be set to a foreign release/architecture
        instead of the one from the current system.
        r   r   )r   fileuninstalledmap_cachedirreleasearchs         r   get_file_packagezPackageInfo.get_file_packagev   s     "D
 	
r   c                      t        d      )zuReturn the architecture of the system.

        This should use the notation of the particular distribution.
        r   r   r%   r   r   get_system_architecturez#PackageInfo.get_system_architecture   r   r   c                      y)zReturn a list of default library search paths.

        The entries should be separated with a colon ':', like for
        $LD_LIBRARY_PATH. This needs to take any multiarch directories into
        account.
        z/lib:/usr/libr%   r   s    r   get_library_pathszPackageInfo.get_library_paths   s     r   c                     t        d      )a  Explicitly set a distribution mirror URL.

        This might be called for operations that need to fetch distribution
        files/packages from the network.

        By default, the mirror will be read from the system configuration
        files.
        r   r   )r   urls     r   
set_mirrorzPackageInfo.set_mirror   s     "D
 	
r   c                     t        d      )a  Download source package and unpack it into output_dir.

        This also has to care about applying patches etc., so that output_dir
        will eventually contain the actually compiled source. output_dir needs
        to exist and should be empty.

        If version is given, this particular version will be retrieved.
        Otherwise this will fetch the latest available version.

        If sandbox is given, that sandbox is used to download the source
        package, otherwise it uses the system configuration.

        Return the directory that contains the actual source root directory
        (which might be a subdirectory of output_dir). Return None if the
        source is not available.
        r   r   )r   
srcpackage
output_dirversionsandboxs        r   get_source_treezPackageInfo.get_source_tree   s    " "D
 	
r   c                     t        d      )ztCompare two package versions.

        Return -1 for ver < ver2, 0 for ver1 == ver2, and 1 for ver1 > ver2.
        r   r   )r   ver1ver2s      r   compare_versionszPackageInfo.compare_versions   r   r   c                     	 t        | j                  d      5 }|j                         }ddd       t	        j
                  dt        j                        du S # 1 sw Y   0xY w# t        $ r Y yw xY w)a  Return whether Apport should generate crash reports.

        Signal crashes are controlled by /proc/sys/kernel/core_pattern, but
        some init script needs to set that value based on a configuration file.
        This also determines whether Apport generates reports for Python,
        package, or kernel crashes.

        Implementations should parse the configuration file which controls
        Apport (such as /etc/default/apport in Debian/Ubuntu).
        zutf-8)encodingNTz^\s*enabled\s*=\s*0\s*$)openconfigurationreadOSErrorresearchM)r   config_fileconfs      r   enabledzPackageInfo.enabled   sl    	d((7; *{"'')* yy3T244@DHH* * 		s'   A% AA% A"A% %	A10A1c                     t        d      )zReturn the actual Linux kernel package name.

        This is used when the user reports a bug against the "linux" package.
        r   r   r1   s    r   get_kernel_packagezPackageInfo.get_kernel_package   r   r   c                     t        d      )a  Install packages into a sandbox (for apport-retrace).

        In order to work without any special permissions and without touching
        the running system, this should only download and unpack packages into
        the given root directory, not install them into the system.

        configdir points to a directory with by-release configuration files for
        the packaging system; this is completely dependent on the backend
        implementation, the only assumption is that this looks into
        configdir/release/, so that you can use retracing for multiple
        DistroReleases. As a special case, if configdir is None, it uses the
        current system configuration, and "release" is ignored.

        release is the value of the report's 'DistroRelease' field.

        packages is a list of ('packagename', 'version') tuples. If the version
        is None, it should install the most current available version.

        If cache_dir is given, then the downloaded packages will be stored
        there, to speed up subsequent retraces.

        If permanent_rootdir is True, then the sandbox created from the
        downloaded packages will be reused, to speed up subsequent retraces.

        If architecture is given, the sandbox will be created with packages of
        the given architecture (as specified in a report's "Architecture"
        field). If not given it defaults to the host system's architecture.

        If origins is given, the sandbox will be created with apt data sources
        for foreign origins.

        If install_deps is True, then the dependencies of packages will also
        be installed.

        Return a string with outdated packages, or None if all packages were
        installed.

        If something is wrong with the environment (invalid configuration,
        package servers down, etc.), this should raise a SystemError with a
        meaningful error message.
        r   r   )r   rootdir	configdirr+   packagesverbose	cache_dirpermanent_rootdirarchitectureoriginsinstall_dbginstall_depss               r   install_packageszPackageInfo.install_packages   s    n "D
 	
r   c                     t        d      )z2Return known package names which match given glob.r   r   )r   nameglobs     r   package_name_globzPackageInfo.package_name_glob   r   r   c                      y)zCheck if a package is one which has been allow listed.

        Return True for a package which came from an origin which is listed in
        native-origins.d, False if it comes from a third-party source.
        Fr%   r
   s     r   is_native_origin_packagez$PackageInfo.is_native_origin_package&  s     r   c                     | j                  d      D ]&  }| j                  |      s	 | j                  |       ( y# t        $ r |cY c S w xY w)zReturn a valid package name which is not installed.

        This is only used in the test suite. The default implementation should
        work, but might be slow for your backend, so you might want to
        reimplement this.
        *N)r\   r   r   
ValueErrorr
   s     r   get_uninstalled_packagez#PackageInfo.get_uninstalled_package1  s`     --c2 	G))'2  )	   s   <AAc                 R    | j                  d      r| j                  d      d   } | S )Nz
 GNU/Linux   )maxsplitr   )endswithrsplit)names    r   _sanitize_operating_system_namez+PackageInfo._sanitize_operating_system_nameD  s*     ==&;;;*1-Dr   c                    | j                   r| j                   S 	 t        j                         }| j                  |d         }|j	                  d      }|r|r||f| _         | j                   S t        j                  ddgdt        j                  t        j                  d	      }|j                  j                         j                  d
d      j                         \  }}|j                         |j                         f| _         | j                   S # t
        $ r,}t        j                  j                  | d       Y d}~d}~ww xY w)zReturn (osname, osversion) tuple.

        This is read from /etc/os-release, or if that doesn't exist,
        'lsb_release -sir' output.
        NAME
VERSION_IDz-. Falling back to calling 'lsb_release -sir'.Nlsb_releasez-sirFT)checkstdoutstderrtext
 )_os_versionplatformfreedesktop_os_releaseri   getrE   sysrp   write
subprocessrunPIPEro   stripreplacesplit)r   inforh   r9   errorrm   s         r   get_os_versionzPackageInfo.get_os_versionK  s    ###	V224D77VEDhh|,G$('? '''
 !nnF#????
 &,,224<<T3GMMOw JJL'--/:  	VJJw&STUU	Vs   AD 	E"E  E)FNNN)NN)FNFNNTF)__name__
__module____qualname____doc__rC   r   r   r   r   r   r   r   r!   r#   r&   r-   staticmethodr/   r2   r5   r;   r?   rK   rM   rY   r\   r^   rb   rt   ri   r   r%   r   r   r   r      s    . *M











 NR
& 
 


*
I(
 9
v
	" K  r   r   )r   ru   rF   rz   rx   r   r%   r   r   <module>r      s"    *  	  
V  V r   