Skip to content

Version 0.50 #52

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 19 commits into from
Jan 1, 2021
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
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [0.50] - 2021-01-01
### Added
- `network_control`, `network_enable` and `network_disable` functions
### Changed
- `sync` parameter added to `wakeup` function
- `debug` parameter added to `internet` function
## [0.45] - 2020-12-26
### Added
- `__main__.py`
Expand Down Expand Up @@ -81,7 +87,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added
- Some useful scripts for Orangepi/Raspberrypi boards

[Unreleased]: https://github.com/Moduland/Orangetool/compare/v0.45...dev
[Unreleased]: https://github.com/Moduland/Orangetool/compare/v0.50...dev
[0.50]: https://github.com/Moduland/Orangetool/compare/v0.45...v0.50
[0.45]: https://github.com/Moduland/Orangetool/compare/v0.35...v0.45
[0.35]: https://github.com/Moduland/Orangetool/compare/v0.25...v0.35
[0.25]: https://github.com/Moduland/Orangetool/compare/v0.24...v0.25
Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ By [Moduland Co](http://www.moduland.ir)

## Installation
### Source Code
- Download [Version 0.45](https://github.com/moduland/Orangetool/archive/v0.45.zip) or [Latest Source ](https://github.com/Moduland/Orangetool/archive/dev.zip)
- Download [Version 0.50](https://github.com/moduland/Orangetool/archive/v0.50.zip) or [Latest Source ](https://github.com/Moduland/Orangetool/archive/dev.zip)
- `pip3 install -r requirements.txt` or `pip install -r requirements.txt` (Need root access)
- `python3 setup.py install` or `python setup.py install`
### PyPI

- Check [Python Packaging User Guide](https://packaging.python.org/installing/)
- `pip3 install orangetool==0.45` or `pip install orangetool==0.45` (Need root access)
- `pip3 install orangetool==0.50` or `pip install orangetool==0.50` (Need root access)
<div align="center">
<a href="https://asciinema.org/a/141548" target="_blank"><img src="https://asciinema.org/a/141548.png" /></a>
</div>
Expand Down Expand Up @@ -135,7 +135,13 @@ orangetool.set_ip("192.168.1.46","eth0") #this function set static ip for syste

mac_dic=orangetool.mac() # return dict of all system net devices mac addresses

#7- network_enable

status=network_enable("eth0") # enable network device

#8- network_disable

status=network_disable("eth0") # disable network device

```

Expand Down Expand Up @@ -237,7 +243,7 @@ orangetool.restart() # restart system

#5- wakeup

orangetool.wakeup(day=1,hour=0,minute=1) # set rtc wakeuptime
orangetool.wakeup(day=1,hour=0,minute=1,sync=True) # set rtc wakeuptime

#6- get_temp

Expand Down
2 changes: 1 addition & 1 deletion orangetool/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""Orangetool modules."""

from .orangetool_display import hdmi_on, hdmi_off, hdmi_size
from .orangetool_ip import internet, local_ip, global_ip, set_ip, ping, mac
from .orangetool_ip import internet, local_ip, global_ip, set_ip, ping, mac, network_disable, network_enable
from .orangetool_system import check_update, get_temp, uptime, idletime, wakeup, version, sleep, hibernate, halt, restart
from .orangetool_ram import ram_total, ram_used, ram_free, ram_percent, freeup
from .orangetool_storage import mount_status, storage_status, unmount, unmount_all, mount, usb_on, usb_off
Expand Down
73 changes: 65 additions & 8 deletions orangetool/orangetool_ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@
import platform


def internet(host="8.8.8.8", port=53, timeout=3):
def internet(host="8.8.8.8", port=53, timeout=3, debug=False):
"""
Check internet connections.

:param host: the host that check connection to
:param host: the host that check connection to
:type host:str
:param port: port that check connection with
:param port: port that check connection with
:type port:int
:param timeout: times that check the connection
:param timeout: times that check the connection
:type timeout:int
:return bool: True if Connection is Stable
:param debug:flag for using debug mode
:type debug:bool
:return bool: True if connection is stable
>>> internet() # if there is stable internet connection
True
>>> internet() # if there is no stable internet connection
Expand All @@ -30,16 +32,17 @@ def internet(host="8.8.8.8", port=53, timeout=3):
socket.setdefaulttimeout(timeout)
socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port))
return True
except Exception as ex:
print(str(ex))
except Exception as e:
if debug:
print(str(e))
return 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
:param debug:flag for using debug mode
:type debug:bool
:return: local ip as string
"""
Expand Down Expand Up @@ -180,3 +183,57 @@ def mac(debug=False):
if debug:
print(str(e))
return GENERAL_ERROR_MESSAGE


def network_control(command, device="eth0", debug=False):
"""
Control network adaptor.

:param command: input command
:type command: str
:param device: network device name
:type device:str
:param debug: flag for using debug mode
:type debug:bool
:return: True in successful and False otherwise
"""
try:
cmd = "up"
if command == "down":
cmd = "down"
cmd_out = sub.Popen(["ifconfig", device, cmd],
stderr=sub.PIPE, stdin=sub.PIPE, stdout=sub.PIPE)
output = list(cmd_out.communicate())
if len(output[0]) == 0 and len(output[1]) == 0:
return True
return False
except Exception as e:
if debug:
print(str(e))
return GENERAL_ERROR_MESSAGE


def network_enable(device="eth0", debug=False):
"""
Shortcut to enable network adaptor.

:param device: network device name
:type device:str
:param debug: flag for using debug mode
:type debug:bool
:return: True in successful and False otherwise
"""
return network_control("up", device=device, debug=debug)


def network_disable(device="eth0", debug=False):
"""
Shortcut to disable network adaptor.

:param device: network device name
:type device:str
:param debug: flag for using debug mode
:type debug:bool
:return: True in successful and False otherwise
"""
return network_control("down", device=device, debug=debug)
2 changes: 1 addition & 1 deletion orangetool/orangetool_params.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""Orangetool params."""

ORANGETOOL_VERSION = "0.45"
ORANGETOOL_VERSION = "0.50"
UPDATE_URL = "http://www.orangetool.ir/version"
IP_PATTERN = r"(?:[0-9]{1,3}\.){3}[0-9]{1,3}"
GLOBAL_IP_API_1 = "http://ipinfo.io/ip"
Expand Down
1 change: 1 addition & 0 deletions orangetool/orangetool_ram.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from .orangetool_params import GENERAL_ERROR_MESSAGE
from .orangetool_utils import convert_bytes


def ram_total(convert=True):
"""
Return total ram of board.
Expand Down
1 change: 1 addition & 0 deletions orangetool/orangetool_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def unmount_all(debug=False):
print(str(e))
return GENERAL_ERROR_MESSAGE


def mount(device_name, mount_address=None, debug=False):
"""
Mount memory devices by addresses.
Expand Down
18 changes: 14 additions & 4 deletions orangetool/orangetool_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def get_temp(zone=0, debug=False):
print(str(e))
return GENERAL_ERROR_MESSAGE

def time_control(mode="uptime",debug=False):

def time_control(mode="uptime", debug=False):
"""
Return system time.

Expand All @@ -65,7 +66,7 @@ def time_control(mode="uptime",debug=False):
:return: system time as string
"""
index = 0
if mode in ["idle","idletime"]:
if mode in ["idle", "idletime"]:
index = 1
try:
command = open("/proc/uptime")
Expand All @@ -76,6 +77,7 @@ def time_control(mode="uptime",debug=False):
print(str(e))
return GENERAL_ERROR_MESSAGE


def uptime(debug=False):
"""
Return system uptime.
Expand All @@ -84,7 +86,7 @@ def uptime(debug=False):
:type debug:bool
:return: system uptime as string
"""
return time_control(mode="uptime",debug=debug)
return time_control(mode="uptime", debug=debug)


def idletime(debug=False):
Expand All @@ -108,7 +110,7 @@ def version():
tprint("v" + ORANGETOOL_VERSION, font="bulbhead")


def wakeup(day=0, hour=0, minute=0, debug=False):
def wakeup(day=0, hour=0, minute=0, sync=True, debug=False):
"""
Set wakeup time for kernel RTC (need sudo).

Expand All @@ -118,11 +120,19 @@ def wakeup(day=0, hour=0, minute=0, debug=False):
:type hour:int
:param minute: minute for wakeup
:type minute:int
:param sync: RTC sync flag
:type sync: bool
:param debug: flag for using debug mode
:type debug:bool
:return: bool
"""
try:
if sync:
_ = sub.Popen(
["hwclock", "-w"],
stderr=sub.PIPE,
stdout=sub.PIPE,
stdin=sub.PIPE)
total_time = day * 24 * 60 + hour * 60 + minute
epoch = time.time() + total_time * 60
file = open("/sys/class/rtc/rtc0/wakealarm", "w")
Expand Down
2 changes: 1 addition & 1 deletion orangetool/orangetool_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

if __name__ == "__main__":
version()
check_update()
check_update()
2 changes: 2 additions & 0 deletions orangetool/orangetool_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""Orangetool utils."""
import random


def zero_insert(input_string):
"""
Get a string as input if input is one digit add a zero.
Expand Down Expand Up @@ -49,6 +50,7 @@ def random_generator(number):
response += str(random.randint(0, 9))
return response


def convert_bytes(num):
"""
Convert num to idiomatic byte unit.
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ def read_description():
setup(
name='orangetool',
packages=['orangetool'],
version='0.45',
version='0.50',
description='Some useful script for Orangepi/Raspberrypi boards',
long_description=read_description(),
long_description_content_type='text/markdown',
author='Moduland Co',
author_email='[email protected]',
url='https://github.com/Moduland/Orangetool',
download_url='https://github.com/Moduland/Orangetool/tarball/v0.45',
download_url='https://github.com/Moduland/Orangetool/tarball/v0.50',
keywords="orangepi raspberrypi embedded-systems python",
classifiers=[
'Development Status :: 4 - Beta',
Expand Down
2 changes: 1 addition & 1 deletion version_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys
import codecs
Failed = 0
VERSION = "0.45"
VERSION = "0.50"


SETUP_ITEMS = [
Expand Down