a
    !c                     @   s   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlZ	ddl
Z
ddlZddlZeejd Ze
dZd	d
 Zdd Zdd Zdd ZdS )z/Various utility functions, and a utility class.    )absolute_import)unicode_literals)format_number)_N
SC_CLK_TCKdnfc                 C   s   t | t S )zConvert a number of jiffies to seconds. How many jiffies are in a second
    is system-dependent, e.g. 100 jiffies = 1 second is common.

    :param jiffies: a number of jiffies
    :return: the equivalent number of seconds
    )int_USER_HZ)Zjiffies r
   1/usr/lib/python3.9/site-packages/dnf/cli/utils.pyjiffies_to_seconds   s    r   c                 C   sj   | dkr0d| d | d d | d d | d f S | dkrVd| d | d d | d f S d| d | d f S )a  Return a human-readable string representation of the length of
    a time interval given in seconds.

    :param seconds: the length of the time interval in seconds
    :return: a human-readable string representation of the length of
      the time interval
    iQ z%d day(s) %d:%02d:%02di     <   z%d:%02d:%02dz	%02d:%02dr
   )Zsecondsr
   r
   r   seconds_to_ui_time)   s    

r   c                 C   s  t | } tjd|  r4tjdr4tjd|  s8dS i }td|  |}|D ]f}|d dkr`qN|dd dd}t|d	k rqNtj	|d d
|d< |d 
 ||d 
  < qNW d   n1 s0    Y  d|vrdS d|vrdS d}td>}|D ](}|drt |tdd } q(qW d   n1 s>0    Y  |du rVdS td|  h}|  }|t|d  |d< tdtdtdtdtdd|d	 td|d< W d   n1 s0    Y  |S )z!Return info dict about a process.z/proc/%d/statusz
/proc/statz/proc/%d/statN
z:	      z kBr   vmrssvmsizezbtime    
start_timeZRunningZSleepingZUninterruptibleZZombiezTraced/Stopped)RSDZTZUnknownstate)r   ospathexistsopensplitlenr   utilZrtrimstriplower
startswithreadr   r   get)pidpsZstatus_filelinedataZ	boot_timeZ	stat_fileZps_statr
   r
   r   get_process_info<   sR    
<

(
(r.   c                 C   s   t | }|s$td}t||  dS td| |d f }td| ttdtt|d d tt|d	 d  ttt |d
  }ttdtj	
|d
 | ttd|d  dS )z0Output information about process holding a lock.z=Unable to find information about the locking process (PID %d)Nz$  The application with PID %d is: %snamez%sz    Memory : %5s RSS (%5sB VSZ)r   i   r   r   z    Started: %s - %s agoz    State  : %sr   )r.   r   loggerZcriticalr   r   r   timer   r$   Znormalize_time)r*   r+   msgZagor
   r
   r   show_lock_ownerl   s"    

r3   )__doc__Z
__future__r   r   Zdnf.cli.formatr   Zdnf.i18nr   Zdnf.utilr   Zloggingr   r1   sysconfsysconf_namesr	   Z	getLoggerr0   r   r   r.   r3   r
   r
   r
   r   <module>   s   

0