|
7 | 7 | import os
|
8 | 8 | import string
|
9 | 9 | import random
|
| 10 | +import time |
10 | 11 | ip_pattern=r"(?:[0-9]{1,3}\.){3}[0-9]{1,3}"
|
11 | 12 | api_1="http://ipinfo.io/ip"
|
12 | 13 | VERSION="orangetool-v0.2"
|
@@ -99,7 +100,7 @@ def set_ip(ip,DEVICE="eth0",DEBUG=False):
|
99 | 100 | '''
|
100 | 101 | try:
|
101 | 102 | if bool(re.match(ip_pattern,ip))==False or ip.find("192.168.")==-1 or DEVICE not in mac().keys():
|
102 |
| - raise Exception |
| 103 | + raise Exception("IP Formation Error") |
103 | 104 | static_string=static_string.replace("ip",ip)
|
104 | 105 | static_string=static_string.replace("device",DEVICE)
|
105 | 106 | file=open("/etc/network/interfaces","w")
|
@@ -265,7 +266,7 @@ def ping(ip,packet_number=3,DEBUG=False):
|
265 | 266 | '''
|
266 | 267 | try:
|
267 | 268 | if re.match(ip_pattern,ip)==False:
|
268 |
| - raise Exception |
| 269 | + raise Exception("IP Formation Error") |
269 | 270 | output=str(list(sub.Popen(["ping",ip,"-c",str(packet_number)],stdout=sub.PIPE,stderr=sub.PIPE).communicate())[0])
|
270 | 271 | if output.find("Unreachable")==-1:
|
271 | 272 | return True
|
@@ -405,7 +406,7 @@ def mount(device_name,mount_address=None,DEBUG=False):
|
405 | 406 | '''
|
406 | 407 | try:
|
407 | 408 | if mount_status(device_name)!="u":
|
408 |
| - raise Exception |
| 409 | + raise Exception("Device already mount") |
409 | 410 | if mount_address==None:
|
410 | 411 | mount_address="/mnt/"+random_generator(5)
|
411 | 412 | command=sub.Popen(["mkdir",mount_address], stdout=sub.PIPE, stderr=sub.PIPE)
|
@@ -504,6 +505,53 @@ def hdmi_size(v=None,h=None,DEBUG=False):
|
504 | 505 | if DEBUG==True:
|
505 | 506 | print(str(e))
|
506 | 507 | return "Error"
|
| 508 | +def wakeup(day=0,hour=0,minute=0,DEBUG=False): |
| 509 | + ''' |
| 510 | + This function set wakeup time for kernel RTC (need sudo) |
| 511 | + :param day: days for wakeup |
| 512 | + :param hour: hout for wakeup |
| 513 | + :param minute: minute for wakeup |
| 514 | + :param DEBUG: Flag for using Debug mode |
| 515 | + :type day:int |
| 516 | + :type hour:int |
| 517 | + :type minute:int |
| 518 | + :type DEBUG:bool |
| 519 | + :return: bool |
| 520 | + ''' |
| 521 | + try: |
| 522 | + total_time=day*24*60+hour*60+minute |
| 523 | + epoch=time.time()+total_time*60 |
| 524 | + file=open("/sys/class/rtc/rtc0/wakealarm","w") |
| 525 | + file.write("0") |
| 526 | + file.close() |
| 527 | + file = open("/sys/class/rtc/rtc0/wakealarm", "w") |
| 528 | + file.write(str(epoch)) |
| 529 | + file.close() |
| 530 | + return True |
| 531 | + except Exception as e: |
| 532 | + if DEBUG==True: |
| 533 | + print(str(e)) |
| 534 | + return "Error" |
| 535 | +def sleep(DEBUG=False): |
| 536 | + ''' |
| 537 | + This function is a shortcut for sleep (need sudo) |
| 538 | + :param DEBUG: Flag for using Debug mode |
| 539 | + :type DEBUG:bool |
| 540 | + :return: None |
| 541 | + ''' |
| 542 | + try: |
| 543 | + command=sub.Popen("pm-suspend",stderr=sub.PIPE,stdout=sub.PIPE,stdin=sub.PIPE) |
| 544 | + response=list(command.communicate()) |
| 545 | + if len(response[1])>0: |
| 546 | + raise Exception('Root Error') |
| 547 | + except Exception as e: |
| 548 | + if DEBUG==True: |
| 549 | + print(str(e)) |
| 550 | + return "Error" |
| 551 | + |
| 552 | + |
| 553 | + |
| 554 | + |
507 | 555 |
|
508 | 556 |
|
509 | 557 |
|
|
0 commit comments