Skip to content

Debug #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Nov 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]
### Added
- `FUNDING.yml`
- `__version__` variable
- `hibernate` function
### Changed
- `dev-requirements.txt` modified
- Test system modified
- `DEBUG` parameter renamed to `debug`
## [0.35] - 2019-06-01
### Added
- `version_check.py`
Expand Down
25 changes: 2 additions & 23 deletions orangetool/__init__.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,10 @@
# -*- coding: utf-8 -*-
"""Orangetool modules."""
"""
MIT License

Copyright (c) 2017 Moduland Co

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""

from .orangetool_display import *
from .orangetool_ip import *
from .orangetool_system import *
from .orangetool_ram import *
from .orangetool_storage import *

__version__ = ORANGETOOL_VERSION
32 changes: 16 additions & 16 deletions orangetool/orangetool_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
"""Orangetool display functions."""


def hdmi_controller(command, DEBUG=False):
def hdmi_controller(command, debug=False):
"""
Control hdmi port.

:param command: inpurt command
:type command: bool
:param DEBUG: flag for using Debug mode
:type DEBUG: bool
:param debug: flag for using debug mode
:type debug: bool
:return: bool
"""
try:
Expand All @@ -21,43 +21,43 @@ def hdmi_controller(command, DEBUG=False):
hdmi_control.close()
return True
except Exception as e:
if DEBUG:
if debug:
print(str(e))
return "Error"


def hdmi_on(DEBUG=False):
def hdmi_on(debug=False):
"""
Turn on hdmi port (need sudo -s).

:param DEBUG: flag for using Debug mode
:type DEBUG:bool
:param debug: flag for using debug mode
:type debug:bool
:return: bool
"""
hdmi_controller(True, DEBUG)
hdmi_controller(True, debug)


def hdmi_off(DEBUG=False):
def hdmi_off(debug=False):
"""
Turn off hdmi port (need sudo -s).

:param DEBUG: flag for using Debug mode
:type DEBUG:bool
:param debug: flag for using debug mode
:type debug:bool
:return: bool
"""
hdmi_controller(False, DEBUG)
hdmi_controller(False, debug)


def hdmi_size(v=None, h=None, DEBUG=False):
def hdmi_size(v=None, h=None, debug=False):
"""
Change hdmi display resolution (need sudo -s) (if call without any argument return current resolution).

:param v: vertical line
:param h: horizental line
:param DEBUG: flag for using Debug mode
:param debug: flag for using debug mode
:type v : int
:type h:int
:type DEBUG:bool
:type debug:bool
:return: bool
"""
try:
Expand All @@ -71,6 +71,6 @@ def hdmi_size(v=None, h=None, DEBUG=False):
hdmi_control.close()
return True
except Exception as e:
if DEBUG:
if debug:
print(str(e))
return "Error"
52 changes: 26 additions & 26 deletions orangetool/orangetool_ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import requests
import re
import platform
ip_pattern = r"(?:[0-9]{1,3}\.){3}[0-9]{1,3}"
api_1 = "http://ipinfo.io/ip"
IP_PATTERN = r"(?:[0-9]{1,3}\.){3}[0-9]{1,3}"
GLOBAL_IP_API_1 = "http://ipinfo.io/ip"


def internet(host="8.8.8.8", port=53, timeout=3):
Expand Down Expand Up @@ -36,12 +36,12 @@ def internet(host="8.8.8.8", port=53, timeout=3):
return False


def local_ip(DEBUG=False):
def local_ip(debug=False):
"""
Return local ip of computer in windows by socket module and in unix with hostname command in shell.

:param DEBUG:flag for using Debug Mode
:type DEBUG:bool
:param debug:flag for using debug Mode
:type debug:bool
:return: local ip as string
"""
try:
Expand All @@ -62,32 +62,32 @@ def local_ip(DEBUG=False):
return "Error"

except Exception as e:
if DEBUG:
if debug:
print(str(e))
return "Error"


def global_ip(DEBUG=False):
def global_ip(debug=False):
"""
Return ip with by http://ipinfo.io/ip api.

