%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/DistUpgrade/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/DistUpgrade/__pycache__/utils.cpython-312.pyc

�

QKfE���ddlZddlZddlZddlZddlZddlZddlZddlZddlmZddl	m	Z
ddl	mZddlm
Z
ddlmZmZmZddlmZddlmZmZmZmZmZddlZddlZej8�Gd	�d
e�ZGd�d�Zd
�Z d�Z!d.d�Z"d�Z#d/d�Z$d�Z%d�Z&d�Z'd�Z(d�Z)d�Z*Gd�de�Z+d.d�Z,d.d�Z-d�Z.d�Z/d�Z0d�Z1d.d �Z2d!�Z3d.d"�Z4d.d#�Z5d$�Z6d%�Z7d&�Z8d'�Z9d(�Z:d)�Z;d*�Z<e=d+k(re6dd,d-�yy)0�N)�copy)�gettext)�ngettext)�ceil)�S_IMODE�S_IXUSR�ST_MODE)�urlsplit)�ProxyHandler�Request�build_opener�install_opener�urlopenc�$�eZdZdZdd�Zd�Zd�Zy)�
ExecutionTimez�
    Helper that can be used in with statements to have a simple
    measure of the timing of a particular block of code, e.g.
    with ExecutionTime("db flush"):
        db.flush()
    c��||_y�N)�info)�selfrs  �3/usr/lib/python3/dist-packages/DistUpgrade/utils.py�__init__zExecutionTime.__init__<s	����	�c�6�tj�|_yr)�time�now�rs r�	__enter__zExecutionTime.__enter__?s���9�9�;��rc�v�t|j�dtj�|jz
���y)Nz: )�printrrr)r�type�value�stacks    r�__exit__zExecutionTime.__exit__Bs"��
�$�)�)�T�Y�Y�[�4�8�8�%;�<�=rN)�)�__name__�
__module__�__qualname__�__doc__rrr#�rrrr4s�����>rrc�(�eZdZdZdZdZdZdZdZdZ	y)	�SoftwarePropertiesPager������N)
r%r&r'�ubuntu_software�other_software�updates�authentication�additional_drivers�developer_options�
ubuntu_pror)rrr+r+Fs'���O��N��G��N������Jrr+c�4�t|�}t|j�}|jr+|jj	|jd�|_|j
r+|jj	|j
d�|_t
|�S)Nzhidden-uzhidden-p)rr
�uri�username�replace�password�str)�entry�tmp�	url_partss   r�)get_string_with_no_auth_from_source_entryrBPsl��
�u�+�C�����!�I�����'�'�/�/�)�"4�"4�j�A�������'�'�/�/�)�"4�"4�j�A����s�8�Orc��d}	ddl}|j�}|jd�}|S#t$rt	j
d�Y|SwxYw)z)return True if Unity is currently runningFrNzcom.canonical.Unityz&could not check for Unity dbus service)�dbus�
SessionBus�name_has_owner�	Exception�logging�	exception)�
unity_runningrD�buss   r�is_unity_runningrLZs]���M�D���o�o����*�*�+@�A�
�����D����B�C���D�s�%+�A
�A
c�d�|stj�}|dkDr�d|z}t|�5}|j�}ddd�j	d�djd�d}||k(ryt
|jd�dj�d�}|dkDr��y#1swY�jxYw)	Nrz
/proc/%s/stat�(r-�)Tr,F)�os�getpid�open�read�	partition�
rpartition�int�split)�processname�pid�	stat_file�stat_f�stat�commands      r�is_child_of_process_namer^gs�����i�i�k��

