├── MANIFEST.in
├── requirements.txt
├── docs
├── _static
│ └── fork-me.png
├── _templates
│ └── layout.html
├── index.rst
├── Makefile
├── make.bat
└── conf.py
├── .gitignore
├── .travis.yml
├── tox.ini
├── asyncdgt
├── _info.py
├── __main__.py
└── __init__.py
├── test.py
├── setup.py
├── README.rst
├── release.py
└── LICENSE.txt
/MANIFEST.in:
--------------------------------------------------------------------------------
1 | README.rst
2 | LICENSE.txt
3 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | pyee==0.1.0
2 | pyserial==2.7
3 | wheel==0.24.0
4 |
--------------------------------------------------------------------------------
/docs/_static/fork-me.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/niklasf/python-asyncdgt/HEAD/docs/_static/fork-me.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | venv
2 | dist
3 | docs/_build
4 | asyncdgt.egg-info
5 | asyncdgt/__pycache__
6 | pythonhosted.zip
7 | release-*.txt
8 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: python
2 | sudo: false
3 | python:
4 | - "3.4"
5 | - "3.5"
6 | install: pip install tox-travis
7 | script: tox
8 |
--------------------------------------------------------------------------------
/docs/_templates/layout.html:
--------------------------------------------------------------------------------
1 | {% extends "!layout.html" %}
2 | {% block document %}
3 |
4 | {{ super() }}
5 | {% endblock %}
6 |
--------------------------------------------------------------------------------
/docs/index.rst:
--------------------------------------------------------------------------------
1 | .. include:: ../README.rst
2 |
3 | Reference documentation
4 | -----------------------
5 |
6 | .. autofunction:: asyncdgt.connect
7 |
8 | .. autofunction:: asyncdgt.auto_connect
9 |
10 | .. autoclass:: asyncdgt.Connection
11 | :members:
12 | :show-inheritance:
13 |
14 | .. autoclass:: asyncdgt.Board
15 | :members:
16 |
17 | .. autoclass:: asyncdgt.Clock
18 | :members:
19 |
--------------------------------------------------------------------------------
/tox.ini:
--------------------------------------------------------------------------------
1 | [tox]
2 | envlist = py34,py35
3 |
4 | [testenv]
5 | passenv = COVERALLS_REPO_TOKEN TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH
6 | deps =
7 | coverage
8 | coveralls
9 | -rrequirements.txt
10 | commands =
11 | coverage erase
12 | coverage run --source asyncdgt test.py --verbose
13 | coveralls
14 |
15 | [flake8]
16 | ignore = E302,E402,E241,E131,E126,E128
17 | max-line-length = 120
18 |
--------------------------------------------------------------------------------
/asyncdgt/_info.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # This file is part of the python-asyncdgt library.
3 | # Copyright (C) Niklas Fiekas
4 | #
5 | # This program is free software: you can redistribute it and/or modify
6 | # it under the terms of the GNU General Public License as published by
7 | # the Free Software Foundation, either version 3 of the License, or
8 | # (at your option) any later version.
9 | #
10 | # This program is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | # GNU General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU General Public License
16 | # along with this program. If not, see .
17 |
18 | """
19 | Communicate asynchronously with DGT boards.
20 | """
21 |
22 | __author__ = "Niklas Fiekas"
23 |
24 | __email__ = "niklas.fiekas@tu-clausthal.de"
25 |
26 | __version__ = "0.0.1"
27 |
--------------------------------------------------------------------------------
/test.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | # This file is part of the python-asyncdgt library.
4 | # Copyright (C) 2015 Niklas Fiekas
5 | #
6 | # This program is free software: you can redistribute it and/or modify
7 | # it under the terms of the GNU General Public License as published by
8 | # the Free Software Foundation, either version 3 of the License, or
9 | # (at your option) any later version.
10 | #
11 | # This program is distributed in the hope that it will be useful,
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | # GNU General Public License for more details.
15 | #
16 | # You should have received a copy of the GNU General Public License
17 | # along with this program. If not, see .
18 |
19 | import asyncdgt
20 | import unittest
21 |
22 |
23 | class BoardTestCase(unittest.TestCase):
24 | def test_board_fen(self):
25 | board = asyncdgt.Board()
26 | self.assertEqual(board.board_fen(), "8/8/8/8/8/8/8/8")
27 |
28 | fen = "2k3nr/ppp1bpp1/8/4n3/2Pr4/5NPq/PP1BPP1P/R2Q1RK1"
29 | board.set_board_fen(fen)
30 | self.assertEqual(board.board_fen(), fen)
31 |
32 |
33 | if __name__ == "__main__":
34 | unittest.main()
35 |
--------------------------------------------------------------------------------
/setup.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | # This file is part of the python-asyncdgt library.
4 | # Copyright (C) 2015 Niklas Fiekas
5 | #
6 | # This program is free software: you can redistribute it and/or modify
7 | # it under the terms of the GNU General Public License as published by
8 | # the Free Software Foundation, either version 3 of the License, or
9 | # (at your option) any later version.
10 | #
11 | # This program is distributed in the hope that it will be useful,
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | # GNU General Public License for more details.
15 | #
16 | # You should have received a copy of the GNU General Public License
17 | # along with this program. If not, see .
18 |
19 | import sys
20 | import os
21 | import setuptools
22 |
23 | sys.path.insert(0, os.path.abspath("asyncdgt"))
24 | import _info as asyncdgt
25 |
26 |
27 | def read_description():
28 | with open(os.path.join(os.path.dirname(__file__), "README.rst")) as readme:
29 | return readme.read()
30 |
31 |
32 | def dependencies():
33 | deps = []
34 | deps.append("pyee")
35 | deps.append("pyserial")
36 | return deps
37 |
38 |
39 | setuptools.setup(
40 | name="asyncdgt",
41 | version=asyncdgt.__version__,
42 | author=asyncdgt.__author__,
43 | author_email=asyncdgt.__email__,
44 | description=asyncdgt.__doc__.strip().rstrip("."),
45 | long_description=read_description(),
46 | license="GPL3",
47 | keywords="chess dgt",
48 | url="https://github.com/niklasf/python-asyncdgt",
49 | packages=["asyncdgt"],
50 | test_suite="test",
51 | install_requires=dependencies(),
52 | classifiers=[
53 | "Development Status :: 2 - Pre-Alpha",
54 | "Intended Audience :: Developers",
55 | "License :: OSI Approved :: GNU General Public License (GPL)",
56 | "Operating System :: Unix",
57 | "Programming Language :: Python",
58 | "Programming Language :: Python :: 3.4",
59 | "Topic :: Games/Entertainment :: Board Games",
60 | "Topic :: Software Development :: Libraries :: Python Modules",
61 | ],
62 | )
63 |
--------------------------------------------------------------------------------
/README.rst:
--------------------------------------------------------------------------------
1 | asyncdgt: Communicate asynchronously with DGT boards
2 | ====================================================
3 |
4 | asyncdgt uses asyncio to communicate asynchronously with a DGT electronic
5 | chess board.
6 | `View reference documentation `_.
7 |
8 | .. image:: https://badge.fury.io/py/asyncdgt.svg
9 | :target: https://pypi.python.org/pypi/asyncdgt
10 |
11 | .. image:: https://travis-ci.org/niklasf/python-asyncdgt.svg
12 | :target: https://travis-ci.org/niklasf/python-asyncdgt
13 |
14 | Example
15 | -------
16 |
17 | Create an event loop and a connection to the DGT board.
18 |
19 | .. code:: python
20 |
21 | import asyncio
22 |
23 | loop = asyncio.get_event_loop()
24 | dgt = asyncdgt.auto_connect(loop, ["/dev/ttyACM*"])
25 |
26 | Register some `pyee `__ event handlers. They
27 | will be called whenever a board gets connected, disconnected or the position
28 | changed.
29 |
30 | .. code:: python
31 |
32 | @dgt.on("connected")
33 | def on_connected(port):
34 | print("Board connected to {0}!".format(port))
35 |
36 | @dgt.on("disconnected")
37 | def on_disconnected():
38 | print("Board disconnected!")
39 |
40 | @dgt.on("board")
41 | def on_board(board):
42 | print("Position changed:")
43 | print(board)
44 | print()
45 |
46 | Get some information outside of an event handler using the coroutine
47 | ``get_version()``.
48 |
49 | .. code:: python
50 |
51 | print("Version:", loop.run_until_complete(dgt.get_version()))
52 |
53 |
54 | Run the event loop.
55 |
56 | .. code:: python
57 |
58 | try:
59 | loop.run_forever()
60 | except KeyboardInterrupt:
61 | pass
62 | finally:
63 | dgt.close()
64 | loop.close()
65 |
66 | See ``asyncdgt/__main__.py`` for the complete example. Run with
67 | ``python -m asyncdgt /dev/ttyACM0``.
68 |
69 | Hardware
70 | --------
71 |
72 | Tested with the following boards:
73 |
74 | * DGT e-Board 3.1
75 | * DGT e-Board 3.1 Bluetooth
76 |
77 | Clocks:
78 |
79 | * DGT Clock 3000
80 |
81 | Dependencies
82 | ------------
83 |
84 | * Python 3.4
85 | * `pyee `__
86 | * `pyserial `_
87 |
88 | ``pip install -r requirements.txt``
89 |
90 | Related projects
91 | ----------------
92 |
93 | * `python-chess `_,
94 | a general purpose chess library.
95 |
96 | * `picochess `_,
97 | a standalone chess computer for DGT boards. Some of the DGT protocol handling
98 | has been shamelessly extracted from their code.
99 |
100 | License
101 | -------
102 |
103 | python-asyncdtg is licensed under the GPL3. See the ``LICENSE.txt`` file for
104 | the full license text.
105 |
--------------------------------------------------------------------------------
/release.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # Helper script to create and publish a new asyncdgt release.
3 |
4 | import os
5 | import sys
6 | import configparser
7 | import requests
8 | import bs4
9 | import asyncdgt
10 |
11 |
12 | def system(command):
13 | print(command)
14 | if 0 != os.system(command):
15 | sys.exit(1)
16 |
17 |
18 | def check_git():
19 | print("--- CHECK GIT ----------------------------------------------------")
20 | system("git diff --exit-code")
21 |
22 |
23 | def test():
24 | print("--- TEST ---------------------------------------------------------")
25 | system("python test.py")
26 |
27 |
28 | def check_readme():
29 | print("--- CHECK README -------------------------------------------------")
30 | system("python setup.py --long-description | rst2html --strict --no-raw > /dev/null")
31 |
32 |
33 | def tag_and_push():
34 | print("--- TAG AND PUSH -------------------------------------------------")
35 | tagname = "v{0}".format(asyncdgt.__version__)
36 | release_filename = "release-{0}.txt".format(tagname)
37 |
38 | if not os.path.exists(release_filename):
39 | print(">>> Creating {0} ...".format(release_filename))
40 | with open(release_filename, "w") as release_txt:
41 | headline = "asyncdgt {0}".format(tagname)
42 | release_txt.write(headline + os.linesep)
43 |
44 | with open(release_filename, "r") as release_txt:
45 | release = release_txt.read().strip() + os.linesep
46 | print(release)
47 |
48 | with open(release_filename, "w") as release_txt:
49 | release_txt.write(release)
50 |
51 | guessed_tagname = input(">>> Sure? Confirm tagname: ")
52 | if guessed_tagname != tagname:
53 | print("Actual tagname is: {0}".format(tagname))
54 | sys.exit(1)
55 |
56 | system("git tag {0} -s -F {1}".format(tagname, release_filename))
57 | system("git push origin master {0}".format(tagname))
58 | return tagname
59 |
60 |
61 | def pypi():
62 | print("--- PYPI ---------------------------------------------------------")
63 | system("python setup.py sdist upload")
64 |
65 |
66 | def pythonhosted(tagname):
67 | print("--- PYTHONHOSTED -------------------------------------------------")
68 |
69 | print("Creating pythonhosted.zip ...")
70 | system("cd docs; make singlehtml; cd ..")
71 | system("cd docs/_build/singlehtml; zip -r ../../../pythonhosted.zip *; cd ../../..")
72 |
73 | print("Getting credentials ...")
74 | config = configparser.ConfigParser()
75 | config.read(os.path.expanduser("~/.pypirc"))
76 | username = config.get("pypi", "username")
77 | password = config.get("pypi", "password")
78 | auth = requests.auth.HTTPBasicAuth(username, password)
79 | print("Username: {0}".format(username))
80 |
81 | print("Getting CSRF token ...")
82 | session = requests.Session()
83 | res = session.get("https://pypi.python.org/pypi?:action=pkg_edit&name=asyncdgt", auth=auth)
84 | if res.status_code != 200:
85 | print(res.text)
86 | print(res)
87 | sys.exit(1)
88 | soup = bs4.BeautifulSoup(res.text, "html.parser")
89 | csrf = soup.find("input", {"name": "CSRFToken"})["value"]
90 | print("CSRF: {0}".format(csrf))
91 |
92 | print("Uploading ...")
93 | with open("pythonhosted.zip", "rb") as zip_file:
94 | res = session.post("https://pypi.python.org/pypi", auth=auth, data={
95 | "CSRFToken": csrf,
96 | ":action": "doc_upload",
97 | "name": "asyncdgt",
98 | }, files={
99 | "content": zip_file,
100 | })
101 | if res.status_code != 200 or not tagname in res.text:
102 | print(res)
103 | sys.exit(1)
104 |
105 | print("Done.")
106 |
107 |
108 | def github_release(tagname):
109 | print("--- GITHUB RELEASE -----------------------------------------------")
110 | print("https://github.com/niklasf/python-asyncdgt/releases/tag/{0}".format(tagname))
111 |
112 |
113 | if __name__ == "__main__":
114 | check_git()
115 | check_readme()
116 | test()
117 | tagname = tag_and_push()
118 | pypi()
119 | pythonhosted(tagname)
120 | github_release(tagname)
121 |
--------------------------------------------------------------------------------
/asyncdgt/__main__.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # This file is part of the python-asyncdgt library.
3 | # Copyright (C) 2015 Niklas Fiekas
4 | #
5 | # This program is free software: you can redistribute it and/or modify
6 | # it under the terms of the GNU General Public License as published by
7 | # the Free Software Foundation, either version 3 of the License, or
8 | # (at your option) any later version.
9 | #
10 | # This program is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | # GNU General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU General Public License
16 | # along with this program. If not, see .
17 |
18 | """
19 | The asyncdgt library.
20 | Copyright (C) 2015 Niklas Fiekas
21 |
22 | Usage:
23 | python -m asyncdgt [--debug]
24 |
25 | [--debug]
26 | Enable debug logger.
27 |
28 |
29 | The serial port with the DGT board.
30 | """
31 |
32 | import asyncio
33 | import asyncdgt
34 | import logging
35 | import sys
36 | import serial
37 | import serial.tools.list_ports
38 |
39 |
40 | def usage():
41 | # Print usage information.
42 | print(__doc__.strip())
43 |
44 | # List the available ports.
45 | print(" Probably one of:")
46 | for dev, name, info in serial.tools.list_ports.comports():
47 | print(" * {0} ({1})".format(dev, info))
48 |
49 | return 1
50 |
51 |
52 | def main(port_globs):
53 | loop = asyncio.get_event_loop()
54 |
55 | dgt = asyncdgt.auto_connect(loop, port_globs)
56 |
57 | @dgt.on("connected")
58 | def on_connected(port):
59 | print("Board connected to {0}!".format(port))
60 |
61 | @dgt.on("disconnected")
62 | def on_disconnected():
63 | print("Board disconnected!")
64 |
65 | @dgt.on("board")
66 | def on_board(board):
67 | print("Position changed:")
68 | print(board)
69 |
70 | @dgt.on("button_pressed")
71 | def on_button_pressed(button):
72 | print("Button {0} pressed!".format(button))
73 |
74 | @dgt.on("clock")
75 | def on_clock(clock):
76 | print("Clock status changed:", clock)
77 |
78 | # Get some information.
79 | print("Version:", loop.run_until_complete(dgt.get_version()))
80 | print("Serial:", loop.run_until_complete(dgt.get_serialnr()))
81 | print("Long serial:", loop.run_until_complete(dgt.get_long_serialnr()))
82 | print("Board:", loop.run_until_complete(dgt.get_board()).board_fen())
83 |
84 | # Get the clock version.
85 | try:
86 | print("Clock version:", loop.run_until_complete(asyncio.wait_for(dgt.get_clock_version(), 1.0)))
87 | except asyncio.TimeoutError:
88 | print("Clock version request timed out.")
89 |
90 | # Display some text.
91 | print("Displaying text ...")
92 | quote = "Now, I am become death, the destroyer of worlds. Ready"
93 | loop.run_until_complete(clock_display_sentence(dgt, quote))
94 |
95 | # Let the clock beep.
96 | try:
97 | print("Beep ...")
98 | loop.run_until_complete(asyncio.wait_for(dgt.clock_beep(0.1), 1.0))
99 | except asyncio.TimeoutError:
100 | print("Beep not acknowledged in time.")
101 |
102 | # Start a countdown.
103 | try:
104 | print("Countdown ...")
105 | loop.run_until_complete(asyncio.wait_for(dgt.clock_set(left_time=10, right_time=7, left_running=True), 1.0))
106 | except asyncio.TimeoutError:
107 | print("Clock does not respond.")
108 |
109 | # Run the event loop.
110 | print("Running event loop ...")
111 | try:
112 | loop.run_forever()
113 | except KeyboardInterrupt:
114 | pass
115 | finally:
116 | dgt.close()
117 |
118 | pending = asyncio.Task.all_tasks(loop)
119 | loop.run_until_complete(asyncio.gather(*pending))
120 | loop.close()
121 |
122 | return 0
123 |
124 |
125 | @asyncio.coroutine
126 | def clock_display_sentence(dgt, sentence):
127 | for word in sentence.split():
128 | yield from asyncio.sleep(0.2)
129 |
130 | try:
131 | yield from asyncio.wait_for(dgt.clock_text(word), 0.5)
132 | except asyncio.TimeoutError:
133 | print("Sending clock text timed out.")
134 |
135 |
136 | if __name__ == "__main__":
137 | if "--debug" in sys.argv:
138 | logging.basicConfig(level=logging.DEBUG)
139 |
140 | port_globs = [arg for arg in sys.argv[1:] if arg != "--debug"]
141 | if not port_globs:
142 | sys.exit(usage())
143 | else:
144 | sys.exit(main(port_globs))
145 |
--------------------------------------------------------------------------------
/docs/Makefile:
--------------------------------------------------------------------------------
1 | # Makefile for Sphinx documentation
2 | #
3 |
4 | # You can set these variables from the command line.
5 | SPHINXOPTS =
6 | SPHINXBUILD = python $(shell which /usr/bin/sphinx-build)
7 | PAPER =
8 | BUILDDIR = _build
9 |
10 | # User-friendly check for sphinx-build
11 | ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1)
12 | $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/)
13 | endif
14 |
15 | # Internal variables.
16 | PAPEROPT_a4 = -D latex_paper_size=a4
17 | PAPEROPT_letter = -D latex_paper_size=letter
18 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
19 | # the i18n builder cannot share the environment and doctrees with the others
20 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
21 |
22 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest coverage gettext
23 |
24 | help:
25 | @echo "Please use \`make ' where is one of"
26 | @echo " html to make standalone HTML files"
27 | @echo " dirhtml to make HTML files named index.html in directories"
28 | @echo " singlehtml to make a single large HTML file"
29 | @echo " pickle to make pickle files"
30 | @echo " json to make JSON files"
31 | @echo " htmlhelp to make HTML files and a HTML help project"
32 | @echo " qthelp to make HTML files and a qthelp project"
33 | @echo " applehelp to make an Apple Help Book"
34 | @echo " devhelp to make HTML files and a Devhelp project"
35 | @echo " epub to make an epub"
36 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
37 | @echo " latexpdf to make LaTeX files and run them through pdflatex"
38 | @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx"
39 | @echo " text to make text files"
40 | @echo " man to make manual pages"
41 | @echo " texinfo to make Texinfo files"
42 | @echo " info to make Texinfo files and run them through makeinfo"
43 | @echo " gettext to make PO message catalogs"
44 | @echo " changes to make an overview of all changed/added/deprecated items"
45 | @echo " xml to make Docutils-native XML files"
46 | @echo " pseudoxml to make pseudoxml-XML files for display purposes"
47 | @echo " linkcheck to check all external links for integrity"
48 | @echo " doctest to run all doctests embedded in the documentation (if enabled)"
49 | @echo " coverage to run coverage check of the documentation (if enabled)"
50 |
51 | clean:
52 | rm -rf $(BUILDDIR)/*
53 |
54 | html:
55 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
56 | @echo
57 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
58 |
59 | dirhtml:
60 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
61 | @echo
62 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
63 |
64 | singlehtml:
65 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
66 | @echo
67 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
68 |
69 | pickle:
70 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
71 | @echo
72 | @echo "Build finished; now you can process the pickle files."
73 |
74 | json:
75 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
76 | @echo
77 | @echo "Build finished; now you can process the JSON files."
78 |
79 | htmlhelp:
80 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
81 | @echo
82 | @echo "Build finished; now you can run HTML Help Workshop with the" \
83 | ".hhp project file in $(BUILDDIR)/htmlhelp."
84 |
85 | qthelp:
86 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
87 | @echo
88 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \
89 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:"
90 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/asyncdgt.qhcp"
91 | @echo "To view the help file:"
92 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/asyncdgt.qhc"
93 |
94 | applehelp:
95 | $(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp
96 | @echo
97 | @echo "Build finished. The help book is in $(BUILDDIR)/applehelp."
98 | @echo "N.B. You won't be able to view it unless you put it in" \
99 | "~/Library/Documentation/Help or install it in your application" \
100 | "bundle."
101 |
102 | devhelp:
103 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
104 | @echo
105 | @echo "Build finished."
106 | @echo "To view the help file:"
107 | @echo "# mkdir -p $$HOME/.local/share/devhelp/asyncdgt"
108 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/asyncdgt"
109 | @echo "# devhelp"
110 |
111 | epub:
112 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
113 | @echo
114 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub."
115 |
116 | latex:
117 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
118 | @echo
119 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
120 | @echo "Run \`make' in that directory to run these through (pdf)latex" \
121 | "(use \`make latexpdf' here to do that automatically)."
122 |
123 | latexpdf:
124 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
125 | @echo "Running LaTeX files through pdflatex..."
126 | $(MAKE) -C $(BUILDDIR)/latex all-pdf
127 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
128 |
129 | latexpdfja:
130 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
131 | @echo "Running LaTeX files through platex and dvipdfmx..."
132 | $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja
133 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
134 |
135 | text:
136 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
137 | @echo
138 | @echo "Build finished. The text files are in $(BUILDDIR)/text."
139 |
140 | man:
141 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
142 | @echo
143 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man."
144 |
145 | texinfo:
146 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
147 | @echo
148 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
149 | @echo "Run \`make' in that directory to run these through makeinfo" \
150 | "(use \`make info' here to do that automatically)."
151 |
152 | info:
153 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
154 | @echo "Running Texinfo files through makeinfo..."
155 | make -C $(BUILDDIR)/texinfo info
156 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
157 |
158 | gettext:
159 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
160 | @echo
161 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
162 |
163 | changes:
164 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
165 | @echo
166 | @echo "The overview file is in $(BUILDDIR)/changes."
167 |
168 | linkcheck:
169 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
170 | @echo
171 | @echo "Link check complete; look for any errors in the above output " \
172 | "or in $(BUILDDIR)/linkcheck/output.txt."
173 |
174 | doctest:
175 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
176 | @echo "Testing of doctests in the sources finished, look at the " \
177 | "results in $(BUILDDIR)/doctest/output.txt."
178 |
179 | coverage:
180 | $(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage
181 | @echo "Testing of coverage in the sources finished, look at the " \
182 | "results in $(BUILDDIR)/coverage/python.txt."
183 |
184 | xml:
185 | $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml
186 | @echo
187 | @echo "Build finished. The XML files are in $(BUILDDIR)/xml."
188 |
189 | pseudoxml:
190 | $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml
191 | @echo
192 | @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml."
193 |
--------------------------------------------------------------------------------
/docs/make.bat:
--------------------------------------------------------------------------------
1 | @ECHO OFF
2 |
3 | REM Command file for Sphinx documentation
4 |
5 | if "%SPHINXBUILD%" == "" (
6 | set SPHINXBUILD=sphinx-build
7 | )
8 | set BUILDDIR=_build
9 | set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% .
10 | set I18NSPHINXOPTS=%SPHINXOPTS% .
11 | if NOT "%PAPER%" == "" (
12 | set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%
13 | set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS%
14 | )
15 |
16 | if "%1" == "" goto help
17 |
18 | if "%1" == "help" (
19 | :help
20 | echo.Please use `make ^` where ^ is one of
21 | echo. html to make standalone HTML files
22 | echo. dirhtml to make HTML files named index.html in directories
23 | echo. singlehtml to make a single large HTML file
24 | echo. pickle to make pickle files
25 | echo. json to make JSON files
26 | echo. htmlhelp to make HTML files and a HTML help project
27 | echo. qthelp to make HTML files and a qthelp project
28 | echo. devhelp to make HTML files and a Devhelp project
29 | echo. epub to make an epub
30 | echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter
31 | echo. text to make text files
32 | echo. man to make manual pages
33 | echo. texinfo to make Texinfo files
34 | echo. gettext to make PO message catalogs
35 | echo. changes to make an overview over all changed/added/deprecated items
36 | echo. xml to make Docutils-native XML files
37 | echo. pseudoxml to make pseudoxml-XML files for display purposes
38 | echo. linkcheck to check all external links for integrity
39 | echo. doctest to run all doctests embedded in the documentation if enabled
40 | echo. coverage to run coverage check of the documentation if enabled
41 | goto end
42 | )
43 |
44 | if "%1" == "clean" (
45 | for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i
46 | del /q /s %BUILDDIR%\*
47 | goto end
48 | )
49 |
50 |
51 | REM Check if sphinx-build is available and fallback to Python version if any
52 | %SPHINXBUILD% 2> nul
53 | if errorlevel 9009 goto sphinx_python
54 | goto sphinx_ok
55 |
56 | :sphinx_python
57 |
58 | set SPHINXBUILD=python -m sphinx.__init__
59 | %SPHINXBUILD% 2> nul
60 | if errorlevel 9009 (
61 | echo.
62 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
63 | echo.installed, then set the SPHINXBUILD environment variable to point
64 | echo.to the full path of the 'sphinx-build' executable. Alternatively you
65 | echo.may add the Sphinx directory to PATH.
66 | echo.
67 | echo.If you don't have Sphinx installed, grab it from
68 | echo.http://sphinx-doc.org/
69 | exit /b 1
70 | )
71 |
72 | :sphinx_ok
73 |
74 |
75 | if "%1" == "html" (
76 | %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html
77 | if errorlevel 1 exit /b 1
78 | echo.
79 | echo.Build finished. The HTML pages are in %BUILDDIR%/html.
80 | goto end
81 | )
82 |
83 | if "%1" == "dirhtml" (
84 | %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml
85 | if errorlevel 1 exit /b 1
86 | echo.
87 | echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml.
88 | goto end
89 | )
90 |
91 | if "%1" == "singlehtml" (
92 | %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml
93 | if errorlevel 1 exit /b 1
94 | echo.
95 | echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml.
96 | goto end
97 | )
98 |
99 | if "%1" == "pickle" (
100 | %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle
101 | if errorlevel 1 exit /b 1
102 | echo.
103 | echo.Build finished; now you can process the pickle files.
104 | goto end
105 | )
106 |
107 | if "%1" == "json" (
108 | %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json
109 | if errorlevel 1 exit /b 1
110 | echo.
111 | echo.Build finished; now you can process the JSON files.
112 | goto end
113 | )
114 |
115 | if "%1" == "htmlhelp" (
116 | %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp
117 | if errorlevel 1 exit /b 1
118 | echo.
119 | echo.Build finished; now you can run HTML Help Workshop with the ^
120 | .hhp project file in %BUILDDIR%/htmlhelp.
121 | goto end
122 | )
123 |
124 | if "%1" == "qthelp" (
125 | %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp
126 | if errorlevel 1 exit /b 1
127 | echo.
128 | echo.Build finished; now you can run "qcollectiongenerator" with the ^
129 | .qhcp project file in %BUILDDIR%/qthelp, like this:
130 | echo.^> qcollectiongenerator %BUILDDIR%\qthelp\asyncdgt.qhcp
131 | echo.To view the help file:
132 | echo.^> assistant -collectionFile %BUILDDIR%\qthelp\asyncdgt.ghc
133 | goto end
134 | )
135 |
136 | if "%1" == "devhelp" (
137 | %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp
138 | if errorlevel 1 exit /b 1
139 | echo.
140 | echo.Build finished.
141 | goto end
142 | )
143 |
144 | if "%1" == "epub" (
145 | %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub
146 | if errorlevel 1 exit /b 1
147 | echo.
148 | echo.Build finished. The epub file is in %BUILDDIR%/epub.
149 | goto end
150 | )
151 |
152 | if "%1" == "latex" (
153 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
154 | if errorlevel 1 exit /b 1
155 | echo.
156 | echo.Build finished; the LaTeX files are in %BUILDDIR%/latex.
157 | goto end
158 | )
159 |
160 | if "%1" == "latexpdf" (
161 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
162 | cd %BUILDDIR%/latex
163 | make all-pdf
164 | cd %~dp0
165 | echo.
166 | echo.Build finished; the PDF files are in %BUILDDIR%/latex.
167 | goto end
168 | )
169 |
170 | if "%1" == "latexpdfja" (
171 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
172 | cd %BUILDDIR%/latex
173 | make all-pdf-ja
174 | cd %~dp0
175 | echo.
176 | echo.Build finished; the PDF files are in %BUILDDIR%/latex.
177 | goto end
178 | )
179 |
180 | if "%1" == "text" (
181 | %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text
182 | if errorlevel 1 exit /b 1
183 | echo.
184 | echo.Build finished. The text files are in %BUILDDIR%/text.
185 | goto end
186 | )
187 |
188 | if "%1" == "man" (
189 | %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man
190 | if errorlevel 1 exit /b 1
191 | echo.
192 | echo.Build finished. The manual pages are in %BUILDDIR%/man.
193 | goto end
194 | )
195 |
196 | if "%1" == "texinfo" (
197 | %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo
198 | if errorlevel 1 exit /b 1
199 | echo.
200 | echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo.
201 | goto end
202 | )
203 |
204 | if "%1" == "gettext" (
205 | %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale
206 | if errorlevel 1 exit /b 1
207 | echo.
208 | echo.Build finished. The message catalogs are in %BUILDDIR%/locale.
209 | goto end
210 | )
211 |
212 | if "%1" == "changes" (
213 | %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes
214 | if errorlevel 1 exit /b 1
215 | echo.
216 | echo.The overview file is in %BUILDDIR%/changes.
217 | goto end
218 | )
219 |
220 | if "%1" == "linkcheck" (
221 | %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck
222 | if errorlevel 1 exit /b 1
223 | echo.
224 | echo.Link check complete; look for any errors in the above output ^
225 | or in %BUILDDIR%/linkcheck/output.txt.
226 | goto end
227 | )
228 |
229 | if "%1" == "doctest" (
230 | %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest
231 | if errorlevel 1 exit /b 1
232 | echo.
233 | echo.Testing of doctests in the sources finished, look at the ^
234 | results in %BUILDDIR%/doctest/output.txt.
235 | goto end
236 | )
237 |
238 | if "%1" == "coverage" (
239 | %SPHINXBUILD% -b coverage %ALLSPHINXOPTS% %BUILDDIR%/coverage
240 | if errorlevel 1 exit /b 1
241 | echo.
242 | echo.Testing of coverage in the sources finished, look at the ^
243 | results in %BUILDDIR%/coverage/python.txt.
244 | goto end
245 | )
246 |
247 | if "%1" == "xml" (
248 | %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml
249 | if errorlevel 1 exit /b 1
250 | echo.
251 | echo.Build finished. The XML files are in %BUILDDIR%/xml.
252 | goto end
253 | )
254 |
255 | if "%1" == "pseudoxml" (
256 | %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml
257 | if errorlevel 1 exit /b 1
258 | echo.
259 | echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml.
260 | goto end
261 | )
262 |
263 | :end
264 |
--------------------------------------------------------------------------------
/docs/conf.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | # -*- coding: utf-8 -*-
3 | #
4 | # asyncdgt documentation build configuration file, created by
5 | # sphinx-quickstart on Sun Sep 13 20:34:05 2015.
6 | #
7 | # This file is execfile()d with the current directory set to its
8 | # containing dir.
9 | #
10 | # Note that not all possible configuration values are present in this
11 | # autogenerated file.
12 | #
13 | # All configuration values have a default; values that are commented out
14 | # serve to show the default.
15 |
16 | import sys
17 | import os
18 | import shlex
19 |
20 | # If extensions (or modules to document with autodoc) are in another directory,
21 | # add these directories to sys.path here. If the directory is relative to the
22 | # documentation root, use os.path.abspath to make it absolute, like shown here.
23 | sys.path.insert(0, os.path.abspath('..'))
24 | import asyncdgt
25 |
26 | # -- General configuration ------------------------------------------------
27 |
28 | # If your documentation needs a minimal Sphinx version, state it here.
29 | #needs_sphinx = '1.0'
30 |
31 | # Add any Sphinx extension module names here, as strings. They can be
32 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
33 | # ones.
34 | extensions = [
35 | 'sphinx.ext.autodoc',
36 | ]
37 | autodoc_member_order = 'bysource'
38 |
39 | # Add any paths that contain templates here, relative to this directory.
40 | templates_path = ['_templates']
41 |
42 | # The suffix(es) of source filenames.
43 | # You can specify multiple suffix as a list of string:
44 | # source_suffix = ['.rst', '.md']
45 | source_suffix = '.rst'
46 |
47 | # The encoding of source files.
48 | #source_encoding = 'utf-8-sig'
49 |
50 | # The master toctree document.
51 | master_doc = 'index'
52 |
53 | # General information about the project.
54 | project = 'asyncdgt'
55 | copyright = '2015, Niklas Fiekas'
56 | author = 'Niklas Fiekas'
57 |
58 | # The version info for the project you're documenting, acts as replacement for
59 | # |version| and |release|, also used in various other places throughout the
60 | # built documents.
61 | #
62 | # The short X.Y version.
63 | version = asyncdgt.__version__
64 | # The full version, including alpha/beta/rc tags.
65 | release = asyncdgt.__version__
66 |
67 | # The language for content autogenerated by Sphinx. Refer to documentation
68 | # for a list of supported languages.
69 | #
70 | # This is also used if you do content translation via gettext catalogs.
71 | # Usually you set "language" from the command line for these cases.
72 | language = None
73 |
74 | # There are two options for replacing |today|: either, you set today to some
75 | # non-false value, then it is used:
76 | #today = ''
77 | # Else, today_fmt is used as the format for a strftime call.
78 | #today_fmt = '%B %d, %Y'
79 |
80 | # List of patterns, relative to source directory, that match files and
81 | # directories to ignore when looking for source files.
82 | exclude_patterns = ['_build']
83 |
84 | # The reST default role (used for this markup: `text`) to use for all
85 | # documents.
86 | #default_role = None
87 |
88 | # If true, '()' will be appended to :func: etc. cross-reference text.
89 | #add_function_parentheses = True
90 |
91 | # If true, the current module name will be prepended to all description
92 | # unit titles (such as .. function::).
93 | #add_module_names = True
94 |
95 | # If true, sectionauthor and moduleauthor directives will be shown in the
96 | # output. They are ignored by default.
97 | #show_authors = False
98 |
99 | # The name of the Pygments (syntax highlighting) style to use.
100 | pygments_style = 'sphinx'
101 |
102 | # A list of ignored prefixes for module index sorting.
103 | #modindex_common_prefix = []
104 |
105 | # If true, keep warnings as "system message" paragraphs in the built documents.
106 | #keep_warnings = False
107 |
108 | # If true, `todo` and `todoList` produce output, else they produce nothing.
109 | todo_include_todos = False
110 |
111 |
112 | # -- Options for HTML output ----------------------------------------------
113 |
114 | # The theme to use for HTML and HTML Help pages. See the documentation for
115 | # a list of builtin themes.
116 | html_theme = 'alabaster'
117 |
118 | # Theme options are theme-specific and customize the look and feel of a theme
119 | # further. For a list of options available for each theme, see the
120 | # documentation.
121 | #html_theme_options = {}
122 |
123 | # Add any paths that contain custom themes here, relative to this directory.
124 | #html_theme_path = []
125 |
126 | # The name for this set of Sphinx documents. If None, it defaults to
127 | # " v documentation".
128 | #html_title = None
129 |
130 | # A shorter title for the navigation bar. Default is the same as html_title.
131 | #html_short_title = None
132 |
133 | # The name of an image file (relative to this directory) to place at the top
134 | # of the sidebar.
135 | #html_logo = None
136 |
137 | # The name of an image file (within the static path) to use as favicon of the
138 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
139 | # pixels large.
140 | #html_favicon = None
141 |
142 | # Add any paths that contain custom static files (such as style sheets) here,
143 | # relative to this directory. They are copied after the builtin static files,
144 | # so a file named "default.css" will overwrite the builtin "default.css".
145 | html_static_path = ['_static']
146 |
147 | # Add any extra paths that contain custom files (such as robots.txt or
148 | # .htaccess) here, relative to this directory. These files are copied
149 | # directly to the root of the documentation.
150 | #html_extra_path = []
151 |
152 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
153 | # using the given strftime format.
154 | #html_last_updated_fmt = '%b %d, %Y'
155 |
156 | # If true, SmartyPants will be used to convert quotes and dashes to
157 | # typographically correct entities.
158 | #html_use_smartypants = True
159 |
160 | # Custom sidebar templates, maps document names to template names.
161 | #html_sidebars = {}
162 |
163 | # Additional templates that should be rendered to pages, maps page names to
164 | # template names.
165 | #html_additional_pages = {}
166 |
167 | # If false, no module index is generated.
168 | #html_domain_indices = True
169 |
170 | # If false, no index is generated.
171 | #html_use_index = True
172 |
173 | # If true, the index is split into individual pages for each letter.
174 | #html_split_index = False
175 |
176 | # If true, links to the reST sources are added to the pages.
177 | #html_show_sourcelink = True
178 |
179 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
180 | #html_show_sphinx = True
181 |
182 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
183 | #html_show_copyright = True
184 |
185 | # If true, an OpenSearch description file will be output, and all pages will
186 | # contain a tag referring to it. The value of this option must be the
187 | # base URL from which the finished HTML is served.
188 | #html_use_opensearch = ''
189 |
190 | # This is the file name suffix for HTML files (e.g. ".xhtml").
191 | #html_file_suffix = None
192 |
193 | # Language to be used for generating the HTML full-text search index.
194 | # Sphinx supports the following languages:
195 | # 'da', 'de', 'en', 'es', 'fi', 'fr', 'h', 'it', 'ja'
196 | # 'nl', 'no', 'pt', 'ro', 'r', 'sv', 'tr'
197 | #html_search_language = 'en'
198 |
199 | # A dictionary with options for the search language support, empty by default.
200 | # Now only 'ja' uses this config value
201 | #html_search_options = {'type': 'default'}
202 |
203 | # The name of a javascript file (relative to the configuration directory) that
204 | # implements a search results scorer. If empty, the default will be used.
205 | #html_search_scorer = 'scorer.js'
206 |
207 | # Output file base name for HTML help builder.
208 | htmlhelp_basename = 'asyncdgtdoc'
209 |
210 | # -- Options for LaTeX output ---------------------------------------------
211 |
212 | latex_elements = {
213 | # The paper size ('letterpaper' or 'a4paper').
214 | #'papersize': 'letterpaper',
215 |
216 | # The font size ('10pt', '11pt' or '12pt').
217 | #'pointsize': '10pt',
218 |
219 | # Additional stuff for the LaTeX preamble.
220 | #'preamble': '',
221 |
222 | # Latex figure (float) alignment
223 | #'figure_align': 'htbp',
224 | }
225 |
226 | # Grouping the document tree into LaTeX files. List of tuples
227 | # (source start file, target name, title,
228 | # author, documentclass [howto, manual, or own class]).
229 | latex_documents = [
230 | (master_doc, 'asyncdgt.tex', 'asyncdgt Documentation',
231 | 'Niklas Fiekas', 'manual'),
232 | ]
233 |
234 | # The name of an image file (relative to this directory) to place at the top of
235 | # the title page.
236 | #latex_logo = None
237 |
238 | # For "manual" documents, if this is true, then toplevel headings are parts,
239 | # not chapters.
240 | #latex_use_parts = False
241 |
242 | # If true, show page references after internal links.
243 | #latex_show_pagerefs = False
244 |
245 | # If true, show URL addresses after external links.
246 | #latex_show_urls = False
247 |
248 | # Documents to append as an appendix to all manuals.
249 | #latex_appendices = []
250 |
251 | # If false, no module index is generated.
252 | #latex_domain_indices = True
253 |
254 |
255 | # -- Options for manual page output ---------------------------------------
256 |
257 | # One entry per manual page. List of tuples
258 | # (source start file, name, description, authors, manual section).
259 | man_pages = [
260 | (master_doc, 'asyncdgt', 'asyncdgt Documentation',
261 | [author], 1)
262 | ]
263 |
264 | # If true, show URL addresses after external links.
265 | #man_show_urls = False
266 |
267 |
268 | # -- Options for Texinfo output -------------------------------------------
269 |
270 | # Grouping the document tree into Texinfo files. List of tuples
271 | # (source start file, target name, title, author,
272 | # dir menu entry, description, category)
273 | texinfo_documents = [
274 | (master_doc, 'asyncdgt', 'asyncdgt Documentation',
275 | author, 'asyncdgt', 'One line description of project.',
276 | 'Miscellaneous'),
277 | ]
278 |
279 | # Documents to append as an appendix to all manuals.
280 | #texinfo_appendices = []
281 |
282 | # If false, no module index is generated.
283 | #texinfo_domain_indices = True
284 |
285 | # How to display URL addresses: 'footnote', 'no', or 'inline'.
286 | #texinfo_show_urls = 'footnote'
287 |
288 | # If true, do not generate a @detailmenu in the "Top" node's menu.
289 | #texinfo_no_detailmenu = False
290 |
--------------------------------------------------------------------------------
/asyncdgt/__init__.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # This file is part of the python-asyncdgt library.
3 | # Copyright (C) Niklas Fiekas
4 | #
5 | # This program is free software: you can redistribute it and/or modify
6 | # it under the terms of the GNU General Public License as published by
7 | # the Free Software Foundation, either version 3 of the License, or
8 | # (at your option) any later version.
9 | #
10 | # This program is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | # GNU General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU General Public License
16 | # along with this program. If not, see .
17 |
18 |
19 | from asyncdgt._info import __doc__
20 | from asyncdgt._info import __author__
21 | from asyncdgt._info import __email__
22 | from asyncdgt._info import __version__
23 |
24 | import asyncio
25 | import collections
26 | import serial
27 | import serial.tools.list_ports
28 | import pyee
29 | import glob
30 | import fnmatch
31 | import logging
32 | import copy
33 | import os
34 | import itertools
35 | import threading
36 | import queue
37 |
38 |
39 | DGT_SEND_RESET = 0x40
40 | DGT_SEND_BRD = 0x42
41 | DGT_SEND_UPDATE_BRD = 0x44
42 | DGT_SEND_UPDATE_NICE = 0x4b
43 | DGT_RETURN_SERIALNR = 0x45
44 | DGT_RETURN_LONG_SERIALNR = 0x55
45 | DGT_SEND_BATTERY_STATUS = 0x4C
46 | DGT_SEND_VERSION = 0x4D
47 |
48 | DGT_FONE = 0x00
49 | DGT_BOARD_DUMP = 0x06
50 | DGT_BWTIME = 0x0D
51 | DGT_FIELD_UPDATE = 0x0E
52 | DGT_EE_MOVES = 0x0F
53 | DGT_BUSADRES = 0x10
54 | DGT_SERIALNR = 0x11
55 | DGT_LONG_SERIALNR = 0x22
56 | DGT_TRADEMARK = 0x12
57 | DGT_VERSION = 0x13
58 | DGT_BOARD_DUMP_50B = 0x14
59 | DGT_BOARD_DUMP_50W = 0x15
60 | DGT_BATTERY_STATUS = 0x20
61 | DGT_LONG_SERIALNR = 0x22
62 |
63 | MESSAGE_BIT = 0x80
64 |
65 | DGT_CLOCK_MESSAGE = 0x2b
66 | DGT_CLOCK_START_MESSAGE = 0x03
67 | DGT_CLOCK_END_MESSAGE = 0x00
68 | DGT_CLOCK_DISPLAY = 0x01
69 | DGT_CLOCK_END = 0x03
70 | DGT_CLOCK_SETNRUN = 0x0a
71 | DGT_CLOCK_BEEP = 0x0b
72 | DGT_CLOCK_ASCII = 0x0c
73 | DGT_CLOCK_SEND_VERSION = 0x09
74 |
75 | PIECE_TO_CHAR = {
76 | 0x01: "P",
77 | 0x02: "R",
78 | 0x03: "N",
79 | 0x04: "B",
80 | 0x05: "K",
81 | 0x06: "Q",
82 | 0x07: "p",
83 | 0x08: "r",
84 | 0x09: "n",
85 | 0x0a: "b",
86 | 0x0b: "k",
87 | 0x0c: "q",
88 | }
89 |
90 | LOGGER = logging.getLogger(__name__)
91 |
92 |
93 | class Board(object):
94 | """
95 | A position on the board.
96 |
97 | >>> board = asyncdgt.Board("rnbqkbnr/pppppppp/8/8/3P4/8/PPP1PPPP/RNBQKBNR")
98 | >>> print(board)
99 | r n b k q b n r
100 | p p p p p p p p
101 | . . . . . . . .
102 | . . . . . . . .
103 | . . . P . . . .
104 | . . . . . . . .
105 | P P P . P P P .
106 | R N B Q K B N R
107 | """
108 |
109 | def __init__(self, board_fen=None):
110 | self.state = bytearray(0x00 for _ in range(64))
111 | if board_fen:
112 | self.set_board_fen(board_fen)
113 |
114 | def board_fen(self):
115 | """
116 | Gets the FEN of the position.
117 |
118 | >>> board = asyncdgt.Board()
119 | >>> board.board_fen()
120 | '8/8/8/8/8/8/8/8'
121 | """
122 | fen = []
123 | empty = 0
124 |
125 | for index, c in enumerate(self.state):
126 | if not c:
127 | empty += 1
128 |
129 | if empty > 0 and (c or (index + 1) % 8 == 0):
130 | fen.append(str(empty))
131 | empty = 0
132 |
133 | if c:
134 | fen.append(PIECE_TO_CHAR[c])
135 |
136 | if (index + 1) % 8 == 0 and index < 63:
137 | fen.append("/")
138 |
139 | return "".join(fen)
140 |
141 | def set_board_fen(self, fen):
142 | """Set a FEN."""
143 | # Ensure there are enough rows.
144 | rows = fen.split("/")
145 | if len(rows) != 8:
146 | raise ValueError("expected 8 rows in the fen: {0}".format(repr(fen)))
147 |
148 | # Validate each row.
149 | for row in rows:
150 | field_sum = 0
151 | previous_was_digit = False
152 |
153 | for c in row:
154 | if c in ["1", "2", "3", "4", "5", "6", "7", "8"]:
155 | if previous_was_digit:
156 | raise ValueError("two subsequent digits in the fen: {0}".format(repr(fen)))
157 | field_sum += int(c)
158 | previous_was_digit = True
159 | elif c in PIECE_TO_CHAR.values():
160 | field_sum += 1
161 | previous_was_digit = False
162 | else:
163 | raise ValueError("invalid character in the fen: {0}".format(repr(fen)))
164 |
165 | if field_sum != 8:
166 | raise ValueError("expected 8 columns per row in fen: {0}".format(repr(fen)))
167 |
168 | # Put the pieces on the board.
169 | self.clear()
170 | square_index = 0
171 | for c in fen:
172 | if c in ["1", "2", "3", "4", "5", "6", "7", "8"]:
173 | square_index += int(c)
174 | elif c != "/":
175 | for piece_code, char in PIECE_TO_CHAR.items():
176 | if c == char:
177 | self.state[square_index] = piece_code
178 | break
179 | else:
180 | assert False
181 |
182 | square_index += 1
183 |
184 | def clear(self):
185 | """Clear the board."""
186 | self.state = bytearray(0x00 for _ in range(64))
187 |
188 | def copy(self):
189 | """Get a copy of the board."""
190 | return copy.deepcopy(self)
191 |
192 | def __str__(self):
193 | builder = []
194 |
195 | for square_index in range(0, 64):
196 | if self.state[square_index]:
197 | builder.append(PIECE_TO_CHAR[self.state[square_index]])
198 | else:
199 | builder.append(".")
200 |
201 | if square_index == 63:
202 | pass
203 | elif square_index % 8 == 7:
204 | builder.append("\n")
205 | else:
206 | builder.append(" ")
207 |
208 | return "".join(builder)
209 |
210 | def __repr__(self):
211 | return "Board({0})".format(repr(self.board_fen()))
212 |
213 | def __eq__(self, other):
214 | return not self.__ne__(other)
215 |
216 | def __ne__(self, other):
217 | if other is None:
218 | return True
219 |
220 | return self.state != other.state
221 |
222 |
223 | class Clock(collections.namedtuple("Clock", ["left_time", "right_time", "left_up"])):
224 | """
225 | The status of the clock.
226 |
227 | *left_time* is the remaining time for the left side in seconds.
228 |
229 | *right_time* is the remaining time for the right side in seconds.
230 |
231 | *left_up* is information about the status of the lever.
232 | """
233 | pass
234 |
235 |
236 | class AsyncDriver(object):
237 | """Provides fully asynchronous serial communication."""
238 |
239 | def __init__(self, connection):
240 | self.connection = connection
241 | self.disconnect()
242 |
243 | def configure_serial(self):
244 | self.connection.serial.timeout = 0
245 | self.connection.serial.writeTimeout = 0
246 |
247 | def connect(self, port):
248 | # Hook serial device into event loop.
249 | self.connection.loop.add_reader(self.connection.serial, self.can_read)
250 |
251 | def disconnect(self):
252 | if self.connection.serial:
253 | self.connection.loop.remove_reader(self.connection.serial)
254 | self.connection.loop.remove_writer(self.connection.serial)
255 |
256 | self.message_id = 0
257 | self.header_buffer = b""
258 | self.message_buffer = b""
259 | self.remaining_header_length = 3
260 | self.remaining_message_length = 0
261 |
262 | self.write_buffer = b""
263 |
264 | def can_read(self):
265 | try:
266 | # Partial header.
267 | if self.remaining_header_length:
268 | header_part = self.connection.serial.read(self.remaining_header_length)
269 | self.header_buffer += header_part
270 | self.remaining_header_length -= len(header_part)
271 |
272 | # Header complete.
273 | if not self.remaining_header_length and not self.message_buffer:
274 | self.message_id = self.header_buffer[0]
275 | self.remaining_message_length = (self.header_buffer[1] << 7) + self.header_buffer[2] - 3
276 |
277 | # Partial message.
278 | if not self.remaining_header_length and self.remaining_message_length:
279 | message_part = self.connection.serial.read(self.remaining_message_length)
280 | self.message_buffer += message_part
281 | self.remaining_message_length -= len(message_part)
282 | except (TypeError, OSError, serial.SerialException):
283 | LOGGER.exception("Error reading from serial port")
284 | self.connection.disconnect()
285 | else:
286 | # Message complete.
287 | if not self.remaining_header_length and not self.remaining_message_length:
288 | self.connection.process_message(self.message_id, self.message_buffer)
289 | self.header_buffer = b""
290 | self.remaining_header_length = 3
291 | self.message_buffer = b""
292 |
293 | def write(self, buf):
294 | # Start writer.
295 | if not self.write_buffer:
296 | self.connection.loop.add_writer(self.connection.serial, self.can_write)
297 |
298 | # Append to buffer.
299 | self.write_buffer += buf
300 |
301 | def can_write(self):
302 | try:
303 | # Write as much as possible without blocking.
304 | bytes_written = self.connection.serial.write(self.write_buffer)
305 | LOGGER.debug("Sent: %s", " ".join(format(c, "02x") for c in self.write_buffer[:bytes_written]))
306 | except (TypeError, OSError, serial.SerialException):
307 | # Connection failed.
308 | LOGGER.exception("Error writing to serial port")
309 | self.connection.disconnect()
310 | else:
311 | # Remove written bytes from buffer.
312 | self.write_buffer = self.write_buffer[bytes_written:]
313 | finally:
314 | # Stop writer.
315 | if not self.write_buffer:
316 | self.connection.loop.remove_writer(self.connection.serial)
317 |
318 |
319 | class ThreadedDriver(object):
320 | """Fallback. Provides threaded serial communication."""
321 |
322 | def __init__(self, connection):
323 | self.connection = connection
324 | self.write_queue = queue.Queue()
325 | self.connected = False
326 |
327 | self.shutdown_marker = object()
328 |
329 | def configure_serial(self):
330 | self.connection.serial.timeout = None
331 | self.connection.serial.writeTimeout = None
332 |
333 | def disconnect(self):
334 | # No longer connected.
335 | self.connected = False
336 |
337 | # Clear the write queue.
338 | while not self.write_queue.empty():
339 | self.write_queue.get_nowait()
340 |
341 | # Wake up the write queue.
342 | self.write_queue.put(self.shutdown_marker)
343 |
344 | def connect(self, port):
345 | if self.connected:
346 | return
347 |
348 | self.connected = True
349 |
350 | # Clear the write queue.
351 | while not self.write_queue.empty():
352 | self.write_queue.get_nowait()
353 |
354 | self.write_thread = threading.Thread(target=self.write_loop)
355 | self.write_thread.daemon = True
356 | self.write_thread.start()
357 |
358 | self.read_thread = threading.Thread(target=self.read_loop)
359 | self.read_thread.daemon = True
360 | self.read_thread.start()
361 |
362 | def write(self, buf):
363 | self.write_queue.put(buf)
364 |
365 | def write_loop(self):
366 | try:
367 | while self.connected:
368 | buf = self.write_queue.get()
369 | if buf is self.shutdown_marker:
370 | break
371 |
372 | self.connection.serial.write(buf)
373 | self.write_queue.task_done()
374 | except (TypeError, OSError, serial.SerialException):
375 | LOGGER.exception("Error writing to serial port")
376 | self.connection.loop.call_soon_threadsafe(self.connection.disconnect)
377 |
378 | def read_loop(self):
379 | try:
380 | while self.connected:
381 | header = self.connection.serial.read(3)
382 | message_id = header[0]
383 | message_length = (header[1] << 7) + header[2]
384 |
385 | message = self.connection.serial.read(message_length - 3)
386 |
387 | self.connection.loop.call_soon_threadsafe(self.connection.process_message, message_id, message)
388 | except (TypeError, OSError, serial.SerialException):
389 | LOGGER.exception("Error reading from serial port")
390 | self.connection.loop.call_soon_threadsafe(self.connection.disconnect)
391 |
392 |
393 | class Connection(pyee.EventEmitter):
394 | """
395 | Manages a DGT board connection.
396 |
397 | *loop* is the :mod:`asyncio` event loop.
398 |
399 | *port_globs* is a list of glob expressions like ``["/dev/ttyACM*"]``. When
400 | connecting the first successful match will be used.
401 |
402 | Provides events:
403 |
404 | * ``connected(port)``. When the board is connected.
405 | * ``disconnected()``. When the board is disconnected.
406 | * ``board(board)``. When the position on the board changed.
407 | * ``clock(clock)``. When the clock status changed.
408 | * ``button_pressed(button)``. When a clock button has been pressed.
409 | """
410 |
411 | def __init__(self, loop, port_globs, lock_port=False):
412 | super().__init__()
413 |
414 | self.loop = loop
415 | self.port_globs = list(port_globs)
416 | self.lock_port = lock_port
417 |
418 | self.serial = None
419 | self.board = Board()
420 |
421 | if os.name not in ["nt"]:
422 | self.driver = AsyncDriver(self)
423 | else:
424 | logging.info("Using threaded driver on Windows")
425 | self.driver = ThreadedDriver(self)
426 |
427 | self.version_received = asyncio.Event(loop=loop)
428 | self.serialnr_received = asyncio.Event(loop=loop)
429 | self.long_serialnr_received = asyncio.Event(loop=loop)
430 | self.battery_status_received = asyncio.Event(loop=loop)
431 | self.board_received = asyncio.Event(loop=loop)
432 | self.clock_version_received = asyncio.Event(loop=loop)
433 | self.clock_ack_received = asyncio.Event(loop=loop)
434 |
435 | self.clock_lock = asyncio.Lock(loop=loop)
436 |
437 | self.closed = False
438 | self.connected = asyncio.Event(loop=loop)
439 | self.disconnect()
440 |
441 | def port_candidates(self):
442 | # Match in the filesystem.
443 | for port_glob in self.port_globs:
444 | if "://" in port_glob:
445 | yield port_glob
446 | else:
447 | yield from glob.iglob(port_glob)
448 |
449 | # Match the list of known serial devices.
450 | for dev, _, _ in serial.tools.list_ports.comports():
451 | for port_glob in self.port_globs:
452 | if fnmatch.fnmatch(dev, port_glob):
453 | yield dev
454 | break
455 |
456 | def unique_port_candidates(self):
457 | seen = set()
458 | for port in itertools.filterfalse(seen.__contains__, self.port_candidates()):
459 | seen.add(port)
460 | yield port
461 |
462 | def connect(self):
463 | """Try to connect. Returns the connected port or ``False``."""
464 | for port in self.unique_port_candidates():
465 | try:
466 | self.connect_port(port)
467 | except serial.SerialException as err:
468 | self.serial = None
469 | LOGGER.error("Could not connect to port %s: %s", port, err)
470 | else:
471 | return port
472 |
473 | return False
474 |
475 | def connect_port(self, port):
476 | # Clean up possible previous connections.
477 | self.closed = False
478 | self.disconnect()
479 |
480 | # Configure port.
481 | self.serial = serial.serial_for_url(port, do_not_open=True)
482 | self.serial.baudrate = 9600
483 | self.serial.stopbits = serial.STOPBITS_ONE
484 | self.serial.parity = serial.PARITY_NONE
485 | self.serial.bytesize = serial.EIGHTBITS
486 |
487 | self.driver.configure_serial()
488 |
489 | # Close once first to allow reconnecting after an interrupted
490 | # connection.
491 | self.serial.close()
492 | self.serial.open()
493 |
494 | # Lock serial port.
495 | if self.lock_port:
496 | try:
497 | import fcntl
498 | import termios
499 | fcntl.ioctl(self.serial.fd, termios.TIOCEXCL)
500 | except (ImportError, OSError):
501 | LOGGER.warning("Could not set TIOCEXCL on port", self.serial.fd)
502 |
503 | # Notify driver of new connection.
504 | self.driver.connect(port)
505 |
506 | # Request initial board state and updates.
507 | self.write(bytearray([DGT_SEND_UPDATE_NICE]))
508 | self.write(bytearray([DGT_SEND_BRD]))
509 |
510 | # Fire connected event.
511 | LOGGER.info("Connected to %s", port)
512 | self.emit("connected", port)
513 | self.connected.set()
514 |
515 | def close(self):
516 | """Close any open board connection."""
517 | self.closed = True
518 | self.disconnect()
519 |
520 | def disconnect(self):
521 | was_connected = self.serial is not None
522 |
523 | self.driver.disconnect()
524 |
525 | if was_connected:
526 | # Release serial port.
527 | if self.lock_port:
528 | try:
529 | import fcntl
530 | import termios
531 | fcntl.ioctl(self.serial.fd, termios.TIOCNXCL)
532 | except (ImportError, OSError):
533 | LOGGER.warning("Could not set TIOCNXCL on port")
534 |
535 | self.serial.close()
536 |
537 | self.serial = None
538 |
539 | self.version_received.clear()
540 | self.version = None
541 |
542 | self.serialnr_received.clear()
543 | self.serialnr = None
544 |
545 | self.long_serialnr_received.clear()
546 | self.long_serialnr = None
547 |
548 | self.battery_status_received.clear()
549 | self.battery_status = None
550 |
551 | self.board_received.clear()
552 | self.board.clear()
553 |
554 | self.clock_version_received.clear()
555 | self.clock_version = None
556 |
557 | self.clock_ack_received.clear()
558 |
559 | self.clock_state = None
560 | self.board_state = None
561 |
562 | self.connected.clear()
563 |
564 | if was_connected:
565 | LOGGER.info("Disconnected")
566 | self.emit("disconnected")
567 |
568 | def write(self, buf):
569 | return self.driver.write(buf)
570 |
571 | def process_message(self, message_id, message):
572 | LOGGER.debug("Message %s: %s", hex(message_id), " ".join(format(c, "02x") for c in message))
573 |
574 | if message_id == MESSAGE_BIT | DGT_BOARD_DUMP:
575 | self.board.state = bytearray(message)
576 | self.board_received.set()
577 | if self.board != self.board_state:
578 | self.board_state = self.board
579 | self.emit("board", self.board.copy())
580 | elif message_id == MESSAGE_BIT | DGT_FIELD_UPDATE:
581 | self.board.state[message[0]] = message[1]
582 | self.emit("board", self.board.copy())
583 | elif message_id == MESSAGE_BIT | DGT_VERSION:
584 | self.version = "%d.%d" % (message[0], message[1])
585 | self.version_received.set()
586 | elif message_id == MESSAGE_BIT | DGT_SERIALNR:
587 | self.serialnr = "".join(chr(c) for c in message)
588 | self.serialnr_received.set()
589 | elif message_id == MESSAGE_BIT | DGT_LONG_SERIALNR:
590 | self.long_serialnr = "".join(chr(c) for c in message)
591 | self.long_serialnr_received.set()
592 | elif message_id == MESSAGE_BIT | DGT_BATTERY_STATUS:
593 | self.battery_status = "".join(chr(c) for c in message if c)
594 | self.battery_status_received.set()
595 | elif message_id == MESSAGE_BIT | DGT_BWTIME:
596 | self.process_bwtime(message)
597 |
598 | def process_bwtime(self, message):
599 | if message[0] & 0x0f == 0x0A or message[3] == 0x0A:
600 | # Handle Clock ACKs.
601 | ack0 = (message[1] & 0x7f) | (message[3] << 3) & 0x80
602 | ack1 = (message[2] & 0x7f) | (message[3] << 2) & 0x80
603 | ack2 = (message[4] & 0x7f) | (message[0] << 3) & 0x80
604 | ack3 = (message[5] & 0x7f) | (message[0] << 2) & 0x80
605 | if ack0 != 0x10:
606 | LOGGER.warning("Clock ACK error")
607 | return
608 | else:
609 | self.clock_ack_received.set()
610 |
611 | if ack1 == 0x88:
612 | # Button pressed.
613 | self.emit("button_pressed", int(chr(ack3)))
614 | elif ack1 == 0x09:
615 | # Version received.
616 | self.clock_version = "{0}.{1}".format(ack2 >> 4, ack2 & 0x0f)
617 | self.clock_version_received.set()
618 | elif any(message[:6]):
619 | # Clock time updated.
620 | r_hours = message[0] & 0x0f
621 | r_mins = (message[1] >> 4) * 10 + (message[1] & 0x0f)
622 | r_secs = (message[2] >> 4) * 10 + (message[2] & 0x0f)
623 | l_hours = message[3] & 0x0f
624 | l_mins = (message[4] >> 4) * 10 + (message[4] & 0x0f)
625 | l_secs = (message[5] >> 4) * 10 + (message[5] & 0x0f)
626 |
627 | l_up = message[6] in [0x10, 0x09]
628 |
629 | clock_state = Clock(
630 | l_hours * 60 * 60 + l_mins * 60 + l_secs,
631 | r_hours * 60 * 60 + r_mins * 60 + r_secs,
632 | bool(l_up))
633 |
634 | if self.clock_state != clock_state:
635 | self.clock_state = clock_state
636 | self.emit("clock", clock_state)
637 | else:
638 | LOGGER.warning("Unknown clock message")
639 |
640 | @asyncio.coroutine
641 | def get_version(self):
642 | """Coroutine. Get the board version."""
643 | self.version_received.clear()
644 | yield from self.connected.wait()
645 | self.write(bytearray([DGT_SEND_VERSION]))
646 | yield from self.version_received.wait()
647 | return self.version
648 |
649 | @asyncio.coroutine
650 | def get_board(self):
651 | """
652 | Coroutine. Get the current board position as a :class:`asyncdgt.Board`.
653 | """
654 | self.board_received.clear()
655 | yield from self.connected.wait()
656 | self.write(bytearray([DGT_SEND_BRD]))
657 | yield from self.board_received.wait()
658 | return self.board.copy()
659 |
660 | @asyncio.coroutine
661 | def get_serialnr(self):
662 | """Coroutine. Get the board serial number."""
663 | self.serialnr_received.clear()
664 | yield from self.connected.wait()
665 | self.write(bytearray([DGT_RETURN_SERIALNR]))
666 | yield from self.serialnr_received.wait()
667 | return self.serialnr
668 |
669 | @asyncio.coroutine
670 | def get_long_serialnr(self):
671 | """Coroutine. Get the long variant of the board serial number."""
672 | self.long_serialnr_received.clear()
673 | yield from self.connected.wait()
674 | self.write(bytearray([DGT_RETURN_LONG_SERIALNR]))
675 | yield from self.long_serialnr_received.wait()
676 | return self.long_serialnr
677 |
678 | @asyncio.coroutine
679 | def get_clock_version(self):
680 | """Coroutine. Get the clock version."""
681 | self.clock_version_received.clear()
682 | yield from self.connected.wait()
683 | self.write(bytearray([
684 | DGT_CLOCK_MESSAGE, 3,
685 | DGT_CLOCK_START_MESSAGE,
686 | DGT_CLOCK_SEND_VERSION,
687 | DGT_CLOCK_END_MESSAGE,
688 | ]))
689 | yield from self.clock_version_received.wait()
690 | return self.clock_version
691 |
692 | @asyncio.coroutine
693 | def clock_beep(self, seconds=0.064):
694 | """Coroutine. Let the clock beep."""
695 | seconds = min(seconds, 10.0)
696 | ms = seconds * 1000
697 | intervals = max(int(round(ms / 64)), 1)
698 |
699 | yield from self.connected.wait()
700 |
701 | with (yield from self.clock_lock):
702 | self.clock_ack_received.clear()
703 | self.write(bytearray([
704 | DGT_CLOCK_MESSAGE, 4,
705 | DGT_CLOCK_START_MESSAGE,
706 | DGT_CLOCK_BEEP,
707 | intervals,
708 | DGT_CLOCK_END_MESSAGE,
709 | ]))
710 | yield from asyncio.sleep(intervals * 0.064)
711 | yield from self.clock_ack_received.wait()
712 |
713 | @asyncio.coroutine
714 | def clock_text(self, text_dgt_xl, text_dgt_3000=None):
715 | """
716 | Coroutine. Display ASCII text on the clock.
717 |
718 | *text_dgt_xl* should consist of at most 6 ASCII characters.
719 |
720 | An optional longer 8 character version of the string can be provided
721 | for the DGT 3000 clock.
722 | """
723 | if text_dgt_3000 is None:
724 | text_dgt_3000 = text_dgt_xl
725 |
726 | yield from self.connected.wait()
727 |
728 | if not self.clock_version:
729 | yield from self.get_clock_version()
730 |
731 | with (yield from self.clock_lock):
732 | if self.clock_version.startswith("2."):
733 | # DGT 3000.
734 | t = _center_text(text_dgt_3000, 8)
735 | self.write(bytearray([
736 | DGT_CLOCK_MESSAGE, 12,
737 | DGT_CLOCK_START_MESSAGE,
738 | DGT_CLOCK_ASCII,
739 | ] + [c for c in t] + [
740 | 0x01,
741 | DGT_CLOCK_END_MESSAGE,
742 | ]))
743 | else:
744 | # DGT XL.
745 | t = _center_text(text_dgt_xl, 6)
746 | self.write(bytearray([
747 | DGT_CLOCK_MESSAGE, 11,
748 | DGT_CLOCK_START_MESSAGE,
749 | DGT_CLOCK_DISPLAY,
750 | t[2], t[1], t[0], t[5], t[4], t[3], 0x00,
751 | 0x01,
752 | DGT_CLOCK_END_MESSAGE
753 | ]))
754 |
755 | yield from asyncio.sleep(0.064)
756 |
757 | @asyncio.coroutine
758 | def clock_set(self, left_time, right_time, left_running=False, right_running=False):
759 | """Coroutine. Setup the clock and start or stop countdowns."""
760 | l_mins, l_secs = divmod(left_time, 60)
761 | l_hours, l_mins = divmod(l_mins, 60)
762 |
763 | r_mins, r_secs = divmod(right_time, 60)
764 | r_hours, r_mins = divmod(r_mins, 60)
765 |
766 | status = 0x00
767 | if left_running:
768 | status |= 0x01
769 | if right_running:
770 | status |= 0x02
771 |
772 | yield from self.connected.wait()
773 |
774 | with (yield from self.clock_lock):
775 | self.clock_ack_received.clear()
776 |
777 | self.write(bytearray([
778 | DGT_CLOCK_MESSAGE, 10,
779 | DGT_CLOCK_START_MESSAGE,
780 | DGT_CLOCK_SETNRUN,
781 | l_hours, l_mins, l_secs, r_hours, r_mins, r_secs, status,
782 | DGT_CLOCK_END_MESSAGE
783 | ]))
784 |
785 | self.write(bytearray([
786 | DGT_CLOCK_MESSAGE, 3,
787 | DGT_CLOCK_START_MESSAGE,
788 | DGT_CLOCK_END,
789 | DGT_CLOCK_END_MESSAGE,
790 | ]))
791 |
792 | yield from asyncio.sleep(0.064)
793 |
794 | def __enter__(self):
795 | if self.connect():
796 | return self
797 | else:
798 | raise IOError("dgt board not connected")
799 |
800 | def __exit__(self, exc_type, exc_value, traceback):
801 | return self.close()
802 |
803 |
804 | def _center_text(text, display_size):
805 | text = text.ljust((len(text) + display_size) // 2).rjust(display_size)
806 | bytestr = text.encode("ascii")
807 | if len(bytestr) > display_size:
808 | LOGGER.warning("Text %r exceeds display size of %d", text, display_size)
809 | return bytestr[0:8]
810 | else:
811 | return bytestr
812 |
813 |
814 | def connect(loop, port_globs):
815 | """
816 | Creates a :class:`asyncdgt.Connection`.
817 |
818 | Raises :exc:`IOError` when no board can be connected.
819 | """
820 | return Connection(loop, port_globs).__enter__()
821 |
822 |
823 | def auto_connect(loop, port_globs, lock_port=False, max_backoff=10.0):
824 | """
825 | Creates a :class:`asyncdgt.Connection`.
826 |
827 | If no board is available or the board gets disconnected, reconnection
828 | attempts will be made with exponential backoff.
829 |
830 | *max_backoff* is the maximum expontential backoff time in seconds. The
831 | exponential backoff will not be increased beyond this.
832 | """
833 | dgt = Connection(loop, port_globs, lock_port=lock_port)
834 |
835 | @asyncio.coroutine
836 | def reconnect():
837 | backoff = 0.5
838 | connected = False
839 |
840 | while not dgt.closed:
841 | LOGGER.debug("Trying to connect ...")
842 | connected = dgt.connect()
843 | if connected:
844 | break
845 |
846 | yield from asyncio.sleep(backoff)
847 | backoff = min(backoff * 2, max_backoff)
848 |
849 | def on_disconnected():
850 | if not dgt.closed:
851 | loop.create_task(reconnect())
852 |
853 | dgt.on("disconnected", on_disconnected)
854 |
855 | on_disconnected()
856 |
857 | return dgt
858 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------