Browse Source

added setup.py

master
Holger Frey 6 years ago
parent
commit
0715ad9248
  1. 1
      .gitignore
  2. 12
      Pipfile
  3. 25
      Pipfile.lock
  4. 2
      s2watchdog/__init__.py
  5. 64
      s2watchdog/pysema.py
  6. 35
      setup.py

1
.gitignore vendored

@ -24,6 +24,7 @@ var/
*.egg-info/ *.egg-info/
.installed.cfg .installed.cfg
*.egg *.egg
.venv/
# PyInstaller # PyInstaller
# Usually these files are written by a python script from a template # Usually these files are written by a python script from a template

12
Pipfile

@ -0,0 +1,12 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
"s2watchdog" = {editable = true, path = "."}
[dev-packages]
[requires]
python_version = "3.7"

25
Pipfile.lock generated

@ -0,0 +1,25 @@
{
"_meta": {
"hash": {
"sha256": "a7568a70424d02f7de75f3c40f0434e4a03581a9e51e8f18117c08b4025b9261"
},
"pipfile-spec": 6,
"requires": {
"python_version": "3.7"
},
"sources": [
{
"name": "pypi",
"url": "https://pypi.org/simple",
"verify_ssl": true
}
]
},
"default": {
"s2watchdog": {
"editable": true,
"path": "."
}
},
"develop": {}
}

2
s2watchdog/__init__.py

@ -0,0 +1,2 @@
def test():
print('TESTRUN')

64
s2watchdog/pysema.py

@ -0,0 +1,64 @@
''' simple tool for sending email with sendmail, postfix or ssmtpd
import pysema
send(
['alice@example.com', 'bob@example.com'],
'really good subject line',
'Message body goes here'
)
'''
import subprocess
from email.message import EmailMessage
# path to the sendmail programm
SENDMAIL_PATH = '/usr/sbin/sendmail'
class SendMailException(Exception):
''' Exception while using pysema '''
pass
def send(to=None, subject='', message='', **headers):
msg = create_message(to, subject, message, **headers)
send_message(msg)
def create_message(to=None, subject='', message='', **headers):
if isinstance(to, str):
recipients = to
elif isinstance(to, (list, set, tuple)):
recipients = ', '.join(to)
else:
raise SendMailException('No recipients given')
# ensure that the 'from' keyword (if given) is uppercase
sender_mail = headers.pop('from', None)
if sender_mail is not None:
headers['From'] = sender_mail
headers['To'] = recipients
headers['Subject'] = subject
msg = EmailMessage()
msg.set_content(message)
for key, value in headers.items():
msg[key] = value
return msg
def send_message(msg):
if not isinstance(msg, EmailMessage):
raise SendMailException('Type Error: not an EmailMessage')
try:
subprocess.run(
[SENDMAIL_PATH, '-t', '-oi'],
input=msg.as_bytes(),
check=True
)
except subprocess.CalledProcessError as e:
raise SendMailException from e

35
setup.py

@ -0,0 +1,35 @@
import os
from setuptools import setup, find_packages
here = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(here, 'README.md')) as f:
README = f.read()
requires = [
]
setup(
name='s2watchdog',
version='0.0.1',
description='simple watchdog script for our deep freezer alert system',
long_description=README,
classifiers=[
'Programming Language :: Python',
'Environment :: Console',
'Topic :: System :: Monitoring',
],
author='Holger Frey',
author_email='frey@imtek.de',
url='https://git.cpi.imtek.uni-freiburg.de/holgi/s2watchdog',
keywords='alerts',
packages=find_packages(),
include_package_data=True,
zip_safe=False,
install_requires=requires,
entry_points={
'console_scripts': [
's2watchdog = s2watchdog:test',
],
},
)
Loading…
Cancel
Save