Skip to content

Commit

Permalink
release 0.9.0
Browse files Browse the repository at this point in the history
miccoli committed Jan 4, 2016
2 parents 2cec574 + 1a87630 commit 888e912
Showing 30 changed files with 847 additions and 443 deletions.
45 changes: 11 additions & 34 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,38 +1,15 @@
*.py[cod]
MANIFEST

# C extensions
*.so

# Packages
# general things to ignore
build/
dist/
*.egg-info/
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg
lib
lib64
__pycache__

# Installer logs
pip-log.txt
*.py[cod]
__pycache__/

# Unit test / coverage reports
.coverage
# tox
.tox
nosetests.xml

# Translations
*.mo

# docs/sphinx
/docs/_build/

# emacs backup files
*~
# docutil generated
/README.html
/CHANGELOG.html
/TODO.html
33 changes: 33 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Changelog
=========

v0.9.0 (2016-01-04)
-------------------

No major new features, API cleanup to ensure that connections are
properly closed. Functions that return binary data return ``bytes``.

* implement dummy context management protocol for ``_Proxy``
for consitency with _PersistentProxy
* ``OwnetProxy`` class deprecated
* create a diagnostics directory ``./diags``
* move test suite from ``./test`` to ``./tests``
* ``pyownet.protocol._OwnetConnection.req()`` returns ``bytes`` and not
``bytearray``

This is due to a simplification in
``pyownet.protocol._OwnetConnection._read_socket()`` method.
* better connection logic in ``pyownet.protocol.proxy()`` factory:
first connect or raise ``protocol.ConnError``,
then test owserver protocol or raise ``protocol.ProtocolError``
* use relative imports in ``pyownet.protocol``
* ``./test`` and ``./examples`` minor code refactor
* ``.gitignore`` cleanup (use only project specific ignores)
* add ``__del__`` in ``_PersistentProxy`` to ensure connection is closed
* use ``with _OwnetConnection`` inside ``_Proxy`` to shutdown sockets
* implement context management protocol for ``_OwnetConnection`` to
guarantee that connection is shutdown on exit
* py26 testing via ``unittest2``
* transform ``./test`` directory in package, so that common code
(used for reading configuration files) can be shared more easily
* move ``./pyownet`` to ``./src/pyownet``
4 changes: 2 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
include *.rst LICENSE.txt
recursive-include test __init__.py test*.py tests.ini
include README.rst CHANGELOG.rst LICENSE.txt
recursive-include tests __init__.py test*.py tests.ini
recursive-include examples *.py
61 changes: 36 additions & 25 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,41 +1,52 @@
pyownet, a pythonic interface to ownet
======================================
pyownet: Python OWFS client library (owserver protocol)
=======================================================

|docs|

.. |docs| image:: https://readthedocs.org/projects/pyownet/badge/?version=latest&style=flat
.. image:: https://readthedocs.org/projects/pyownet/badge/?version=latest&style=flat
:target: http://pyownet.readthedocs.org/en/latest/
:alt: Package Documentation

pyownet is a pure python package that allows to access an `owserver`_
via the `owserver network protocol`_, in short *ownet*.

owserver is part of the `OWFS 1-Wire File System`_:

OWFS is an easy way to use the powerful 1-wire system of
Dallas/Maxim.

OWFS is a simple and flexible program to monitor and control the
physical environment. You can write scripts to read temperature,
flash lights, write to an LCD, log and graph, ...
.. image:: https://img.shields.io/pypi/v/pyownet.svg
:target: https://pypi.python.org/pypi/pyownet
:alt: Python Package Index version

The ``pyownet.protocol`` module is a low-level implementation of the
ownet protocol. Interaction with an owserver takes place via a proxy
object whose methods correspond to ownet messages:
Pyownet is a pure python package that allows network client access to
the `OWFS 1-Wire File System`_ via an `owserver`_ and the `owserver
network protocol`_, in short *ownet*.

::
The ``pyownet.protocol`` module is an implementation of the owserver
client protocol that exposes owserver messages as methods of a proxy
object::

>>> owproxy = pyownet.protocol.proxy(host="owserver.example.com", port=4304)
>>> owproxy.ping()
>>> owproxy.dir()
['/10.67C6697351FF/', '/05.4AEC29CDBAAB/']
>>> owproxy.present('/10.67C6697351FF/temperature')
True
>>> owproxy.read('/10.67C6697351FF/temperature')
' 91.6195'

Python 3 is supported via ``2to3`` and ``use_2to3 = True`` in
``setup.py``.
Installation
------------

To install pyownet::

$ pip install pyownet


Python version support
----------------------

