Skip to content

Commit 7fc5d13

Browse files
fix : some functions moved to orangetool_utils.py
1 parent 19c1421 commit 7fc5d13

File tree

4 files changed

+72
-71
lines changed

4 files changed

+72
-71
lines changed

orangetool/orangetool_ram.py

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,7 @@
22
"""Orangetool RAM functions."""
33
import psutil
44
from .orangetool_params import GENERAL_ERROR_MESSAGE
5-
6-
7-
def convert_bytes(num):
8-
"""
9-
Convert num to idiomatic byte unit.
10-
11-
:param num: the input number.
12-
:type num:int
13-
:return: str
14-
>>> convert_bytes(200)
15-
'200.0 bytes'
16-
>>> convert_bytes(6000)
17-
'5.9 KB'
18-
>>> convert_bytes(80000)
19-
'78.1 KB'
20-
"""
21-
for x in ['bytes', 'KB', 'MB', 'GB', 'TB']:
22-
if num < 1024.0:
23-
return "%3.1f %s" % (num, x)
24-
num /= 1024.0
25-
5+
from .orangetool_utils import convert_bytes
266

277
def ram_total(convert=True):
288
"""

orangetool/orangetool_storage.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import subprocess as sub
44
import os
55
import string
6-
import random
76
from .orangetool_params import GENERAL_ERROR_MESSAGE, ROOT_ERROR_MESSAGE
7+
from .orangetool_utils import random_generator
88

99

1010
def mount_status(device_name, debug=False):
@@ -105,23 +105,6 @@ def unmount_all(debug=False):
105105
print(str(e))
106106
return GENERAL_ERROR_MESSAGE
107107

108-
109-
def random_generator(number):
110-
"""
111-
Generate random number.
112-
113-
:param number: random number digits
114-
:type number: int
115-
:return: random number as str
116-
"""
117-
response = ""
118-
i = 0
119-
while(i < number):
120-
i += 1
121-
response += str(random.randint(0, 9))
122-
return response
123-
124-
125108
def mount(device_name, mount_address=None, debug=False):
126109
"""
127110
Mount memory devices by addresses.

orangetool/orangetool_system.py

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"""Orangetool system functions."""
33
import subprocess as sub
44
from .orangetool_params import ORANGETOOL_VERSION, UPDATE_URL, GENERAL_ERROR_MESSAGE, ROOT_ERROR_MESSAGE
5+
from .orangetool_utils import time_convert
56
import time
67
import requests
78
from art import tprint
@@ -53,38 +54,6 @@ def get_temp(zone=0, debug=False):
5354
print(str(e))
5455
return GENERAL_ERROR_MESSAGE
5556

56-
57-
def zero_insert(input_string):
58-
"""
59-
Get a string as input if input is one digit add a zero.
60-
61-
:param input_string: input digit az string
62-
:type input_string:str
63-
:return: modified output as str
64-
"""
65-
if len(input_string) == 1:
66-
return "0" + input_string
67-
return input_string
68-
69-
70-
def time_convert(input_string):
71-
"""
72-
Convert input_string from sec to DD,HH,MM,SS Format.
73-
74-
:param input_string: input time string in sec
75-
:type input_string:str
76-
:return: converted time as string
77-
"""
78-
input_sec = float(input_string)
79-
input_minute = input_sec // 60
80-
input_sec = int(input_sec - input_minute * 60)
81-
input_hour = input_minute // 60
82-
input_minute = int(input_minute - input_hour * 60)
83-
input_day = int(input_hour // 24)
84-
input_hour = int(input_hour - input_day * 24)
85-
return zero_insert(str(input_day)) + " days, " + zero_insert(str(input_hour)) + " hour, " + \
86-
zero_insert(str(input_minute)) + " minutes, " + zero_insert(str(input_sec)) + " seconds"
87-
8857
def time_control(mode="uptime",debug=False):
8958
"""
9059
Return system time.

orangetool/orangetool_utils.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# -*- coding: utf-8 -*-
2+
"""Orangetool utils."""
3+
import random
4+
5+
def zero_insert(input_string):
6+
"""
7+
Get a string as input if input is one digit add a zero.
8+
9+
:param input_string: input digit az string
10+
:type input_string:str
11+
:return: modified output as str
12+
"""
13+
if len(input_string) == 1:
14+
return "0" + input_string
15+
return input_string
16+
17+
18+
def time_convert(input_string):
19+
"""
20+
Convert input_string from sec to DD,HH,MM,SS Format.
21+
22+
:param input_string: input time string in sec
23+
:type input_string:str
24+
:return: converted time as string
25+
"""
26+
input_sec = float(input_string)
27+
input_minute = input_sec // 60
28+
input_sec = int(input_sec - input_minute * 60)
29+
input_hour = input_minute // 60
30+
input_minute = int(input_minute - input_hour * 60)
31+
input_day = int(input_hour // 24)
32+
input_hour = int(input_hour - input_day * 24)
33+
return zero_insert(str(input_day)) + " days, " + zero_insert(str(input_hour)) + " hour, " + \
34+
zero_insert(str(input_minute)) + " minutes, " + zero_insert(str(input_sec)) + " seconds"
35+
36+
37+
def random_generator(number):
38+
"""
39+
Generate random number.
40+
41+
:param number: random number digits
42+
:type number: int
43+
:return: random number as str
44+
"""
45+
response = ""
46+
i = 0
47+
while(i < number):
48+
i += 1
49+
response += str(random.randint(0, 9))
50+
return response
51+
52+
def convert_bytes(num):
53+
"""
54+
Convert num to idiomatic byte unit.
55+
56+
:param num: the input number.
57+
:type num:int
58+
:return: str
59+
>>> convert_bytes(200)
60+
'200.0 bytes'
61+
>>> convert_bytes(6000)
62+
'5.9 KB'
63+
>>> convert_bytes(80000)
64+
'78.1 KB'
65+
"""
66+
for x in ['bytes', 'KB', 'MB', 'GB', 'TB']:
67+
if num < 1024.0:
68+
return "%3.1f %s" % (num, x)
69+
num /= 1024.0

0 commit comments

Comments
 (0)