Import native OS color scheme

This commit is contained in:
clamsawd 2015-10-30 08:45:47 +01:00
parent db9959b61e
commit af9f3479ca
3 changed files with 43 additions and 65 deletions

View File

@ -5,7 +5,7 @@
# ip2e (IP to email) - Create the configuration file. |
# Created by clamsawd (clamsawd@openmailbox.org) |
# Licensed by GPL v.3 |
# Last update: 29-10-2015 |
# Last update: 30-10-2015 |
# |
# Dependences: curl or wget |
# Compatible with Python 3.x |

View File

@ -5,7 +5,7 @@
# ip2e (IP to email) - Run ip2e daemon. |
# Created by clamsawd (clamsawd@openmailbox.org) |
# Licensed by GPL v.3 |
# Last update: 29-10-2015 |
# Last update: 30-10-2015 |
# |
# Dependences: curl or wget |
# Compatible with Python 3.x |
@ -107,12 +107,24 @@ except:
#Import variables from ip2e-conf.py
exec(open("ip2e-conf.py").read())
#Import Windows colors scheme
#Import native OS color scheme
def GreenColor():
if os.name == "posix":
GreenColor = (chr(27)+"[1;32m")
print (GreenColor+"", end="")
elif os.name == "nt":
os.system("color 2")
def RedColor():
if os.name == "posix":
RedColor = (chr(27)+"[1;31m")
print (RedColor+"", end="")
elif os.name == "nt":
os.system("color 4")
def OrangeColor():
if os.name == "posix":
OrangeColor = (chr(27)+"[1;33m")
print (OrangeColor+"", end="")
elif os.name == "nt":
os.system("color 6")
#Check if exists a previous log.file.
@ -125,20 +137,13 @@ createlog.close()
ClearScreen()
editlog=open('ip2e.log','a')
CurrentTime = time.strftime("%H:%M")
if os.name == "posix":
print (chr(27)+"[1;32m"+"[ip2e-daemon] ["+CurrentTime+"] Initialized ip2e-daemon v"+version+" (Ctrl+C to stop)")
elif os.name == "nt":
GreenColor()
print ("[ip2e-daemon] ["+CurrentTime+"] Initialized ip2e-daemon v"+version+" (Ctrl+C to stop)")
if os.name == "posix":
print (chr(27)+"[1;32m"+"[ip2e-daemon] ["+CurrentTime+"] Log in "+os.environ["HOME"]+"/.ip2e/ip2e.log")
print ("[ip2e-daemon] ["+CurrentTime+"] Log in "+os.environ["HOME"]+"/.ip2e/ip2e.log")
elif os.name == "nt":
GreenColor()
print ("[ip2e-daemon] ["+CurrentTime+"] Log in "+os.environ["USERPROFILE"]+"\.ip2e\\ip2e.log")
editlog.write("[ip2e-daemon] ["+CurrentTime+"] Initialized ip2e-daemon v"+version+"\n")
if os.name == "posix":
print (chr(27)+"[1;33m"+"[ip2e-daemon] ["+CurrentTime+"] Waiting 60 seconds...")
elif os.name == "nt":
OrangeColor()
print ("[ip2e-daemon] ["+CurrentTime+"] Waiting 60 seconds...")
editlog.write("[ip2e-daemon] ["+CurrentTime+"] Waiting 60 seconds...\n")
@ -151,9 +156,6 @@ while PublicIP <= 2:
GetCurrentIP = 1
while GetCurrentIP <= 2:
CurrentTime = time.strftime("%H:%M")
if os.name == "posix":
print (chr(27)+"[1;33m"+"[ip2e-daemon] ["+CurrentTime+"] IP Updating...")
elif os.name == "nt":
OrangeColor()
print ("[ip2e-daemon] ["+CurrentTime+"] IP Updating...")
editlog=open('ip2e.log','a')
@ -168,10 +170,6 @@ while PublicIP <= 2:
GetCurrentIP += 2
else:
CurrentTime = time.strftime("%H:%M")
if os.name == "posix":
print (chr(27)+"[1;31m"+"[ip2e-daemon] ["+CurrentTime+"] Error getting IP")
print (chr(27)+"[1;33m"+"[ip2e-daemon] ["+CurrentTime+"] Retrying in 5 seconds...")
elif os.name == "nt":
RedColor()
print ("[ip2e-daemon] ["+CurrentTime+"] Error getting IP")
print ("[ip2e-daemon] ["+CurrentTime+"] Retrying in 5 seconds...")
@ -181,17 +179,11 @@ while PublicIP <= 2:
exec(open("current-ip.py").read())
if CurrentIP == NewIP:
CurrentTime = time.strftime("%H:%M")
if os.name == "posix":
print (chr(27)+"[1;32m"+"[ip2e-daemon] ["+CurrentTime+"] IP has not changed")
elif os.name == "nt":
GreenColor()
print ("[ip2e-daemon] ["+CurrentTime+"] IP has not changed")
editlog.write("[ip2e-daemon] ["+CurrentTime+"] IP has not changed\n")
else:
CurrentTime = time.strftime("%H:%M")
if os.name == "posix":
print (chr(27)+"[1;32m"+"[ip2e-daemon] ["+CurrentTime+"] New IP - From "+CurrentIP+" to "+NewIP)
elif os.name == "nt":
GreenColor()
print ("[ip2e-daemon] ["+CurrentTime+"] New IP - From "+CurrentIP+" to "+NewIP)
editlog.write("[ip2e-daemon] ["+CurrentTime+"] New IP - From "+CurrentIP+" to "+NewIP+"\n")
@ -209,10 +201,6 @@ while PublicIP <= 2:
server.ehlo()
server.login(FromEmailUser,FromEmailPass)
except:
if os.name == "posix":
print (chr(27)+"[1;31m"+"[ip2e-daemon] ["+CurrentTime+"] Failed to connect ("+SmtpFromEmail+")")
print (chr(27)+"[1;31m"+"[ip2e-daemon] ["+CurrentTime+"] Check your settings [Aborted]")
elif os.name == "nt":
RedColor()
print ("[ip2e-daemon] ["+CurrentTime+"] Failed to connect ("+SmtpFromEmail+")")
print ("[ip2e-daemon] ["+CurrentTime+"] Check your settings [Aborted]")
@ -225,9 +213,6 @@ while PublicIP <= 2:
server.quit()
CurrentTime = time.strftime("%H:%M")
MailMessage="[ip2e-daemon] ["+CurrentTime+"] Email was sent successfully"
if os.name == "posix":
print (chr(27)+"[1;32m"+MailMessage+" ("+ToEmail+")")
elif os.name == "nt":
GreenColor()
print (MailMessage+" ("+ToEmail+")")
editlog.write(MailMessage+" to "+ToEmail+"\n")
@ -235,10 +220,6 @@ while PublicIP <= 2:
except SMTPException:
CurrentTime = time.strftime("%H:%M")
MailMessage="[ip2e-daemon] ["+CurrentTime+"] Fail to send email"
if os.name == "posix":
print (chr(27)+"[1;31m"+MailMessage+" ("+ToEmail+")")
print (chr(27)+"[1;33m"+"[ip2e-daemon] ["+CurrentTime+"] Retrying in 5 seconds...")
elif os.name == "nt":
RedColor()
print (MailMessage+" ("+ToEmail+")")
print ("[ip2e-daemon] ["+CurrentTime+"] Retrying in 5 seconds...")
@ -256,9 +237,6 @@ while PublicIP <= 2:
createNewip2eIPcf()
writeNewip2eIPcf()
CurrentTime = time.strftime("%H:%M")
if os.name == "posix":
print (chr(27)+"[1;33m"+"[ip2e-daemon] ["+CurrentTime+"] Next update in 10 minutes...")
elif os.name == "nt":
GreenColor()
print ("[ip2e-daemon] ["+CurrentTime+"] Next update in 10 minutes...")
editlog.write("[ip2e-daemon] ["+CurrentTime+"] Next update in 10 minutes...\n")

View File

@ -5,7 +5,7 @@
# ip2e (IP to email) - See the log file. |
# Created by clamsawd (clamsawd@openmailbox.org) |
# Licensed by GPL v.3 |
# Last update: 29-10-2015 |
# Last update: 30-10-2015 |
# |
# Dependences: curl or wget |
# Compatible with Python 3.x |