Skip to content

Commit

Permalink
Merge pull request #115 from motom001/development
Browse files Browse the repository at this point in the history
Daemon überarbeitet und Path auf /usr/local/etc/DoorPi gelegt
  • Loading branch information
motom001 committed Sep 24, 2015
2 parents 9f55bf7 + d4df19d commit 5a1d13a
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 96 deletions.
21 changes: 14 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
sudo: false
language: python
python:
- "2.7"
# command to install dependencies
install:
- "python setup.py install"
# command to run tests
script:
- "doorpi_cli --test --trace"
- '2.7'
install:
- python setup.py install
script:
- doorpi_cli --test --trace
deploy:
provider: pypi
user:
secure: pcCDIPxwtfOt5a4uhWWDf+tl8H4yUb6fOKJfviMrFTH6CvTnapi2BYqpuzrC7n0cBKT1oVybs3AI2/hhzXvMrxJsqpi7iEY1hWJ8cdL+/Rvi8/HJB8+t6EYoS7BVZIH9ySUkfSAzbnvG3FFDa41ZwOseFjvjWKg68mPNLGa1rIuIm5HGlhKZQR1XV9dOLZarmB0u/qHF8xNHAhTDmfQ+Ktd3SzylY2Pv60DZpjw1h3jQ1+7r2S8HvYn9eHUtejb05kZ0rKcGR+gKATS9wK/4i236hKegTIVkiFPcBFKhEIk0WEkF9fH6yusgForcVutlALdo+qTXHmq0TQW6TNrw+1p4HWdoi6YHmRqx/nawkLmMmmgoW1PpkAqf/LqnOqQArCWK/EcMVXc410cAXOigkbg4MjVBSGu9AoXAY2JVTYxGlQ7clolsnYQTQUrEhizHwtXzBhW+YCEvMEdL2DyeNAi+EuhfdIahcCu89Xq9hvEfc/+GxFw80+6tl53fLSBWD5jZOmwQltVMSGyBbkLGXjxmyS5rGRaoN/HPHK2ibojhoWHpa8qatFAN90r10fpNk5qSRcAXSpeiBRA4ron5l58e3lZbkfz2hsEGOrB/WKrDzrFYcqPeZ4Wi7IXPPWpE15M3hno8MUjKccKpL3A2luhBryJgp3XikYLofHzoSQk=
password:
secure: dFEcLae9ppOvAKDqowjMBnLV8fhcbe2I+97vDds3CiCxJXlOVORk4S5hoc1YD/HMUNjrRXE1GvLmQju0K3uSfiQdn6JIJCknF2XV5IIRzSDSL4X5HEUDgZDzZMDwRIcAt14YRWDpapFDfhEM+1fdrXO2TbKmIM4Xmb4ErpMuwZuZyDJ4A2xsfpqiwpaMDm91t/CLkIbbwUifSLFXwl4ZvoMH0WPjqQSYdKXl0rx+ndvlDPq3zaE7ZJOfIzku4xuuXJ2OwwBAFgg4D1F+fGq9wrFe0t7BQqb4tYmTLJ/dJyKsHxUVUObWSFxxps43F8fasSmz9YhyTaTdOh4ArCQfXi28bCbZsu5NTio2UcCI24LcekKudxolslyMJ04AfHFDuCGEWYSGT5AJzBnDs6ElSh1uaxCk7OHo2aG3xl9odF3GG8fnc8cFAqesUQGObasY91cTALyNIcGvl2UdOyTpRr/ryHleQu2mnJtX6cPcYSjql5bzpgwH25B04aHeFCDiUoE/XX5diSv6U3YSmJDAxJS4lKs76u69GhwoaRYnPFpbqHYkYZ0YVYerZe4VqShUCE1I+1CH+VETZjIFK+v1/ZlbFHBELDSAFwMs1kJuuJPsrP7AxjqwY7mL3npVofq1i7kX6MXHCiRCeIexDwcwT5BOq4da8+7olGh3w41VRsw=
distributions: sdist bdist bdist_egg bdist_wheel
on:
branch: master
24 changes: 16 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
DoorPi: VoIP Door-Intercomstation with Raspberry Pi
****************************************************

|travis_status_master|
|travis_status_master| |code_climate_badge|

:DoorPi @ `PyPi`_:
|pypi_latest_version| |pypi_License|
Expand Down Expand Up @@ -89,15 +89,17 @@ via `PyPi`_:
.. code-block:: bash
sudo pip install doorpi &&
sudo doorpi_cli --trace
doorpi_cli --trace
via `GitHub`_:

