3 ft`@sdZddlmZddlmZddlmZddlmZddlZ ddl Z ddl Z ddl Z e j e jdZe jdZd d Zd d Zd dZddZdS)z/Various utility functions, and a utility class.)absolute_import)unicode_literals) format_number)_N SC_CLK_TCKdnfcCs t|tS)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)Zjiffiesr /usr/lib/python3.6/utils.pyjiffies_to_secondssr cCsj|dkr0d|d |d d|dd|dfS|d krVd|d |dd|dfSd|d|dfS) aReturn 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 <z%d day(s) %d:%02d:%02dz %d:%02d:%02dz %02d:%02diiQiiQiiir )Zsecondsr r r seconds_to_ui_time)s    rcCst|}tjjd| s:tjjd s:tjjd| r>dSi}td|v}xn|D]f}|ddkrhqV|ddjdd}t|dkrqVtjj |dd |d<|dj ||d j j <qVWWdQRXd |krdSd |krdSd}td4}x,|D]$}|j d rt|td d}PqWWdQRX|dkr6dStd|^}|j j}|t|d|d<tdtdtdtdtddj|dtd|d<WdQRX|S)z!Return info dict about a process.z/proc/%d/statusz /proc/statz /proc/%d/statN z: z kBrvmrssvmsizezbtime  start_timeZRunningZSleepingZUninterruptibleZZombiezTraced/Stopped)RSDZTZUnknownstaterr)rospathexistsopensplitlenrutilZrtrimstriplower startswithreadr rget)pidpsZ status_filelinedataZ boot_timeZ stat_fileZps_statr r r get_process_info<sJ   *      r.cCst|}|s$td}tj||dStd||df}tjd|tjtdtt|ddtt|d dtttj|d }tjtd tj j |d |tjtd |d dS)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: %snamez%sz Memory : %5s RSS (%5sB VSZ)rirrz Started: %s - %s agoz State : %sr) r.rloggerZcriticalrrrtimerr$Znormalize_time)r*r+msgZagor r r show_lock_ownerls    r3)__doc__Z __future__rrZdnf.cli.formatrZdnf.i18nrZdnf.utilrZloggingrr1sysconf sysconf_namesr Z getLoggerr0r rr.r3r r r r s      0