@@ -85,24 +85,38 @@ def time_convert(input_string):
8585 return zero_insert (str (input_day )) + " days, " + zero_insert (str (input_hour )) + " hour, " + \
8686 zero_insert (str (input_minute )) + " minutes, " + zero_insert (str (input_sec )) + " seconds"
8787
88-
89- def uptime (debug = False ):
88+ def time_control (mode = "uptime" ,debug = False ):
9089 """
91- Return system uptime .
90+ Return system time .
9291
92+ :param mode: time mode (uptime / idle)
93+ :type mode: str
9394 :param debug: flag for using debug mode
9495 :type debug:bool
95- :return: system uptime as string
96+ :return: system time as string
9697 """
98+ index = 0
99+ if mode in ["idle" ,"idletime" ]:
100+ index = 1
97101 try :
98102 command = open ("/proc/uptime" )
99103 response = command .read ()
100- return time_convert (response [:- 1 ].split (" " )[0 ])
104+ return time_convert (response [:- 1 ].split (" " )[index ])
101105 except Exception as e :
102106 if debug :
103107 print (str (e ))
104108 return GENERAL_ERROR_MESSAGE
105109
110+ def uptime (debug = False ):
111+ """
112+ Return system uptime.
113+
114+ :param debug: flag for using debug mode
115+ :type debug:bool
116+ :return: system uptime as string
117+ """
118+ time_control (mode = "uptime" ,debug = debug )
119+
106120
107121def idletime (debug = False ):
108122 """
@@ -112,14 +126,7 @@ def idletime(debug=False):
112126 :type debug:bool
113127 :return: system idle as string
114128 """
115- try :
116- command = open ("/proc/uptime" )
117- response = command .read ()
118- return time_convert (response [:- 1 ].split (" " )[1 ])
119- except Exception as e :
120- if debug :
121- print (str (e ))
122- return GENERAL_ERROR_MESSAGE
129+ time_control (mode = "idle" , debug = debug )
123130
124131
125132def version ():
0 commit comments