{ "info": { "author": "Dmitry Orlov ", "author_email": "me@mosquito.su", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Console", "Intended Audience :: Developers", "Intended Audience :: Education", "Intended Audience :: End Users/Desktop", "License :: OSI Approved :: Apache Software License", "Natural Language :: English", "Natural Language :: Russian", "Operating System :: POSIX :: Linux", "Programming Language :: Cython", "Programming Language :: Python", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: Implementation :: CPython", "Topic :: Software Development :: Libraries", "Topic :: System", "Topic :: System :: Operating System" ], "description": "SystemD wrapper on Cython\n=========================\n\n.. image:: https://img.shields.io/pypi/v/cysystemd.svg\n :target: https://pypi.python.org/pypi/cysystemd/\n :alt: Latest Version\n\n.. image:: https://img.shields.io/pypi/wheel/cysystemd.svg\n :target: https://pypi.python.org/pypi/cysystemd/\n\n.. image:: https://img.shields.io/pypi/pyversions/cysystemd.svg\n :target: https://pypi.python.org/pypi/cysystemd/\n\n.. image:: https://img.shields.io/pypi/l/cysystemd.svg\n :target: https://pypi.python.org/pypi/cysystemd/\n\n\nPython systemd wrapper using Cython\n\n\n.. contents:: Table of contents\n\n\nInstallation\n------------\n\nAll packages available on\n`github releases `_.\n\n\nDebian/Ubuntu\n+++++++++++++\n\nInstall repository key\n\n.. code-block:: bash\n\n wget -qO - 'https://bintray.com/user/downloadSubjectPublicKey?username=bintray' | \\\n apt-key add -\n\n\nInstall the repository file\n\nDebian Jessie:\n\n.. code-block:: bash\n\n echo \"deb http://dl.bintray.com/mosquito/cysystemd jessie main\" > /etc/apt/sources.list.d/cysystemd.list\n apt-get update\n apt-get install python-cysystemd python3-cysystemd\n\nUbuntu Xenial:\n\n.. code-block:: bash\n\n echo \"deb http://dl.bintray.com/mosquito/cysystemd xenial main\" > /etc/apt/sources.list.d/cysystemd.list\n apt-get update\n apt-get install python-cysystemd python3-cysystemd\n\nUbuntu Bionic:\n\n.. code-block:: bash\n\n echo \"deb http://dl.bintray.com/mosquito/cysystemd bionic main\" > /etc/apt/sources.list.d/cysystemd.list\n apt-get update\n apt-get install python-cysystemd python3-cysystemd\n\n\nCentos 7\n++++++++\n\n.. code-block:: bash\n\n yum localinstall \\\n https://github.com/mosquito/cysystemd/releases/download/0.17.1/python-cysystemd-0.17.1-1.centos7.x86_64.rpm\n\n\nInstallation from sources\n+++++++++++++++++++++++++\n\nYou should install systemd headers\n\nFor debian users:\n\n\n.. code-block:: bash\n\n apt-get install build-essential \\\n libsystemd-journal-dev \\\n libsystemd-daemon-dev \\\n libsystemd-dev\n\n\nFor CentOS/RHEL\n\n.. code-block:: bash\n\n yum install gcc systemd-devel\n\n\nAnd install it from pypi\n\n.. code-block:: bash\n\n pip install cysystemd\n\n\nUsage examples\n--------------\n\nWriting to journald\n+++++++++++++++++++\n\nLogging handler for python logger\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n.. code-block:: python\n\n from cysystemd import journal\n import logging\n import uuid\n\n logging.basicConfig(level=logging.DEBUG)\n logger = logging.getLogger()\n logger.addHandler(journal.JournaldLogHandler())\n\n try:\n log.info(\"Trying to do something\")\n raise Exception('foo')\n except:\n logger.exception(\"Test Exception %s\", 1)\n\n\nSystemd daemon notification\n~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n\n.. code-block:: python\n\n from cysystemd.daemon import notify, Notification\n\n # Send READY=1\n notify(Notification.READY)\n\n # Send status\n notify(Notification.STATUS, \"I'm fine.\")\n\n # Send stopping\n notify(Notification.STOPPING)\n\n\nWrite message into Systemd journal\n\n\n.. code-block:: python\n\n from cysystemd import journal\n\n\n journal.write(\"Hello Lennart\")\n\n # Or send structured data\n journal.send(\n message=\"Hello Lennart\",\n priority=journal.Priority.INFO,\n some_field='some value',\n )\n\n\nReading journald\n++++++++++++++++\n\nReading all systemd records\n~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n.. code-block:: python\n\n from cysystemd.reader import JournalReader, JournalOpenMode\n\n journal_reader = JournalReader()\n journal_reader.open(JournalOpenMode.SYSTEM)\n journal_reader.seek_head()\n\n for record in journal_reader:\n print(record.data['MESSAGE'])\n\n\nRead only cron logs\n~~~~~~~~~~~~~~~~~~~\n\n.. _read-only-cron-logs:\n\n.. code-block:: python\n\n from cysystemd.reader import JournalReader, JournalOpenMode, Rule\n\n\n rules = (\n Rule(\"SYSLOG_IDENTIFIER\", \"CRON\") &\n Rule(\"_SYSTEMD_UNIT\", \"crond.service\") |\n Rule(\"_SYSTEMD_UNIT\", \"cron.service\")\n )\n\n cron_reader = JournalReader()\n cron_reader.open(JournalOpenMode.SYSTEM)\n cron_reader.seek_head()\n cron_reader.add_filter(rules)\n\n for record in cron_reader:\n print(record.data['MESSAGE'])\n\n\nPolling records\n~~~~~~~~~~~~~~~\n\n.. code-block:: python\n\n from cysystemd.reader import JournalReader, JournalOpenMode\n\n\n reader = JournalReader()\n reader.open(JournalOpenMode.SYSTEM)\n reader.seek_tail()\n\n poll_timeout = 255\n\n while True:\n reader.wait(poll_timeout)\n\n for record in reader:\n print(record.data['MESSAGE'])\n\n\nJournalD open modes\n~~~~~~~~~~~~~~~~~~~\n\n* CURRENT_USER\n* LOCAL_ONLY\n* RUNTIME_ONLY\n* SYSTEM\n* SYSTEM_ONLY\n\n\n.. code-block:: python\n\n from cysystemd.reader import JournalReader, JournalOpenMode\n\n reader = JournalReader()\n reader.open(JournalOpenMode.CURRENT_USER)\n\n\nJournalD entry\n~~~~~~~~~~~~~~\n\nJournalEntry class has some special properties and methods:\n\n* ``data`` - journal entry content (``dict``)\n* ``date`` - entry timestamp (``datetime`` instance)\n* ``cursor`` - systemd identification bytes for this entry\n* ``boot_id()`` - returns bootid\n* ``get_realtime_sec()`` - entry epoch (``float``)\n* ``get_realtime_usec()`` - entry epoch (``int`` microseconds)\n* ``get_monotonic_sec()`` - entry monotonic time (``float``)\n* ``get_monotonic_usec()`` - entry monotonic time (``int`` microseconds)\n* ``__getitem__(key)`` - shoutcut for ``entry.data[key]``\n\n\nJournalD reader\n~~~~~~~~~~~~~~~\n\nJournalReader class has some special properties and methods:\n\n* ``open(flags=JournalOpenMode.CURRENT_USER)`` - opening journald\n with selected mode\n* ``open_directory(path)`` - opening journald from path\n* ``open_files(*filename)`` - opening journald from files\n* ``data_threshold`` - may be used to get or set the data field size threshold\n for data returned by fething entry data.\n* ``closed`` - returns True when journal reader closed\n* ``locked`` - returns True when journal reader locked\n* ``idle`` - returns True when journal reader opened\n* ``seek_head`` - move reader pointer to the first entry\n* ``seek_tail`` - move reader pointer to the last entry\n* ``seek_monotonic_usec`` - seeks to the entry with the specified monotonic\n timestamp, i.e. CLOCK_MONOTONIC. Since monotonic time restarts on every\n reboot a boot ID needs to be specified as well.\n* ``seek_realtime_usec`` - seeks to the entry with the specified realtime\n (wallclock) timestamp, i.e. CLOCK_REALTIME. Note that the realtime clock\n is not necessarily monotonic. If a realtime timestamp is ambiguous, it is\n not defined which position is sought to.\n* ``seek_cursor`` - seeks to the entry located at the specified cursor\n (see ``JournalEntry.cursor``).\n* ``wait(timeout)`` - It will synchronously wait until the journal gets\n changed. The maximum time this call sleeps may be controlled with the\n timeout_usec parameter.\n* ``__iter__`` - returns JournalReader object\n* ``__next__`` - calls ``next()`` or raise ``StopIteration``\n* ``next(skip=0)`` - returns the next ``JournalEntry``. The ``skip``\n parameter skips some entries.\n* ``previous(skip=0)`` - returns the previous ``JournalEntry``.\n The ``skip`` parameter skips some entries.\n* ``skip_next(skip)`` - skips next entries.\n* ``skip_previous(skip)`` - skips next entries.\n* ``add_filter(rule)`` - adding filter rule.\n See `read-only-cron-logs`_ as example.\n* ``clear_filter`` - reset all filters\n* ``fd`` - returns a special file descriptor\n* ``events`` - returns ``EPOLL`` events\n* ``timeout`` - returns internal timeout\n* ``process_events()`` - After each poll() wake-up process_events() needs\n to be called to process events. This call will also indicate what kind of\n change has been detected.\n* ``get_catalog()`` - retrieves a message catalog entry for the current\n journal entry. This will look up an entry in the message catalog by using\n the \"MESSAGE_ID=\" field of the current journal entry. Before returning\n the entry all journal field names in the catalog entry text enclosed in\n \"@\" will be replaced by the respective field values of the current entry.\n If a field name referenced in the message catalog entry does not exist,\n in the current journal entry, the \"@\" will be removed, but the field name\n otherwise left untouched.\n* ``get_catalog_for_message_id(message_id: UUID)`` - works similar to\n ``get_catalog()`` but the entry is looked up by the specified\n message ID (no open journal context is necessary for this),\n and no field substitution is performed.", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/mosquito/cysystemd", "keywords": "systemd,python,daemon,sd_notify,cython", "license": "Apache", "maintainer": "", "maintainer_email": "", "name": "cysystemd", "package_url": "https://pypi.org/project/cysystemd/", "platform": "POSIX", "project_url": "https://pypi.org/project/cysystemd/", "project_urls": { "Homepage": "http://github.com/mosquito/cysystemd" }, "release_url": "https://pypi.org/project/cysystemd/1.1.1/", "requires_dist": null, "requires_python": "", "summary": "SystemD wrapper on Cython", "version": "1.1.1" }, "last_serial": 4835112, "releases": { "0.16.2": [ { "comment_text": "", "digests": { "md5": "45be55d9846db5206de812612df0fa03", "sha256": "7b84bb3cf9b4b692ea77a197ba2696a4b4f286f7699508d8f88d6ad20b9037d3" }, "downloads": -1, "filename": "cysystemd-0.16.2.tar.gz", "has_sig": false, "md5_digest": "45be55d9846db5206de812612df0fa03", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 170814, "upload_time": "2018-09-06T19:15:16", "url": "https://files.pythonhosted.org/packages/c6/35/3ea53f8ee1662c1a7a16208e4f266c6ff56f403aae95efa49847ea67c9a2/cysystemd-0.16.2.tar.gz" } ], "0.17.1": [ { "comment_text": "", "digests": { "md5": "5ef062b922275ea2994cdf63aab85266", "sha256": "04941a73cb0fe214b4c9ab032e81da1a0d28a4f932404ec89514865bd52f9a77" }, "downloads": -1, "filename": "cysystemd-0.17.1.tar.gz", "has_sig": false, "md5_digest": "5ef062b922275ea2994cdf63aab85266", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 169887, "upload_time": "2018-09-06T20:59:59", "url": "https://files.pythonhosted.org/packages/54/39/994eec23f5f421577f9e7bea674c2dc377bc4805c65bfb20fecc5c580538/cysystemd-0.17.1.tar.gz" } ], "0.17.2": [ { "comment_text": "", "digests": { "md5": "9e1d44edecba1ada9371acf9d39171d7", "sha256": "7da8b39781f3d636594070319b08afa2ec6689e2f433cc68c854fd83916b1cf9" }, "downloads": -1, "filename": "cysystemd-0.17.2.tar.gz", "has_sig": false, "md5_digest": "9e1d44edecba1ada9371acf9d39171d7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 175368, "upload_time": "2018-10-27T20:57:31", "url": "https://files.pythonhosted.org/packages/dd/9d/b2a7365b4b7ddd991ebddbe8fb17aa0bcee9fdbcab7deabc9afb9b4528b1/cysystemd-0.17.2.tar.gz" } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "0f8d02e6702382af034b1b5989a7160a", "sha256": "d053dfa809a5e84520a9d650c741bee48f127f25bb9dd4ac87206ac318c1edd9" }, "downloads": -1, "filename": "cysystemd-1.1.0.tar.gz", "has_sig": false, "md5_digest": "0f8d02e6702382af034b1b5989a7160a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 193228, "upload_time": "2018-11-24T12:45:22", "url": "https://files.pythonhosted.org/packages/b7/64/9ab14a4682c39a5be35d99743f86a9d1b0c8955217bb7957d6af910e880a/cysystemd-1.1.0.tar.gz" } ], "1.1.1": [ { "comment_text": "", "digests": { "md5": "858465d1cb2d47f8c80bff355c14f154", "sha256": "b4de9515d7b295914f3132e2eeb652d32f140c2919efc5e29f0dd770be0dda04" }, "downloads": -1, "filename": "cysystemd-1.1.1.tar.gz", "has_sig": false, "md5_digest": "858465d1cb2d47f8c80bff355c14f154", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 192144, "upload_time": "2019-02-18T13:23:58", "url": "https://files.pythonhosted.org/packages/e2/1e/f11e985e99ed3a6ce1804663aac84205c72c287d4070ee55ee02f470da3d/cysystemd-1.1.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "858465d1cb2d47f8c80bff355c14f154", "sha256": "b4de9515d7b295914f3132e2eeb652d32f140c2919efc5e29f0dd770be0dda04" }, "downloads": -1, "filename": "cysystemd-1.1.1.tar.gz", "has_sig": false, "md5_digest": "858465d1cb2d47f8c80bff355c14f154", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 192144, "upload_time": "2019-02-18T13:23:58", "url": "https://files.pythonhosted.org/packages/e2/1e/f11e985e99ed3a6ce1804663aac84205c72c287d4070ee55ee02f470da3d/cysystemd-1.1.1.tar.gz" } ] }