:param DEBUG:flag for using Debug mode
:type DEBUG:bool
:param debug:flag for using debug mode
:type debug:bool
:return: global ip as string
"""
try:
new_session = requests.session()
response = new_session.get(api_1)
ip_list = re.findall(ip_pattern, response.text)
response = new_session.get(GLOBAL_IP_API_1)
ip_list = re.findall(IP_PATTERN, response.text)
new_session.close()
return ip_list[0]
except Exception as e:
if DEBUG:
if debug:
print(str(e))
return "Error"


def set_ip(ip, restart=False, device="eth0", DEBUG=False):
def set_ip(ip, restart=False, device="eth0", debug=False):
"""
Set static ip in interfaces file (need sudo).

Expand All @@ -97,8 +97,8 @@ def set_ip(ip, restart=False, device="eth0", DEBUG=False):
:type device:str
:param ip: static ip
:type ip :str
:param DEBUG: flag for using Debug mode
:type DEBUG:bool
:param debug: flag for using debug mode
:type debug:bool
:return: True in successful
"""
static_string = '''
Expand All @@ -111,7 +111,7 @@ def set_ip(ip, restart=False, device="eth0", DEBUG=False):
dns-nameservers 8.8.8.8 8.8.4.4
'''
try:
if bool(re.match(ip_pattern, ip)) == False or ip.find(
if bool(re.match(IP_PATTERN, ip)) == False or ip.find(
"192.168.") == -1 or device not in mac().keys():
raise Exception("IP Formation Error")
static_string = static_string.replace("ip", ip)
Expand All @@ -125,25 +125,25 @@ def set_ip(ip, restart=False, device="eth0", DEBUG=False):
restart_func()
return True
except Exception as e:
if DEBUG:
if debug:
print(str(e))
return "Error"


def ping(ip, packet_number=3, DEBUG=False):
def ping(ip, packet_number=3, debug=False):
"""
Ping ip and return True if this ip is available and False otherwise.

:param ip: target ip
:param packet_number: number of packet to size
:param DEBUG: flag for using Debug mode
:param debug: flag for using debug mode
:type ip :str
:type packet_number:int
:type DEBUG:bool
:type debug:bool
:return: a boolean value (True if ip is available and False otherwise)
"""
try:
if re.match(ip_pattern, ip) == False:
if re.match(IP_PATTERN, ip) == False:
raise Exception("IP Formation Error")
output = str(list(sub.Popen(["ping",
ip,
Expand All @@ -155,17 +155,17 @@ def ping(ip, packet_number=3, DEBUG=False):
return True
return False
except Exception as e:
if DEBUG:
if debug:
print(str(e))
return "Error"


def mac(DEBUG=False):
def mac(debug=False):
"""
Return mac addresses of net devices.

:param DEBUG: flag for using Debug mode
:type DEBUG:bool
:param debug: flag for using debug mode
:type debug:bool
:return: return mac addresses as dict with name as keys and mac addresses as values
"""
try:
Expand All @@ -178,6 +178,6 @@ def mac(DEBUG=False):
mac_addr.close()
return dict(zip(dir_list, mac_list))
except Exception as e:
if DEBUG:
if debug:
print(str(e))
return "Error"
8 changes: 4 additions & 4 deletions orangetool/orangetool_ram.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ def ram_percent():
return str(response[2]) + " %"


def freeup(DEBUG=False):
def freeup(debug=False):
"""
To free pagecache, dentries and inodes.

:param DEBUG: flag for using Debug mode
:type DEBUG:bool
:param debug: flag for using debug mode
:type debug:bool
:return: Amount of freeuped ram as string and converted by convert_bytes()
"""
try:
Expand All @@ -94,6 +94,6 @@ def freeup(DEBUG=False):
return convert_bytes(freeuped_ram)
return convert_bytes(0)
except Exception as e:
if DEBUG:
if debug:
print(str(e))
return "Error"
Loading