Skip to content

Commit 4f85547

Browse files
authoredJan 1, 2021
Merge pull request #52 from Moduland/dev
Version 0.50
2 parents e37d254 + 60c07e2 commit 4f85547

12 files changed

+106
-22
lines changed
 

‎CHANGELOG.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

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

84-
[Unreleased]: https://github.com/Moduland/Orangetool/compare/v0.45...dev
90+
[Unreleased]: https://github.com/Moduland/Orangetool/compare/v0.50...dev
91+
[0.50]: https://github.com/Moduland/Orangetool/compare/v0.45...v0.50
8592
[0.45]: https://github.com/Moduland/Orangetool/compare/v0.35...v0.45
8693
[0.35]: https://github.com/Moduland/Orangetool/compare/v0.25...v0.35
8794
[0.25]: https://github.com/Moduland/Orangetool/compare/v0.24...v0.25

‎README.md

+9-3
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ By [Moduland Co](http://www.moduland.ir)
8484

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

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

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

138+
#7- network_enable
138139

140+
status=network_enable("eth0") # enable network device
141+
142+
#8- network_disable
143+
144+
status=network_disable("eth0") # disable network device
139145

140146
```
141147

@@ -237,7 +243,7 @@ orangetool.restart() # restart system
237243

238244
#5- wakeup
239245

240-
orangetool.wakeup(day=1,hour=0,minute=1) # set rtc wakeuptime
246+
orangetool.wakeup(day=1,hour=0,minute=1,sync=True) # set rtc wakeuptime
241247

242248
#6- get_temp
243249

‎orangetool/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"""Orangetool modules."""
33

44
from .orangetool_display import hdmi_on, hdmi_off, hdmi_size
5-
from .orangetool_ip import internet, local_ip, global_ip, set_ip, ping, mac
5+
from .orangetool_ip import internet, local_ip, global_ip, set_ip, ping, mac, network_disable, network_enable
66
from .orangetool_system import check_update, get_temp, uptime, idletime, wakeup, version, sleep, hibernate, halt, restart
77
from .orangetool_ram import ram_total, ram_used, ram_free, ram_percent, freeup
88
from .orangetool_storage import mount_status, storage_status, unmount, unmount_all, mount, usb_on, usb_off

‎orangetool/orangetool_ip.py

+65-8
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,19 @@
1010
import platform
1111

1212

13-
def internet(host="8.8.8.8", port=53, timeout=3):
13+
def internet(host="8.8.8.8", port=53, timeout=3, debug=False):
1414
"""
1515
Check internet connections.
1616
17-
:param host: the host that check connection to
17+
:param host: the host that check connection to
1818
:type host:str
19-
:param port: port that check connection with
19+
:param port: port that check connection with
2020
:type port:int
21-
:param timeout: times that check the connection
21+
:param timeout: times that check the connection
2222
:type timeout:int
23-
:return bool: True if Connection is Stable
23+
:param debug:flag for using debug mode
24+
:type debug:bool
25+
:return bool: True if connection is stable
2426
>>> internet() # if there is stable internet connection
2527
True
2628
>>> internet() # if there is no stable internet connection
@@ -30,16 +32,17 @@ def internet(host="8.8.8.8", port=53, timeout=3):
3032
socket.setdefaulttimeout(timeout)
3133
socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port))
3234
return True
33-
except Exception as ex:
34-
print(str(ex))
35+
except Exception as e:
36+
if debug:
37+
print(str(e))
3538
return False
3639

3740

3841
def local_ip(debug=False):
3942
"""
4043
Return local ip of computer in windows by socket module and in unix with hostname command in shell.
4144
42-
:param debug:flag for using debug Mode
45+
:param debug:flag for using debug mode
4346
:type debug:bool
4447
:return: local ip as string
4548
"""
@@ -180,3 +183,57 @@ def mac(debug=False):
180183
if debug:
181184
print(str(e))
182185
return GENERAL_ERROR_MESSAGE
186+
187+
188+
def network_control(command, device="eth0", debug=False):
189+
"""
190+
Control network adaptor.
191+
192+
:param command: input command
193+
:type command: str
194+
:param device: network device name
195+
:type device:str
196+
:param debug: flag for using debug mode
197+
:type debug:bool
198+
:return: True in successful and False otherwise
199+
"""
200+
try:
201+
cmd = "up"
202+
if command == "down":
203+
cmd = "down"
204+
cmd_out = sub.Popen(["ifconfig", device, cmd],
205+
stderr=sub.PIPE, stdin=sub.PIPE, stdout=sub.PIPE)
206+
output = list(cmd_out.communicate())
207+
if len(output[0]) == 0 and len(output[1]) == 0:
208+
return True
209+
return False
210+
except Exception as e:
211+
if debug:
212+
print(str(e))
213+
return GENERAL_ERROR_MESSAGE
214+
215+
216+
def network_enable(device="eth0", debug=False):
217+
"""
218+
Shortcut to enable network adaptor.
219+
220+
:param device: network device name
221+
:type device:str
222+
:param debug: flag for using debug mode
223+
:type debug:bool
224+
:return: True in successful and False otherwise
225+
"""
226+
return network_control("up", device=device, debug=debug)
227+
228+
229+
def network_disable(device="eth0", debug=False):
230+
"""
231+
Shortcut to disable network adaptor.
232+
233+
:param device: network device name
234+
:type device:str
235+
:param debug: flag for using debug mode
236+
:type debug:bool
237+
:return: True in successful and False otherwise
238+
"""
239+
return network_control("down", device=device, debug=debug)

‎orangetool/orangetool_params.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22
"""Orangetool params."""
33

4-
ORANGETOOL_VERSION = "0.45"
4+
ORANGETOOL_VERSION = "0.50"
55
UPDATE_URL = "http://www.orangetool.ir/version"
66
IP_PATTERN = r"(?:[0-9]{1,3}\.){3}[0-9]{1,3}"
77
GLOBAL_IP_API_1 = "http://ipinfo.io/ip"

‎orangetool/orangetool_ram.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from .orangetool_params import GENERAL_ERROR_MESSAGE
55
from .orangetool_utils import convert_bytes
66

7+
78
def ram_total(convert=True):
89
"""
910
Return total ram of board.

‎orangetool/orangetool_storage.py

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ def unmount_all(debug=False):
104104
print(str(e))
105105
return GENERAL_ERROR_MESSAGE
106106

107+
107108
def mount(device_name, mount_address=None, debug=False):
108109
"""
109110
Mount memory devices by addresses.

‎orangetool/orangetool_system.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ def get_temp(zone=0, debug=False):
5454
print(str(e))
5555
return GENERAL_ERROR_MESSAGE
5656

57-
def time_control(mode="uptime",debug=False):
57+
58+
def time_control(mode="uptime", debug=False):
5859
"""
5960
Return system time.
6061
@@ -65,7 +66,7 @@ def time_control(mode="uptime",debug=False):
6566
:return: system time as string
6667
"""
6768
index = 0
68-
if mode in ["idle","idletime"]:
69+
if mode in ["idle", "idletime"]:
6970
index = 1
7071
try:
7172
command = open("/proc/uptime")
@@ -76,6 +77,7 @@ def time_control(mode="uptime",debug=False):
7677
print(str(e))
7778
return GENERAL_ERROR_MESSAGE
7879

80+
7981
def uptime(debug=False):
8082
"""
8183
Return system uptime.
@@ -84,7 +86,7 @@ def uptime(debug=False):
8486
:type debug:bool
8587
:return: system uptime as string
8688
"""
87-
return time_control(mode="uptime",debug=debug)
89+
return time_control(mode="uptime", debug=debug)
8890

8991

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

110112

111-
def wakeup(day=0, hour=0, minute=0, debug=False):
113+
def wakeup(day=0, hour=0, minute=0, sync=True, debug=False):
112114
"""
113115
Set wakeup time for kernel RTC (need sudo).
114116
@@ -118,11 +120,19 @@ def wakeup(day=0, hour=0, minute=0, debug=False):
118120
:type hour:int
119121
:param minute: minute for wakeup
120122
:type minute:int
123+
:param sync: RTC sync flag
124+
:type sync: bool
121125
:param debug: flag for using debug mode
122126
:type debug:bool
123127
:return: bool
124128
"""
125129
try:
130+
if sync:
131+
_ = sub.Popen(
132+
["hwclock", "-w"],
133+
stderr=sub.PIPE,
134+
stdout=sub.PIPE,
135+
stdin=sub.PIPE)
126136
total_time = day * 24 * 60 + hour * 60 + minute
127137
epoch = time.time() + total_time * 60
128138
file = open("/sys/class/rtc/rtc0/wakealarm", "w")

‎orangetool/orangetool_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
if __name__ == "__main__":
66
version()
7-
check_update()
7+
check_update()

‎orangetool/orangetool_utils.py

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"""Orangetool utils."""
33
import random
44

5+
56
def zero_insert(input_string):
67
"""
78
Get a string as input if input is one digit add a zero.
@@ -49,6 +50,7 @@ def random_generator(number):
4950
response += str(random.randint(0, 9))
5051
return response
5152

53+
5254
def convert_bytes(num):
5355
"""
5456
Convert num to idiomatic byte unit.

‎setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ def read_description():
2929
setup(
3030
name='orangetool',
3131
packages=['orangetool'],
32-
version='0.45',
32+
version='0.50',
3333
description='Some useful script for Orangepi/Raspberrypi boards',
3434
long_description=read_description(),
3535
long_description_content_type='text/markdown',
3636
author='Moduland Co',
3737
author_email='info@orangetool.ir',
3838
url='https://github.com/Moduland/Orangetool',
39-
download_url='https://github.com/Moduland/Orangetool/tarball/v0.45',
39+
download_url='https://github.com/Moduland/Orangetool/tarball/v0.50',
4040
keywords="orangepi raspberrypi embedded-systems python",
4141
classifiers=[
4242
'Development Status :: 4 - Beta',

‎version_check.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import sys
55
import codecs
66
Failed = 0
7-
VERSION = "0.45"
7+
VERSION = "0.50"
88

99

1010
SETUP_ITEMS = [

0 commit comments

Comments
 (0)