Skip to content

Commit 56440e9

Browse files
Merge pull request #37 from Moduland/debug
Debug
2 parents b3122f1 + f57eb44 commit 56440e9

File tree

8 files changed

+116
-134
lines changed

8 files changed

+116
-134
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77
## [Unreleased]
88
### Added
99
- `FUNDING.yml`
10+
- `__version__` variable
1011
- `hibernate` function
1112
### Changed
1213
- `dev-requirements.txt` modified
1314
- Test system modified
15+
- `DEBUG` parameter renamed to `debug`
1416
## [0.35] - 2019-06-01
1517
### Added
1618
- `version_check.py`

orangetool/__init__.py

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,10 @@
11
# -*- coding: utf-8 -*-
22
"""Orangetool modules."""
3-
"""
4-
MIT License
5-
6-
Copyright (c) 2017 Moduland Co
7-
8-
Permission is hereby granted, free of charge, to any person obtaining a copy
9-
of this software and associated documentation files (the "Software"), to deal
10-
in the Software without restriction, including without limitation the rights
11-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12-
copies of the Software, and to permit persons to whom the Software is
13-
furnished to do so, subject to the following conditions:
14-
15-
The above copyright notice and this permission notice shall be included in all
16-
copies or substantial portions of the Software.
17-
18-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24-
SOFTWARE.
25-
"""
263

274
from .orangetool_display import *
285
from .orangetool_ip import *
296
from .orangetool_system import *
307
from .orangetool_ram import *
318
from .orangetool_storage import *
9+
10+
__version__ = ORANGETOOL_VERSION

orangetool/orangetool_display.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
"""Orangetool display functions."""
33

44

5-
def hdmi_controller(command, DEBUG=False):
5+
def hdmi_controller(command, debug=False):
66
"""
77
Control hdmi port.
88
99
:param command: inpurt command
1010
:type command: bool
11-
:param DEBUG: flag for using Debug mode
12-
:type DEBUG: bool
11+
:param debug: flag for using debug mode
12+
:type debug: bool
1313
:return: bool
1414
"""
1515
try:
@@ -21,43 +21,43 @@ def hdmi_controller(command, DEBUG=False):
2121
hdmi_control.close()
2222
return True
2323
except Exception as e:
24-
if DEBUG:
24+
if debug:
2525
print(str(e))
2626
return "Error"
2727

2828

29-
def hdmi_on(DEBUG=False):
29+
def hdmi_on(debug=False):
3030
"""
3131
Turn on hdmi port (need sudo -s).
3232
33-
:param DEBUG: flag for using Debug mode
34-
:type DEBUG:bool
33+
:param debug: flag for using debug mode
34+
:type debug:bool
3535
:return: bool
3636
"""
37-
hdmi_controller(True, DEBUG)
37+
hdmi_controller(True, debug)
3838

3939

40-
def hdmi_off(DEBUG=False):
40+
def hdmi_off(debug=False):
4141
"""
4242
Turn off hdmi port (need sudo -s).
4343
44-
:param DEBUG: flag for using Debug mode
45-
:type DEBUG:bool
44+
:param debug: flag for using debug mode
45+
:type debug:bool
4646
:return: bool
4747
"""
48-
hdmi_controller(False, DEBUG)
48+
hdmi_controller(False, debug)
4949

5050

51-
def hdmi_size(v=None, h=None, DEBUG=False):
51+
def hdmi_size(v=None, h=None, debug=False):
5252
"""
5353
Change hdmi display resolution (need sudo -s) (if call without any argument return current resolution).
5454
5555
:param v: vertical line
5656
:param h: horizental line
57-
:param DEBUG: flag for using Debug mode
57+
:param debug: flag for using debug mode
5858
:type v : int
5959
:type h:int
60-
:type DEBUG:bool
60+
:type debug:bool
6161
:return: bool
6262
"""
6363
try:
@@ -71,6 +71,6 @@ def hdmi_size(v=None, h=None, DEBUG=False):
7171
hdmi_control.close()
7272
return True
7373
except Exception as e:
74-
if DEBUG:
74+
if debug:
7575
print(str(e))
7676
return "Error"

orangetool/orangetool_ip.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import requests
88
import re
99
import platform
10-
ip_pattern = r"(?:[0-9]{1,3}\.){3}[0-9]{1,3}"
11-
api_1 = "http://ipinfo.io/ip"
10+
IP_PATTERN = r"(?:[0-9]{1,3}\.){3}[0-9]{1,3}"
11+
GLOBAL_IP_API_1 = "http://ipinfo.io/ip"
1212

1313

1414
def internet(host="8.8.8.8", port=53, timeout=3):
@@ -36,12 +36,12 @@ def internet(host="8.8.8.8", port=53, timeout=3):
3636
return False
3737

3838

39-
def local_ip(DEBUG=False):
39+
def local_ip(debug=False):
4040
"""
4141
Return local ip of computer in windows by socket module and in unix with hostname command in shell.
4242
43-
:param DEBUG:flag for using Debug Mode
44-
:type DEBUG:bool
43+
:param debug:flag for using debug Mode
44+
:type debug:bool
4545
:return: local ip as string
4646
"""
4747
try:
@@ -62,32 +62,32 @@ def local_ip(DEBUG=False):
6262
return "Error"
6363