��'�#�c�)�	�
�)�_�	!���;�;�=�D�	!��.�.��%�a�(�3�3�C�8��;���k�!���$�/�/�#�&�q�)�/�/�1�!�4�5����'��	!�	!�s�B&�&B/c���tjjd�rtjjd�sytjd�tjd�k7S)z&returns True if we are inside a chrootz/procz/proc/1T�/z/proc/1/root)rP�path�existsr\r)rr�
inside_chrootrcwsB���7�7�>�>�'�"�"�'�'�.�.��*C��
�7�7�3�<�2�7�7�>�2�2�2rc��d}|j�D]>}t|�|jd�z
t|�z|kDr|d|zz
}||dzz
}�@|S)z�helpers inspired after textwrap - unfortunately
    we can not use textwrap directly because it break
    packagenames with "-" in them into new lines
    r$�
� )rW�len�rfind)�t�width�subsequent_indent�out�ss     r�wraprn�sd��

�C�
�W�W�Y�����H�s�y�y���&�#�a�&�0�5�8��4�+�+�+�C��q�3�w�����Jrc�b�d}|jd�}|D]}t|fi|��}||dzz
}�|S)Nr$re)rWrn)rm�kwargs�msg�paras�pars     r�twraprt�sF��
�C�
�G�G�D�M�E�����������q�4�x�����Jrc�<�g}tjjd�sgStjdgtj
d��}|j
�djd�}|d=|D]'}|s�|j|j�d��)|S)z;return list of loaded modules (or [] if lsmod is not found)z/sbin/lsmodT��stdout�universal_newlinesrre)	rPrarb�
subprocess�Popen�PIPE�communicaterW�append)�modules�p�lines�lines    r�lsmodr��s����G�
�7�7�>�>�-�(��	����	��
���D�	�A�
�M�M�O�A��$�$�T�*�E�
�a���,����N�N�4�:�:�<��?�+�,��Nrc���tjj|�syttj|�t
�}|tztk(stj||tz�yy)zAcheck if a given binary has the executable bit and if not, add itN)rPrarbrr\r	r�chmod)ra�modes  r�check_and_fix_xbitr��sO��
�7�7�>�>�$����2�7�7�4�=��)�*�D�
�G�^��'�
����t�g�~�&�
(rc�.�ddi}dtjvrytjdj�}|dd|vr||ddSd|vrC|jd�djd�d	}d
|vr|jd
�d}|dzS|dddzS)z8helper to get the country mirror from the current locale�cr$�LANGNr0�_�.rr,�@r-)rP�environ�lowerrW)�lang_mirror�lang�countrys   r�country_mirrorr��s�����)�K�
�R�Z�Z���
�:�:�f��#�#�%�D��B�Q�x�;���4���8�$�$�
�d�{��*�*�S�/�!�$�*�*�3�/��2���'�>��m�m�C�(��+�G���}���B�Q�x�#�~�rc���tjjd�}|rtjd|z�|Stj�}|jdd�S)z0return the codename of the current runing distro�META_RELEASE_FAKE_CODENAMEzQusing fake release name '%s' (because of META_RELEASE_FAKE_CODENAME environment) �VERSION_CODENAME�unknown distribution�rPr��getrH�warning�platform�freedesktop_os_release)�dist�
os_releases  r�get_distr��s[���:�:�>�>�6�7�D�����
7�9=�
>�	
����0�0�2�J��>�>�,�.D�E�Erc���tjjd�}|rtjd|z�|Stj�}|jdd�S)z0return the version of the current running distro�META_RELEASE_FAKE_VERSIONzSusing fake release version '%s' (because of META_RELEASE_FAKE_VERSION environment) �
VERSION_IDr�r�)�descr�s  r�get_dist_versionr��sZ���:�:�>�>�5�6�D�����
6�8<�
=�	
����0�0�2�J��>�>�,�(>�?�?rc��eZdZd�Zy)�HeadRequestc��y)N�HEADr)rs r�
get_methodzHeadRequest.get_method�s��rN)r%r&r'r�r)rrr�r��s��rr�c
���|sd�|d|z�t|�\}}}}}|d|�d|�d|�d|�d|�d��|d	vr6	tt|��}|j�|jd
k(ryy|dk(r�ddl}		|	j|�}
|
j�|
jtjj|��|
jtjj|��}|
j�|r|d|z�|dk7ry	yy#t
$r}|d
|z�Yd}~yd}~wwxYw#t
$r}|r|d|z�Yd}~yd}~wwxYw)z�
    helper that checks if the given uri exists and is downloadable
    (supports optional debug_func function handler to support
     e.g. logging)

    Supports http (via HEAD) and ftp (via size request)
    c��y)NTr))�xs r�<lambda>z"url_downloadable.<locals>.<lambda>�s�rzurl_downloadable: %szs='z' n='z' p='z' q='z' f='�')�http�https��TFzerror from httplib: '%s'N�ftprzftplib.size() returned: %szerror from ftplib: '%s')r