.. code-block:: bash
git clone https://github.com/motom001/DoorPi.git /tmp/DoorPi
sudo python /tmp/DoorPi/setup.py build -b /tmp/DoorPi install
sudo doorpi_cli --trace
sudo rm -r -f /tmp/DoorPi
git clone https://github.com/motom001/DoorPi.git /tmp/DoorPi
cd /tmp/DoorPi
sudo python setup.py install
doorpi_cli --trace
-----------------
Expand Down Expand Up @@ -175,9 +177,11 @@ via `GitHub`_:

.. code-block:: bash
git clone https://github.com/motom001/DoorPi.git /tmp/DoorPi
sudo python /tmp/DoorPi/setup.py build -b /tmp/DoorPi install
sudo doorpi_cli --trace
sudo rm -r -f /tmp/DoorPi
git clone https://github.com/motom001/DoorPi.git /tmp/DoorPi
cd /tmp/DoorPi
sudo python setup.py install
doorpi_cli --trace
-----------------
Configuration
Expand All @@ -203,6 +207,10 @@ But you should change the `BASE_PATH <https://github.com/motom001/DoorPi/blob/ma
.. |travis_status_master| image:: https://travis-ci.org/motom001/DoorPi.svg?branch=master
:target: https://travis-ci.org/motom001/DoorPi

.. |code_climate_badge| image:: https://codeclimate.com/github/motom001/DoorPi/badges/gpa.svg
:target: https://codeclimate.com/github/motom001/DoorPi
:alt: Code Climate

.. |pypi_License| image:: https://img.shields.io/pypi/l/DoorPi.svg
:target: https://creativecommons.org/licenses/by-nc/4.0/
:alt: CC BY-NC 4.0
Expand Down
20 changes: 10 additions & 10 deletions doorpi/docs/service/doorpi → doorpi/docs/service/doorpi.tpl
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: DoorPi
# Provides: !!package!!
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: DoorPi
# Description: VoIP Intercom Service DoorPi
# Short-Description: !!package!!
# Description: !!project!!
### END INIT INFO

. /lib/lsb/init-functions

NAME=DoorPi
DESC="VoIP Intercom Service"
DAEMON=doorpi_cli
DOORPI_PATH=/etc/$NAME
DAEMON_ARGS="--configfile $DOORPI_PATH/conf/doorpi.ini --trace"
PIDFILE=/var/run/doorpi.pid
SCRIPTNAME=/etc/init.d/doorpi
NAME=!!package!!
DESC="!!project!!"
DAEMON=!!doorpi_executable!!
DOORPI_PATH=!!doorpi_path!!
DAEMON_ARGS="!!daemon_args!!"
PIDFILE=!!pidfile!!
SCRIPTNAME=!!daemon_folder!!/!!daemon_name!!

# Exit if the package is not installed
if [ none != "$DAEMON" ] && [ ! -x "$DAEMON" ] ; then
Expand Down
2 changes: 1 addition & 1 deletion doorpi/doorpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def name_and_version(self): return str(metadata.package) + " - version: " + meta
@property
def shutdown(self): return self.__shutdown

_base_path = None
_base_path = metadata.doorpi_path
@property
def base_path(self):
if self._base_path is None:
Expand Down
36 changes: 15 additions & 21 deletions doorpi/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@

TRACE_LEVEL = 5
LOG_FORMAT = '%(asctime)s [%(levelname)s] \t[%(name)s] %(message)s'
DEFAULT_LOG_FILENAME = '/var/log/doorpi/doorpi.log'

logger = logging.getLogger(__name__)

log_level = logging.INFO


def add_trace_level():
logging.addLevelName(TRACE_LEVEL, "TRACE")
def trace(self, message, *args, **kws):
Expand All @@ -42,7 +42,6 @@ def init_logger(arguments):
return logging.getLogger(__name__)



def parse_arguments(argv):
arg_parser = argparse.ArgumentParser(
prog=argv[0],
Expand All @@ -60,23 +59,22 @@ def parse_arguments(argv):
arg_parser.add_argument('--trace', action="store_true")
arg_parser.add_argument('--test', action="store_true")
arg_parser.add_argument(
'--configfile',
'-c', '--configfile',
help='configfile for DoorPi - https://github.com/motom001/DoorPi/wiki for more help',
type=file,
dest='configfile',
required = False
dest='configfile'
)
try:
if len(sys.argv) > 1 and sys.argv[1] in ['start', 'stop', 'restart', 'status']: # running as daemon? cut first argument
return arg_parser.parse_args(args=sys.argv[2:])
return arg_parser.parse_args(args=sys.argv[2:])
else:
return arg_parser.parse_args(args=sys.argv[1:])
return arg_parser.parse_args(args=sys.argv[1:])
except IOError:
print("EXCEPTION: configfile does not exist or is not readable")
print("please refer to the DoorPi wiki for more information ")
print("<https://github.com/motom001/DoorPi/wiki>")
raise SystemExit(1)


def files_preserve_by_path(*paths):
wanted=[]
for path in paths:
Expand All @@ -95,15 +93,6 @@ def fd_wanted(fd):
fd_max = getrlimit(RLIMIT_NOFILE)[1]
return [ fd for fd in xrange(fd_max) if fd_wanted(fd) ]

def get_status_from_doorpi(argv):
try:
print("called: %s" % argv)
import urllib2
print(urllib2.urlopen("http://127.0.0.1:8080/status?json&output=all").read())
except Exception as ex:
print("couln't get Status (Message: %s)" % ex)
return 1
return 0

def main_as_daemon(argv):
if argv[1] is 'reload':
Expand All @@ -114,9 +103,13 @@ def main_as_daemon(argv):
else:
parsed_arguments = parse_arguments(argv)

if not os.path.exists(metadata.log_folder):
os.makedirs(metadata.log_folder)

log_file = os.path.join(metadata.log_folder, "doorpi.log")
logrotating = logging.handlers.RotatingFileHandler(
DEFAULT_LOG_FILENAME,
maxBytes=50000,
log_file,
maxBytes=5000000,
backupCount=10
)
global log_level
Expand All @@ -134,7 +127,7 @@ def main_as_daemon(argv):

daemon_runner = runner.DaemonRunner(doorpi.DoorPi(parsed_arguments))
#This ensures that the logger file handle does not get closed during daemonization
daemon_runner.daemon_context.files_preserve = files_preserve_by_path(DEFAULT_LOG_FILENAME)
daemon_runner.daemon_context.files_preserve = files_preserve_by_path(log_file)
try:
daemon_runner.do_action()
logger.info('loaded with arguments: %s', str(argv))
Expand All @@ -148,9 +141,9 @@ def main_as_daemon(argv):
print("Exception NameError: %s" % ex)
finally:
doorpi.DoorPi().destroy()

return 0


def main_as_application(argv):

parsed_arguments = parse_arguments(argv)
Expand All @@ -164,6 +157,7 @@ def main_as_application(argv):

return 0


def entry_point():
init_logger(sys.argv)

Expand Down
26 changes: 24 additions & 2 deletions doorpi/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
package = 'DoorPi'
project = "VoIP Door-Intercomstation with Raspberry Pi"
project_no_spaces = project.replace(' ', '')
version = '2.4.1.0'
version = '2.4.1.2'
description = 'provide intercomstation to the doorstation by VoIP'
keywords = ['intercom', 'VoIP', 'doorstation', 'home automation', 'IoT']
authors = ['Thomas Meissner']
Expand All @@ -30,7 +30,7 @@
'missing someone? -> sorry -> mail me'
]
supporter_string = '\n'.join(supporters)
copyright = "%s, 2014-2015"%authors[0]
copyright = "%s, 2014-2015" % authors[0]
license = 'CC BY-NC 4.0'
url = 'https://github.com/motom001/DoorPi'

Expand All @@ -51,3 +51,25 @@
authors = '\n'.join(author_strings),
supporters = '\n '.join(supporters),
url = url)


if os.name == 'posix':
dummy_file = 'doorpi/docs/dummy_file'
doorpi_path = os.path.join('/usr/local/etc', package)
pidfile = '/var/run/%s.pid' % package.lower()
daemon_folder = '/etc/init.d'
daemon_name = package.lower()
daemon_name_template = 'doorpi/docs/service/doorpi.tpl'
daemon_name_template_parsed = 'doorpi/docs/service/doorpi'
daemon_args = '--configfile $DOORPI_PATH/conf/doorpi.ini --trace'
doorpi_executable = '/usr/local/bin/doorpi_cli'
log_folder = '%s/log' % doorpi_path
try:
if not os.path.exists(doorpi_path):
os.makedirs(doorpi_path)
except OSError:
doorpi_path = os.path.join(os.path.expanduser('~'), package)
else:
raise Exception('os unknown')


2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ RPi.GPIO >= 0.5.11
pifacedigitalio >= 3.0.5
pyserial >= 2.7
watchdog >= 0.8.3
daemon >= 1.1
python-daemon
linphone4raspberry

0 comments on commit 5a1d13a

Please sign in to comment.