6464
except Exception as e:
65-
if DEBUG:
65+
if debug:
6666
print(str(e))
6767
return "Error"
6868

6969

70-
def global_ip(DEBUG=False):
70+
def global_ip(debug=False):
7171
"""
7272
Return ip with by http://ipinfo.io/ip api.
7373
74-
:param DEBUG:flag for using Debug mode
75-
:type DEBUG:bool
74+
:param debug:flag for using debug mode
75+
:type debug:bool
7676
:return: global ip as string
7777
"""
7878
try:
7979
new_session = requests.session()
80-
response = new_session.get(api_1)
81-
ip_list = re.findall(ip_pattern, response.text)
80+
response = new_session.get(GLOBAL_IP_API_1)
81+
ip_list = re.findall(IP_PATTERN, response.text)
8282
new_session.close()
8383
return ip_list[0]
8484
except Exception as e:
85-
if DEBUG:
85+
if debug:
8686
print(str(e))
8787
return "Error"
8888

8989

90-
def set_ip(ip, restart=False, device="eth0", DEBUG=False):
90+
def set_ip(ip, restart=False, device="eth0", debug=False):
9191
"""
9292
Set static ip in interfaces file (need sudo).
9393
@@ -97,8 +97,8 @@ def set_ip(ip, restart=False, device="eth0", DEBUG=False):
9797
:type device:str
9898
:param ip: static ip
9999
:type ip :str
100-
:param DEBUG: flag for using Debug mode
101-
:type DEBUG:bool
100+
:param debug: flag for using debug mode
101+
:type debug:bool
102102
:return: True in successful
103103
"""
104104
static_string = '''
@@ -111,7 +111,7 @@ def set_ip(ip, restart=False, device="eth0", DEBUG=False):
111111
dns-nameservers 8.8.8.8 8.8.4.4
112112
'''
113113
try:
114-
if bool(re.match(ip_pattern, ip)) == False or ip.find(
114+
if bool(re.match(IP_PATTERN, ip)) == False or ip.find(
115115
"192.168.") == -1 or device not in mac().keys():
116116
raise Exception("IP Formation Error")
117117
static_string = static_string.replace("ip", ip)
@@ -125,25 +125,25 @@ def set_ip(ip, restart=False, device="eth0", DEBUG=False):
125125
restart_func()
126126
return True
127127
except Exception as e:
128-
if DEBUG:
128+
if debug:
129129
print(str(e))
130130
return "Error"
131131

132132

133-
def ping(ip, packet_number=3, DEBUG=False):
133+
def ping(ip, packet_number=3, debug=False):
134134
"""
135135
Ping ip and return True if this ip is available and False otherwise.
136136
137137
:param ip: target ip
138138
:param packet_number: number of packet to size
139-
:param DEBUG: flag for using Debug mode
139+
:param debug: flag for using debug mode
140140
:type ip :str
141141
:type packet_number:int
142-
:type DEBUG:bool
142+
:type debug:bool
143143
:return: a boolean value (True if ip is available and False otherwise)
144144
"""
145145
try:
146-
if re.match(ip_pattern, ip) == False:
146+
if re.match(IP_PATTERN, ip) == False:
147147
raise Exception("IP Formation Error")
148148
output = str(list(sub.Popen(["ping",
149149
ip,
@@ -155,17 +155,17 @@ def ping(ip, packet_number=3, DEBUG=False):
155155
return True
156156
return False
157157
except Exception as e:
158-
if DEBUG:
158+
if debug:
159159
print(str(e))
160160
return "Error"
161161

162162

163-
def mac(DEBUG=False):
163+
def mac(debug=False):
164164
"""
165165
Return mac addresses of net devices.
166166
167-
:param DEBUG: flag for using Debug mode
168-
:type DEBUG:bool
167+
:param debug: flag for using debug mode
168+
:type debug:bool
169169
:return: return mac addresses as dict with name as keys and mac addresses as values
170170
"""
171171
try:
@@ -178,6 +178,6 @@ def mac(DEBUG=False):
178178
mac_addr.close()
179179
return dict(zip(dir_list, mac_list))
180180
except Exception as e:
181-
if DEBUG:
181+
if debug:
182182
print(str(e))
183183
return "Error"

orangetool/orangetool_ram.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ def ram_percent():
7575
return str(response[2]) + " %"
7676

7777

78-
def freeup(DEBUG=False):
78+
def freeup(debug=False):
7979
"""
8080
To free pagecache, dentries and inodes.
8181
82-
:param DEBUG: flag for using Debug mode
83-
:type DEBUG:bool
82+
:param debug: flag for using debug mode
83+
:type debug:bool
8484
:return: Amount of freeuped ram as string and converted by convert_bytes()
8585
"""
8686
try:
@@ -94,6 +94,6 @@ def freeup(DEBUG=False):
9494
return convert_bytes(freeuped_ram)
9595
return convert_bytes(0)
9696
except Exception as e:
97-
if DEBUG:
97+
if debug:
9898
print(str(e))
9999
return "Error"

0 commit comments

Comments
 (0)