The code base is written in Python 2, but Python 3 is fully supported,
and is the main developing language. Running the ``2to3`` tool will
generate valid and, whenever possible, idiomatic Python 3 code.

Explicitly supported versions are Python 2.6, 2.7, 3.2 through 3.5.


Documentation
-------------

Full package documentation is available at
http://pyownet.readthedocs.org/en/latest/


.. _owserver: http://owfs.org/index.php?page=owserver_protocol
.. _owserver network protocol: http://owfs.org/index.php?page=owserver-protocol
14 changes: 0 additions & 14 deletions TODO

This file was deleted.

10 changes: 10 additions & 0 deletions TODO.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
TODO
====

* Document that every pathname had to by an ASCIIZ string on the wire
in older owlib versions.

* ``FLG_ALIAS`` is apparently not working as expected.

* In the reply to a ``MSG_DIR`` message it seems that the offset field
has the pourpose of coding some info.
1 change: 1 addition & 0 deletions diags/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A collection of (yet) undocumented diagnostic tools.
30 changes: 13 additions & 17 deletions test/stress_p.py → diags/stress_p.py
Original file line number Diff line number Diff line change
@@ -3,36 +3,31 @@
import atexit
import time
import threading
import os
import sys

if sys.version_info < (3, ):
from ConfigParser import ConfigParser
from urlparse import (urlsplit, )
else:
from configparser import ConfigParser
from urllib.parse import (urlsplit, )

from pyownet import protocol


config = ConfigParser()

config.add_section('server')
config.set('server', 'host', 'localhost')
config.set('server', 'port', '4304')

config.read([os.path.join(os.path.dirname(__file__), 'tests.ini')])

HOST = config.get('server', 'host')
PORT = config.get('server', 'port')

MTHR = 10

tst = lambda: time.strftime('%T')


def log(s):
print(tst(), s)


def main():
proxy = protocol.proxy(HOST, PORT, verbose=False)
assert len(sys.argv) == 2
urlc = urlsplit(sys.argv[1], scheme='owserver', allow_fragments=False)
host = urlc.hostname or 'localhost'
port = urlc.port or 4304
assert not urlc.path or urlc.path == '/'

proxy = protocol.proxy(host, port, verbose=False)
pid = ver = ''
try:
pid = int(proxy.read('/system/process/pid'))
@@ -68,6 +63,7 @@ def worker(proxy, id):
iter += 1
nap *= 2


@atexit.register
def goodbye():
log('exiting stress_p')
28 changes: 28 additions & 0 deletions diags/stress_ping.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# script to test bug #1
#
import sys

if sys.version_info < (3, ):
from urlparse import (urlsplit, )
else:
from urllib.parse import (urlsplit, )

from pyownet.protocol import proxy


def main():
assert len(sys.argv) == 2
urlc = urlsplit(sys.argv[1], scheme='owserver', allow_fragments=False)
host = urlc.hostname or 'localhost'
port = urlc.port or 4304
path = urlc.path or '/'

p = proxy(host, port, verbose=True)

while True:
ret = p.read(path)
assert ret, "'%s'" % ret

if __name__ == '__main__':
main()
51 changes: 51 additions & 0 deletions diags/stress_s.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""floods owserver with non persistent requests
This program floods the owserver with non persistent dir() requests.
After about 16384 requests should fail with
'[Errno 49] Can't assign requested address'
"""

from __future__ import print_function

import itertools
import sys
if sys.version_info < (3, ):
from urlparse import (urlsplit, )
else:
from urllib.parse import (urlsplit, )

import pyownet
from pyownet import protocol


def main():
assert len(sys.argv) == 2
urlc = urlsplit(sys.argv[1], scheme='owserver', allow_fragments=False)
host = urlc.hostname or 'localhost'
port = urlc.port or 4304
assert not urlc.path or urlc.path == '/'

p = protocol.proxy(host, port, persistent=False)
pid = 'unknown'
ver = 'unknown'
try:
pid = int(p.read('/system/process/pid'))
ver = p.read('/system/configuration/version').decode()
except protocol.OwnetError:
pass
print(pyownet.__name__, pyownet.__version__, pyownet.__file__)
print('proxy_obj: {}'.format(p))
print('server info: pid {}, ver. {}'.format(pid, ver))

freq = 1 << 12

for i in itertools.count():
try:
_ = p.dir()
except protocol.Error as exc:
print('Iteration {0} raised exception: {1}'.format(i, exc))
break
None if i % freq else print('Iteration {}'.format(i))

if __name__ == '__main__':
main()
Loading

0 comments on commit 888e912

Please sign in to comment.