rr��close�coderG�ftplib�FTP�login�cwdrPra�dirname�size�basename�quit)r:�
debug_func�scheme�netlocra�querry�fragment�	http_file�er��fr�s            r�url_downloadabler��sS�����%��+�,�/7��}�,�V�V�T�6�8���6�4���	3���"�"�	���C� 0�1�I��O�O���~�~��$���
�5���
	��
�
�6�"�A�
�G�G�I�
�E�E�"�'�'�/�/�$�'�(��6�6�"�'�'�*�*�4�0�1�D�
�F�F�H���7�$�>�?��q�y�����)�	��1�A�5�6���	�� �	���4�q�8�9���	�s0�3D!�>BE�!	D?�*D:�:D?�	E"�
E�E"c��d}i}tjjd�dk7r#tjjd�|d<n�tjj|�rytj�}tj||�|jdd�}|r;|jd�}t|jd��}|r|rd	|�d
|�d�|d<tjjd�dk7r#tjjd�|d
<nd|vr|d|d
<|r�|j�D]8}tjd|�r�td|ztj ��yt#|�}t%|�}	t'|	�d|vrtj(d|d�d
|vrtj(d|d
�|S)z�init proxy settings

    * use apt.conf http proxy if present,
    * otherwise look into synaptics config file,
    * otherwise the default behavior will use http_proxy environment
      if present
    z/root/.synaptic/synaptic.confzAcquire::http::Proxyr$r�zSynaptic::useProxyFzSynaptic::httpProxyzSynaptic::httpProxyPortzhttp://�:r`zAcquire::https::Proxyr�zhttps?://\w+zproxy '%s' looks invalid)�fileN�
http_proxy�https_proxy)�apt_pkg�config�findrPrarb�
Configuration�read_config_file�find_br>�find_i�values�re�matchr�sys�stderrrr
r�putenv)
�	gsettings�SYNAPTIC_CONF_FILE�proxies�cnf�	use_proxy�
proxy_host�
proxy_port�proxy�
proxy_support�openers
          r�
init_proxyr�s���9���G��~�~���1�2�b�8�!�.�.�-�-�.D�E����	�����*�	+��#�#�%��� � ��&8�9��J�J�3�U�;�	�����"7�8�J��S�Z�Z�(A�B�C�J��j�5?��"L�����~�~���2�3�r�9�"�>�>�.�.�/F�G����	�7�	�"�6�?������^�^�%�	�E��8�8�O�U�3��0�5�8�s�z�z�J��	�%�W�-�
��m�,���v���W���I�I�l�G�F�O�4��g���I�I�m�W�W�%5�6��Nrc��	ddl}|j|jj�}	|jdd�}|j	|d�}|jdd�S#|jj$rR}d}|j|k7r�|jdd	�}|j	|d�}|jdd
�cYd}~Sd}~wwxYw#t$rYywxYw)z�
    Check via dbus if the system is running on battery.
    This function is using UPower per default, if UPower is not
    available it falls-back to DeviceKit.Power.
    rNzorg.freedesktop.UPowerz/org/freedesktop/UPowerzorg.freedesktop.DBus.Properties�	OnBatteryz)org.freedesktop.DBus.Error.ServiceUnknownzorg.freedesktop.DeviceKit.Powerz /org/freedesktop/DeviceKit/Power�
on_batteryF)
rD�Bus�TYPE_SYSTEM�
get_object�	Interface�Get�
exceptions�
DBusException�_dbus_error_namerG)rDrK�devobj�devr��
error_unknowns      rr�r�Es������h�h�t�x�x�+�+�,��	L��^�^�(�*C��F��.�.��)J�K�C��7�7�3�[�A�A�����,�,�		L�G�M��!�!�]�2���^�^�1�2��F��.�.��)J�K�C��7�7�<�l�K�K��		L������s;�)C�5A"�"C
�;AC�C
�C�C
�
C�	C�Cc�&�	ddlm}m}|j|jj
�}|j
dddd|jdd�d	dd
d	d	�
\}}|j|j�|d��}|S#t$rYywxYw)
z�
    Send a dbus signal to logind to not suspend the system, it will be
    released when the return value drops out of scope
    r)�Gio�GLibzorg.freedesktop.login1z/org/freedesktop/login1zorg.freedesktop.login1.Manager�Inhibitz(ssss))zshutdown:sleep�
UpdateManagerzUpdating System�blockN���)�fdF)�
gi.repositoryr�r��bus_get_sync�BusType�SYSTEM�call_with_unix_fd_list_sync�Variant�UnixInputStream�	steal_fdsrG)r�r��
connection�var�fdlist�	inhibitors      r�
inhibit_sleepres���
�+��%�%�c�k�k�&8�&8�9�
� �<�<�$�%�,���L�L���
�
�
����%
���V�(�'�'�6�+;�+;�+=�c�!�f�+E�'�F�	��������s�BB�	B�Bc�6�|dk(s|j�dk(ryy)N�0�FALSEFT)�upper)r>s r�str_to_boolr	�s��
�c�z�S�Y�Y�[�G�+��rc��ddl}	tj�\}}|S#t$r|jd�YywxYw)Nrzgedefaultlocale() failed)rH�locale�getdefaultlocalerGrI)rH�locale_s�encodings   r�get_langr�sE����%�6�6�8���8����������4�5���s��=�=c�D�t|��}|jdd�dS)z4try to guess the flavor based on the running desktop��cache�-r,r)�get_ubuntu_flavor_packagerW)r�pkgs  r�get_ubuntu_flavorr�s$��
$�%�
0�C��9�9�S�!��Q��rc�B�ddlm}|d�}|jdd�S)Nr)�DistUpgradeConfigz"/usr/share/ubuntu-release-upgrader�Distro�MetaPkgs)�#DistUpgrade.DistUpgradeConfigParserr�getlist)r�parsers  r�_load_meta_pkg_listr�s$��F�
�C�
D�F��>�>�(�J�/�/rc�
�dg}	|jtt���|�tj�}|D] }||vr||nd}|s�|js�|cSy#t$r}t	d|�Yd}~�Vd}~wwxYw)z@try to guess the flavor metapackage based on the running desktopzubuntu-desktopz%Could not load list of meta packages:N)�extend�sortedrrGr�apt�Cache�is_installed)r�	meta_pkgsr��meta_pkg�	cache_pkgs     rrr�s���
"�"�I�:����� 3� 5�6�7�
�}��	�	������'/�5�'8�E�(�O�d�	���/�/��O�����:�
�5�q�9�9��:�s�"A#�#	B�,A=�=Bc���t|��}ddi}||vr||S|jd�rt|jdd�d�S|jd�rt|jdd�d�Sy)	z9try to guess the flavor name based on the running desktoprzubuntustudio-desktopz
Ubuntu Studioz-desktopr,rz-netbook�Ubuntu)r�endswith�capitalize_first_word�rsplit)rr�lookups   r�get_ubuntu_flavor_namer.�sx��
#�%�
0�C�$�o�
6�F�
�f�}��c�{��	���j�	!�$�S�Z�Z�
�A�%>�q�%A�B�B�	���j�	!�$�S�Z�Z�
�A�%>�q�%A�B�B�rc��ddl}|jdd�ddlm}m}|j||jj|jj|jj��}|jd|�d|���|j�|j�j|j j"�|j%d�|j'�|j)�y	)
Nr�Gtkz3.0)�Gdkr0)�parent�flagsr �buttonsz<big><b>z</b></big>

