Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
ca3bd59
Further python3 changes
Nov 17, 2020
a4c2061
Again py3 change
Nov 17, 2020
297a4a3
Further py3 changes
uenz Nov 18, 2020
81729b5
Chasnges for Py3
Nov 22, 2020
a47a8bd
Convert binary string to ascii
Nov 22, 2020
a471588
Changes for py3
Nov 22, 2020
a5612e2
Changes for py3
Nov 22, 2020
41c02fb
enablerd rts
Nov 22, 2020
21bfd13
searching
Nov 22, 2020
137e9c1
searching
Nov 23, 2020
dd8c510
searching
Nov 23, 2020
06da7dd
searching
Nov 23, 2020
0411459
searching
Nov 23, 2020
f6d168a
QuickFix for encode error
Nov 24, 2020
c202207
QuickFix for encode error
Nov 24, 2020
7194fe3
QuickFix for encode error
Nov 24, 2020
3fd803f
Locked eMail transition
Nov 24, 2020
724aa4c
Locked eMail transition
Nov 24, 2020
6f72e8e
turn off isr before sending mail
Nov 27, 2020
a73ab74
turn off isr before sending mail
Nov 27, 2020
c419c92
on mail
Nov 28, 2020
f873191
on mail
Nov 28, 2020
7c9298f
Update config_for_pico.sh
uenz Nov 29, 2021
38526a2
Py 3 adjustments
uenz Feb 19, 2023
142fde5
Added missing file
uenz Feb 19, 2023
37f21c1
Update daemon.py
uenz Feb 19, 2023
5b3ebad
Bug fix in daemon.py
uenz Feb 19, 2023
e25d38a
Merge branch 'python3' of github.com:uenz/PiModules into python3
uenz Feb 19, 2023
8216231
Dont use daemon mode for service
uenz Feb 19, 2023
f5868d2
Update config_for_pico.sh
uenz Oct 15, 2023
afd1b2e
Update setup.py
uenz Oct 18, 2023
95029fd
Update setup.py
uenz Oct 18, 2023
cf26f48
Update setup.py
uenz Oct 18, 2023
35dc30a
Update setup.py
uenz Oct 18, 2023
ade18de
Update setup.py
uenz Oct 18, 2023
eff3033
Update setup.py
uenz Oct 18, 2023
ce97642
Made venv possible
uenz Oct 25, 2023
4de4813
Squashed commit of the following:
uenz Apr 8, 2025
c36ac00
Updated licence in toml
uenz Apr 9, 2025
3e5b974
Updated dependencies in toml
uenz Apr 9, 2025
dfd6d57
Updated dependencies in toml
uenz Apr 9, 2025
6b902b7
Update pyproject.toml
uenz Nov 17, 2025
6de7a69
Update pyproject.toml
uenz Nov 17, 2025
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
17 changes: 7 additions & 10 deletions code/python/package/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@ This directory contains the installation scripts and the PiModules(R) Python pac
Installation
------------

First you need to install a couple of Python dependencies. Install python-pip like this:
First you need to install a couple of Python dependencies. Install python3-pip like this:

sudo apt-get install python-pip
sudo apt-get install python3-pip

Then install both `jinja2` and `xmltodict` like this:

sudo pip install jinja2
sudo pip install xmltodict
sudo pip3 install jinja2
sudo pip3 install xmltodict

Both of the above libraries are used in the sending of email alerts by the file-safe shutdown
Both of the above libraries are used in the sending of email alerts by the file-safe shutdown
daemon.

Now install the pimodules package:

sudo python setup.py install
sudo python3 setup.py install

You can record what files are installed by the above process by running it like this:

sudo python setup.py install --record <filename>
sudo python3 setup.py install --record <filename>

Where <filename> will be a text file containing one line per file installed by the process.

Expand Down Expand Up @@ -68,6 +68,3 @@ This file.
* setup.py

Installation file, see `README.md` in the directory above this one.



144 changes: 72 additions & 72 deletions code/python/package/pimodules/alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,78 +8,78 @@


def get_host_name():
try:
command = "uname -n"
process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
output = process.communicate()[0]
return output
except:
return None
try:
command = "uname -n"
process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
output = process.communicate()[0]
return output
except:
return None


def get_ip_address():
try:
command = "hostname -I"
process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
output = process.communicate()[0]
return output
except:
return None


def sendEmail( emailserver, username, port, security, fromAddr, toAddr, b64Password, msgSubjectTemplate, msgBodyTemplate):
try:
port = int(port)
except ValueError:
port = 0

try:
now = datetime.datetime.now()
host = get_host_name()
ipaddress = get_ip_address()
except:
raise

password = base64.b64decode(b64Password)

tVars= { 'now' : now, 'host' : host, 'ipaddress' : ipaddress }

try:
templateLoader = jinja2.FileSystemLoader(searchpath="/")
templateEnv = jinja2.Environment( loader=templateLoader )

subjectTemplate = templateEnv.get_template(msgSubjectTemplate)
bodyTemplate = templateEnv.get_template(msgBodyTemplate)

msgSubject = subjectTemplate.render(tVars)
msgBody = bodyTemplate.render(tVars)

except:
raise

# Writing the message
msg = MIMEText(msgBody)
msg['Subject'] = msgSubject
msg['From'] = fromAddr
msg['To'] = toAddr

# Sending the message
try:
if port:
serverstring = format("%s:%d" % (emailserver, port))
else:
serverstring = emailserver

if security.lower() in ['ssl']:
server = smtplib.SMTP_SSL(serverstring)
else:
server = smtplib.SMTP(serverstring)
server.starttls()

server.login(username, password)
server.sendmail(fromAddr, [toAddr], msg.as_string())
server.quit()
except:
raise

return True
try:
command = "hostname -I"
process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
output = process.communicate()[0]
return output
except:
return None


def sendEmail(emailserver, username, port, security, fromAddr, toAddr, b64Password, msgSubjectTemplate, msgBodyTemplate):
try:
port = int(port)
except ValueError:
port = 0

try:
now = datetime.datetime.now()
host = get_host_name().decode('utf-8')
ipaddress = get_ip_address()
except:
raise

password = base64.b64decode(b64Password).decode('utf-8')

tVars = {'now': now, 'host': host, 'ipaddress': ipaddress}

try:
templateLoader = jinja2.FileSystemLoader(searchpath="/")
templateEnv = jinja2.Environment(loader=templateLoader)

subjectTemplate = templateEnv.get_template(msgSubjectTemplate)
bodyTemplate = templateEnv.get_template(msgBodyTemplate)

msgSubject = subjectTemplate.render(tVars)
msgBody = bodyTemplate.render(tVars)

except:
raise

# Writing the message
msg = MIMEText(msgBody)
msg['Subject'] = msgSubject
msg['From'] = fromAddr
msg['To'] = toAddr

# Sending the message
try:
if port:
serverstring = format("%s:%d" % (emailserver, port))
else:
serverstring = emailserver

if security.lower() in ['ssl']:
server = smtplib.SMTP_SSL(serverstring)
else:
server = smtplib.SMTP(serverstring)
server.starttls()

server.login(username, password)
server.sendmail(fromAddr, [toAddr], msg.as_string())
server.quit()
except:
raise

return True
4 changes: 1 addition & 3 deletions code/python/package/pimodules/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ def write_config_xml(xmlfile, dict):
with open(xmlfile, "wt") as fo:
xmltodict.unparse(dict, fo, pretty=True)
except IOError as e:
print "Error writing XML file: ", e
print("Error writing XML file: "+e)
return False

return True


Loading