r$F)�gi�require_versionr�r1r0�
MessageDialog�DialogFlags�MODAL�MessageType�ERROR�ButtonsType�CLOSE�
set_markup�realize�
get_window�
set_functions�
WMFunction�MOVE�	set_title�run�destroy)r2�summary�messager5r1r0�ds       r�errorrJ�s���
����u�e�$�&������o�o�#�#�
�_�_�
"�
"����%�%�		�	�A��L�L��'�B�C��I�I�K��L�L�N� � ����!4�!4�5��K�K��O��E�E�G��I�I�K�rc��|dkr2tt|td�z��}tdd|�d|izSt	j
t
d�|dzdz�S)zG
    Convert a given size in bytes to a nicer better readable unit
    i@Bi�z
%(size).0f kBr�z%.1f MBg@�@)rVr�floatrr�
format_stringr�)�bytes�
size_in_kbs  r�
humanize_sizerP�si��

�{����e�e�D�k�1�2�3�
����*�E��J�I
�
�	
�
�#�#�A�i�L�%�&�.�6�2I�J�Jrc�@�tjjd�S)NzAPT::Architecture)r�r�r�r)rr�get_archrR�s���>�>���2�3�3rc�<�d}d}d}td�5}|j�D]b}|j�}|s�|j�}||}||k7r�1||jd�d}t	|d�}	|	|k(s�Zddd�y	ddd�y	#1swYy	xYw)
z>check if the current system is listening on the given tcp portr,r.�0Az
/proc/net/tcpr��NTF)rR�	readlines�striprWrV)
�port�INDEX_LOCAL_ADDR�INDEX_STATE�STATE_LISTENING�net_tcpr�r��state�local_port_str�
local_ports
          r�is_port_already_listeningr`�s������K��O�	
�o�	��'��%�%�'�	�D��:�:�<�D����Z�Z�\�F��;�'�E���'��#�$4�5�;�;�C�@��C�N��^�R�0�J��T�!����	�� �!� �s�A*B�=B�B�Bc�
�d}tj�dk7rtd��tjj	d�sytjddgt
jd�	�j�d}||k(ryy)
z!Return True if iptables is activez�Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
rz%Need root to check the iptables statez/sbin/iptablesF�iptablesz-nLTrv)	rP�getuid�OSErrorrarbryrzr{r|)�iptables_emptyrls  r�iptables_activerfsw���N�
�y�y�{�a���=�>�>�
�7�7�>�>�*�+��
�
�
�	�U��J�O�O����k�m�A��C��n���rc��t|�dkDr?|dj�r,|dj�s|dj�|ddzS|S)z-this uppercases the first word's first letterr,rN)rg�isalpha�isupper�
capitalize)�strings rr+r+1sN��
�6�{�Q��6�!�9�,�,�.�v�a�y�7H�7H�7J��a�y�#�#�%��q�r�
�2�2��Mrc�F�t|jdd�}t|�S)zSthis takes a package synopsis and uppercases the first word's
    first letter
    rGr$)�getattr�	candidater+)r�names  r�get_package_labelrp8s!���3�=�=�)�R�0�D� ��&�&r�__main__�bar�bazr)�Fr$)>rrHrPr�r�ryr�rrrr�r�mathrr\rrr	�urllib.parser
�urllib.requestrrr
rrr"r��init_config�objectrr+rBrLr^rcrnrtr�r�r�r�r�r�r�r�r�rr	rrrrr.rJrPrRr`rfr+rpr%r)rr�<module>rzs&��0��	��	��
��� ���*�*�!����������>�F�>�$���
�
� 3�
���&'��,F�@��'��
+�\)�X�@#�L�� �0��*��*K�$4��8�0�'��z��

�$��u��r

Zerion Mini Shell 1.0