Script 'mail_helper' called by obssrc
Hello community,

here is the log from the commit of package python-usbsdmux for openSUSE:Factory 
checked in at 2022-03-17 17:01:42
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python-usbsdmux (Old)
 and      /work/SRC/openSUSE:Factory/.python-usbsdmux.new.25692 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "python-usbsdmux"

Thu Mar 17 17:01:42 2022 rev:2 rq:962464 version:0.2.1

Changes:
--------
--- /work/SRC/openSUSE:Factory/python-usbsdmux/python-usbsdmux.changes  
2020-05-26 17:17:15.047707217 +0200
+++ 
/work/SRC/openSUSE:Factory/.python-usbsdmux.new.25692/python-usbsdmux.changes   
    2022-03-17 17:01:55.133704666 +0100
@@ -1,0 +2,15 @@
+Thu Mar 17 08:56:58 UTC 2022 - Guillaume GARDET <guillaume.gar...@opensuse.org>
+
+- Update to 0.2.1. Main changes:
+  * cli: Handle well-known Exceptions
+  * usb2642i2c: Do not create if device node does not exist 
+  * commandline: 'get' must respect hardware signal priority
+- Main changes in 0.2.0:
+  * Remove the service/client split and access /dev/sg* directly
+  * usb2642i2c: Fix sg device open arguments
+  * Simplify the read-only to read-write mode transition
+  * usbsdmux: honor wait argument in mode_disconnect()
+  * main/service: add get action
+  * usdbsdmux: set/enable default output values only for writes
+
+-------------------------------------------------------------------

Old:
----
  usbsdmux-0.1.8.tar.gz

New:
----
  usbsdmux-0.2.1.tar.gz

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ python-usbsdmux.spec ++++++
--- /var/tmp/diff_new_pack.w8khmx/_old  2022-03-17 17:01:55.737705129 +0100
+++ /var/tmp/diff_new_pack.w8khmx/_new  2022-03-17 17:01:55.745705135 +0100
@@ -1,7 +1,7 @@
 #
 # spec file for package python-usbsdmux
 #
-# Copyright (c) 2020 SUSE LLC
+# Copyright (c) 2022 SUSE LLC
 #
 # All modifications and additions to the file contributed by third parties
 # remain the property of their copyright owners, unless otherwise agreed
@@ -20,7 +20,7 @@
 %define         skip_python2 1
 %define           orig_name usbsdmux
 Name:             python-usbsdmux
-Version:          0.1.8
+Version:        0.2.1
 Release:          0
 Summary:          Tool to control an usb-sd-mux from the command line
 License:          LGPL-2.1-or-later
@@ -34,7 +34,7 @@
 BuildRequires:    pkgconfig(udev)
 Requires:         %{orig_name}-udev
 Requires(post):   update-alternatives
-Requires(postun): update-alternatives
+Requires(postun):update-alternatives
 %python_subpackages
 
 %description

++++++ usbsdmux-0.1.8.tar.gz -> usbsdmux-0.2.1.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/usbsdmux-0.1.8/.gitignore 
new/usbsdmux-0.2.1/.gitignore
--- old/usbsdmux-0.1.8/.gitignore       2019-12-16 16:01:52.000000000 +0100
+++ new/usbsdmux-0.2.1/.gitignore       2021-07-21 10:29:57.000000000 +0200
@@ -5,3 +5,4 @@
 *.egg-info
 *.venv
 .tox/
+envs/
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/usbsdmux-0.1.8/LICENSE new/usbsdmux-0.2.1/LICENSE
--- old/usbsdmux-0.1.8/LICENSE  2019-12-16 16:01:52.000000000 +0100
+++ new/usbsdmux-0.2.1/LICENSE  1970-01-01 01:00:00.000000000 +0100
@@ -1,15 +0,0 @@
-Copyright (C) 2017 Pengutronix, Chris Fiege <entwickl...@pengutronix.de>
-
-This library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Lesser General Public
-License as published by the Free Software Foundation; either
-version 2.1 of the License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public
-License along with this library; if not, write to the Free Software
-Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/usbsdmux-0.1.8/MANIFEST.in 
new/usbsdmux-0.2.1/MANIFEST.in
--- old/usbsdmux-0.1.8/MANIFEST.in      2019-12-16 16:01:52.000000000 +0100
+++ new/usbsdmux-0.2.1/MANIFEST.in      2021-07-21 10:29:57.000000000 +0200
@@ -1,5 +1,4 @@
 include COPYING
-include LICENSE
 include fastentrypoints.py
 graft contrib
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/usbsdmux-0.1.8/Makefile new/usbsdmux-0.2.1/Makefile
--- old/usbsdmux-0.1.8/Makefile 1970-01-01 01:00:00.000000000 +0100
+++ new/usbsdmux-0.2.1/Makefile 2021-07-21 10:29:57.000000000 +0200
@@ -0,0 +1,32 @@
+PYTHON=python3
+
+PYTHON_ENV_ROOT=envs
+PYTHON_PACKAGING_VENV=$(PYTHON_ENV_ROOT)/$(PYTHON)-packaging-env
+
+.PHONY: clean
+
+# packaging environment #######################################################
+$(PYTHON_PACKAGING_VENV)/.created: REQUIREMENTS.packaging.txt
+       rm -rf $(PYTHON_PACKAGING_VENV) && \
+       $(PYTHON) -m venv $(PYTHON_PACKAGING_VENV) && \
+       . $(PYTHON_PACKAGING_VENV)/bin/activate && \
+       pip install --upgrade pip && \
+       pip install -r REQUIREMENTS.packaging.txt
+       date > $(PYTHON_PACKAGING_VENV)/.created
+
+packaging-env: $(PYTHON_PACKAGING_VENV)/.created
+
+sdist: packaging-env
+       . $(PYTHON_PACKAGING_VENV)/bin/activate && \
+       rm -rf dist *.egg-info && \
+       ./setup.py sdist
+
+_release: sdist
+       . $(PYTHON_PACKAGING_VENV)/bin/activate && \
+       twine upload dist/*
+
+# helper ######################################################################
+clean:
+       rm -rf $(PYTHON_ENV_ROOT)
+
+envs: env packaging-env
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/usbsdmux-0.1.8/README.rst 
new/usbsdmux-0.2.1/README.rst
--- old/usbsdmux-0.1.8/README.rst       2019-12-16 16:01:52.000000000 +0100
+++ new/usbsdmux-0.2.1/README.rst       2021-07-21 10:29:57.000000000 +0200
@@ -2,6 +2,7 @@
 ===================
 
 |license|
+|pypi|
 
 Purpose
 -------
@@ -30,12 +31,6 @@
 Quickstart
 ----------
 
-Clone the git repository:
-
-.. code-block:: bash
-
-   $ git clone https://github.com/pengutronix/usbsdmux.git
-
 Create and activate a virtualenv for usbsdmux:
 
 .. code-block:: bash
@@ -47,15 +42,28 @@
 
 .. code-block:: bash
 
-   $ python setup.py install
+   $ pip install usbsdmux
 
-Now you can run ``usbsdmux`` command by giving the appropriate /dev/sg* device,
-e.g.:
+Now you can run ``usbsdmux -h`` to get a list of possible
+command invocations:
 
-.. code-block:: bash
+.. code-block:: text
 
-   $ usbsdmux /dev/sg1 dut
-   $ usbsdmux /dev/sg1 host
+   $ usbsdmux -h
+   usage: usbsdmux [-h] SG {get,dut,client,host,off}
+
+   positional arguments:
+     SG                    /dev/sg* to use
+     {get,dut,client,host,off}
+                          Action:
+                          get - return selected mode
+                          dut - set to dut mode
+                          client - set to dut mode (alias for dut)
+                          host - set to host mode
+                          off - set to off mode
+
+   optional arguments:
+     -h, --help            show this help message and exit
 
 Using as root
 -------------
@@ -63,61 +71,118 @@
 can just use ``usbsdmux`` as root.
 
 If you have installed this tool inside a virtualenv you can just call the
-shell-wrapper with something like
-``sudo /path/to/virtualenv/bin/usbsdmux /dev/sg1 DUT``.
+shell-wrapper along with the appropriate `/dev/sg*` device path:
 
+.. code-block:: bash
 
-Using as non-root user
-----------------------
-Access to /dev/sg* needs the `CAP_SYS_RAWIO 
<http://man7.org/linux/man-pages/man7/capabilities.7.html>`_. By default all 
processes created by root gain this capability.
+   sudo /path/to/virtualenv/bin/usbsdmux /dev/sg0 dut
+   sudo /path/to/virtualenv/bin/usbsdmux /dev/sg0 host
 
-Since you do not want to give this capability to the Python interpreter you
+Using as normal user / Reliable names
+-------------------------------------
 
-* either need to call the scripts as root
-* or use the systemd-service.
+The example udev-rule in ``contib/udev/99-usbsdmux.rules`` serves two purposes:
 
-The systemd-service is intended to be used with socket-activation.
-The service is present inside ``usbsdmux-service``.
+* Allow users currently logged into the system and users in the
+  ``plugdev`` group [1]_ to access connected USB-SD-Muxes.
+* Create a reliable path in the filesystem to access specific
+  USB-SD-Muxes based on their pre-programmed unique serial number.
+  This is useful when multiple USB-SD-Muxes are connect to a system,
+  as the enumeration-order, and thus the ``/dev/sg*`` numbering,
+  may differ between reboots.
+  The serial number is printed on a label attached to the device.
+
+Users of a Debian based distribution [1]_ can install the udev rule
+by cloning this repository and copying it to the appropriate location
+and reloading the active udev rules:
 
-The systemd-units provided in ``contrib/systemd/`` show an example of how to
-set up the service with systemd and socket-activation.
-You may adapt and copy them into your machine's local systemd service folder
-``/etc/systemd/system/``
+.. code-block:: bash
 
-To start the socket unit and let it create the required socket path
-(requires permissions), run::
+   $ git clone "https://github.com/linux-automation/usbsdmux.git";
+   $ sudo cp usbsdmux/contrib/udev/99-usbsdmux.rules /etc/udev/rules.d/
+   $ sudo udevadm control --reload-rules
+
+After reattaching the USB-SD-Mux you should get a list of connected 
USB-SD-Muxes,
+based on their unique serial numbers, by listing the contents of
+the ``/dev/usb-sd-mux/`` directory:
 
-  systemctl start usbsdmux.socket
+.. code-block:: bash
 
-Now you can use the ``usbsdmux`` tool from a non-root user by calling it with
-the client ``-c`` argument, e.g.::
+    $ ls -l /dev/usb-sd-mux/
+    total 0
+    lrwxrwxrwx 1 root plugdev 6 Mar 31 11:21 id-000000000042 -> ../sg3
+    lrwxrwxrwx 1 root plugdev 6 Mar 27 00:33 id-000000000078 -> ../sg2
+    lrwxrwxrwx 1 root plugdev 6 Mar 24 09:51 id-000000000378 -> ../sg1
+
+.. [1] The ``plugdev`` group is used in Debian and Debian based distributions
+       (like Ubuntu and Linux Mint) to grant access to pluggable gadgets.
+       Depending on your Linux distribution you may want to create/use another
+       group for this purpose and adapt the ``udev`` rule accordingly.
+
+Troubleshooting
+---------------
+
+* Some single board computers, especially Raspberry Pi model 4s, do not work 
with
+  new/fast micro SD cards, due to drive strength issues at high frequencies.
+  Use old and slow micro SD cards with these devices.
+  Another workaround is the replacement of resistors ``R101`` and ``R102`` 
with 0??
+  parts. This modifications does however void the EMC compliance statement 
provided
+  by the Linux Automation GmbH.
+* Some usecases, like hard to reach connectors or full-size SD cards, 
necessitate the
+  use of adapters or extension cables, leading to the same drive strength 
issues
+  and require the same workarounds as documented above.
+* In order for the ``/dev/sg*`` device to appear the ``sg`` kernel module 
needs to be loaded
+  into the kernel. This is usually done automatically by ``udev`` once the 
USB-SD-Mux is connected.
+  To manually load the kernel module run ``sudo modprobe sg``.
 
-  usbsdmux -c /dev/sg1 DUT
+.. |license| image:: https://img.shields.io/badge/license-LGPLv2.1-blue.svg
+    :alt: LGPLv2.1
+    :target: 
https://raw.githubusercontent.com/linux-automation/usbsdmux/master/COPYING
 
-If you use a non-standard socket path (i.e. not ``/tmp/sdmux.sock``) you also
-need to explicitly set the socket path::
+.. |pypi| image:: https://img.shields.io/pypi/v/usbsdmux.svg
+    :alt: pypi.org
+    :target: https://pypi.org/project/usbsdmux
 
-  usbsdmux -c -s /path/to/sock.file /dev/sg1 DUT
+Contributing
+------------
 
-Reliable names for the USB-SD-Mux
----------------------------------
+Thank you for thinking about contributing to this project!
+Changes should be submitted via a
+`Github pull request <https://github.com/linux-automation/usbsdmux/pulls>`_.
 
-A USB-SD-Mux comes with a pre-programmed serial that is also printed on the
-device itself. With the udev-rule in ``contib/udev/99-usbsdmux.rules``
-the sg-device for every USB-SD-Mux is linked to a device in
-``/dev/usb-sd-mux/id-*``.
+This project uses the `Developer's Certificate of Origin 1.1
+<https://developercertificate.org/>`_ with the same `process
+<https://www.kernel.org/doc/html/latest/process/submitting-patches.html#sign-your-work-the-developer-s-certificate-of-origin>`_
+as used for the Linux kernel:
 
-This makes sure you can access a USB-SD-Mux with the same name - independent
-of the order they are connected or the USB or the USB-topology.
+  Developer's Certificate of Origin 1.1
 
-ToDo
-----
+  By making a contribution to this project, I certify that:
 
-* Access to /dev/sg* needs the
-  `CAP_SYS_RAWIO <http://man7.org/linux/man-pages/man7/capabilities.7.html>`_.
-  The service should drop all not needed capabilities after it is started.
+  (a) The contribution was created in whole or in part by me and I
+      have the right to submit it under the open source license
+      indicated in the file; or
 
+  (b) The contribution is based upon previous work that, to the best
+      of my knowledge, is covered under an appropriate open source
+      license and I have the right under that license to submit that
+      work with modifications, whether created in whole or in part
+      by me, under the same open source license (unless I am
+      permitted to submit under a different license), as indicated
+      in the file; or
 
-.. |license| image:: https://img.shields.io/badge/license-LGPLv2.1-blue.svg
-    :alt: LGPLv2.1
-    :target: 
https://raw.githubusercontent.com/pengutronix/usb-sd-mux-ctl/master/LICENSE
+  (c) The contribution was provided directly to me by some other
+      person who certified (a), (b) or (c) and I have not modified
+      it.
+
+  (d) I understand and agree that this project and the contribution
+      are public and that a record of the contribution (including all
+      personal information I submit with it, including my sign-off) is
+      maintained indefinitely and may be redistributed consistent with
+      this project or the open source license(s) involved.
+
+Then you just add a line (using ``git commit -s``) saying:
+
+  Signed-off-by: Random J Developer <ran...@developer.example.org>
+
+using your real name (sorry, no pseudonyms or anonymous contributions).
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/usbsdmux-0.1.8/REQUIREMENTS.packaging.txt 
new/usbsdmux-0.2.1/REQUIREMENTS.packaging.txt
--- old/usbsdmux-0.1.8/REQUIREMENTS.packaging.txt       1970-01-01 
01:00:00.000000000 +0100
+++ new/usbsdmux-0.2.1/REQUIREMENTS.packaging.txt       2021-07-21 
10:29:57.000000000 +0200
@@ -0,0 +1,2 @@
+setuptools>=36.5.0
+twine
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/usbsdmux-0.1.8/contrib/systemd/usbsdmux.service 
new/usbsdmux-0.2.1/contrib/systemd/usbsdmux.service
--- old/usbsdmux-0.1.8/contrib/systemd/usbsdmux.service 2019-12-16 
16:01:52.000000000 +0100
+++ new/usbsdmux-0.2.1/contrib/systemd/usbsdmux.service 1970-01-01 
01:00:00.000000000 +0100
@@ -1,11 +0,0 @@
-[Unit]
-Description=USB-SD-Mux Proxy-Service
-After=network.target usbsdmux.socket
-Requires=usbsdmux.socket
-
-[Service]
-Type=simple
-ExecStart=/path/to/usb-sd-mux/.venv/bin/usbsdmux-service
-
-[Install]
-WantedBy=multi-user.target
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/usbsdmux-0.1.8/contrib/systemd/usbsdmux.socket 
new/usbsdmux-0.2.1/contrib/systemd/usbsdmux.socket
--- old/usbsdmux-0.1.8/contrib/systemd/usbsdmux.socket  2019-12-16 
16:01:52.000000000 +0100
+++ new/usbsdmux-0.2.1/contrib/systemd/usbsdmux.socket  1970-01-01 
01:00:00.000000000 +0100
@@ -1,9 +0,0 @@
-[Unit]
-Description=USB-SD-Mux Proxy-Service socket
-PartOf=usbsdmux.service
-
-[Socket]
-ListenSequentialPacket=/tmp/sdmux.sock
-
-[Install]
-WantedBy=sockets.target
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/usbsdmux-0.1.8/contrib/udev/99-usbsdmux.rules 
new/usbsdmux-0.2.1/contrib/udev/99-usbsdmux.rules
--- old/usbsdmux-0.1.8/contrib/udev/99-usbsdmux.rules   2019-12-16 
16:01:52.000000000 +0100
+++ new/usbsdmux-0.2.1/contrib/udev/99-usbsdmux.rules   2021-07-21 
10:29:57.000000000 +0200
@@ -1,2 +1,3 @@
-ACTION=="add", SUBSYSTEM=="scsi_generic", KERNEL=="sg[0-9]", 
ATTRS{manufacturer}=="Pengutronix", ATTRS{product}=="usb-sd-mux*", 
SYMLINK="usb-sd-mux/id-$attr{serial}"
-ACTION=="add", SUBSYSTEM=="scsi_generic", KERNEL=="sg[0-9]", 
ATTRS{manufacturer}=="Linux Automation GmbH", ATTRS{product}=="usb-sd-mux*", 
SYMLINK="usb-sd-mux/id-$attr{serial}"
+# USB-SD-Mux
+ACTION=="add", SUBSYSTEM=="scsi_generic", KERNEL=="sg[0-9]", 
ATTRS{manufacturer}=="Pengutronix", ATTRS{product}=="usb-sd-mux*", 
SYMLINK="usb-sd-mux/id-$attr{serial}", TAG+="uaccess", GROUP="plugdev"
+ACTION=="add", SUBSYSTEM=="scsi_generic", KERNEL=="sg[0-9]", 
ATTRS{manufacturer}=="Linux Automation GmbH", ATTRS{product}=="usb-sd-mux*", 
SYMLINK="usb-sd-mux/id-$attr{serial}", TAG+="uaccess", GROUP="plugdev"
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/usbsdmux-0.1.8/setup.py new/usbsdmux-0.2.1/setup.py
--- old/usbsdmux-0.1.8/setup.py 2019-12-16 16:01:52.000000000 +0100
+++ new/usbsdmux-0.2.1/setup.py 2021-07-21 10:29:57.000000000 +0200
@@ -1,12 +1,11 @@
 #!/usr/bin/env python3
 
-import fastentrypoints
-
 from setuptools import setup
+import fastentrypoints
 
 setup(
     name="usbsdmux",
-    version="0.1.8",
+    version="0.2.1",
     author="Chris Fiege",
     author_email="pyt...@pengutronix.de",
     license="LGPL-2.1-or-later",
@@ -18,8 +17,9 @@
             'usbsdmux = usbsdmux.__main__:main',
             'usbsdmux-configure = usbsdmux.usb2642eeprom:main',
             'usbsdmux-service = usbsdmux.service:main',
-        ]
+        ],
     },
     classifiers=[
+        "License :: OSI Approved :: GNU Lesser General Public License v2 or 
later (LGPLv2+)"
     ]
 )
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/usbsdmux-0.1.8/tox.ini new/usbsdmux-0.2.1/tox.ini
--- old/usbsdmux-0.1.8/tox.ini  2019-12-16 16:01:52.000000000 +0100
+++ new/usbsdmux-0.2.1/tox.ini  1970-01-01 01:00:00.000000000 +0100
@@ -1,11 +0,0 @@
-[testenv:release]
-whitelist_externals = rm
-
-deps =
-    setuptools>=36.5.0
-    twine
-
-commands =
-    rm -rf dist build *.egg-info
-    ./setup.py sdist
-    twine upload dist/*
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/usbsdmux-0.1.8/usbsdmux/__main__.py 
new/usbsdmux-0.2.1/usbsdmux/__main__.py
--- old/usbsdmux-0.1.8/usbsdmux/__main__.py     2019-12-16 16:01:52.000000000 
+0100
+++ new/usbsdmux-0.2.1/usbsdmux/__main__.py     2021-07-21 10:29:57.000000000 
+0200
@@ -1,85 +1,101 @@
 #! /usr/bin/env python3
 
-from .usbsdmux import UsbSdMux
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+# Copyright (C) 2017 Pengutronix, Chris Fiege <entwickl...@pengutronix.de>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  
USA
+
 import argparse
-import sys, errno
-import json
-import socket
-import os
-
-def direct_mode(sg, mode):
-    ctl = UsbSdMux(sg)
-
-    if mode.lower() == "off":
-        ctl.mode_disconnect()
-    elif mode.lower() == "dut" or mode.lower() == "client":
-        ctl.mode_DUT()
-    elif mode.lower() == "host":
-        ctl.mode_host()
+import errno
+import sys
 
-def client_mode(sg, mode, socket_path):
-    sock = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET)
-    try:
-        sock.connect(socket_path)
-    except FileNotFoundError:
-        print("Socket path %s does not exist. Exiting." % socket_path, 
file=sys.stderr)
-        exit(1)
-    except socket.error as ex:
-        print("Failed opening socket %s : %s. Exiting." % (socket_path, ex), 
file=sys.stderr)
-        exit(1)
-    payload = dict()
-    payload["mode"] = mode
-    payload["sg"] = sg
-    sock.send(json.dumps(payload).encode())
-    answer = json.loads(sock.recv(4096).decode())
-    sock.close()
-    if 'text' in answer:
-        print(answer['text'])
-    if not 'error' in answer or answer['error']:
-        exit(1)
+from .usbsdmux import UsbSdMux
 
 def main():
-    parser = argparse.ArgumentParser()
+    parser = argparse.ArgumentParser(
+        formatter_class=argparse.RawTextHelpFormatter
+    )
 
     parser.add_argument("sg", metavar="SG", help="/dev/sg* to use")
     parser.add_argument(
         "mode",
-        help="mode to switch to",
-        choices=["dut", "host", "off", "client"],
+        help="Action:\n"
+             "get - return selected mode\n"
+             "dut - set to dut mode\n"
+             "client - set to dut mode (alias for dut)\n"
+             "host - set to host mode\n"
+             "off - set to off mode",
+        choices=["get", "dut", "client", "host", "off"],
         type=str.lower)
-    parser.add_argument(
-        "-d",
-        "--direct",
-        help="Forces to run in direct mode.",
-        action="store_true",
-        default=False)
-    parser.add_argument(
-        "-c",
-        "--client",
-        help="Force to run in client mode with socket /tmp/sdmux.sock",
-        action="store_true",
-        default=False)
-    parser.add_argument(
-        "-s",
-        "--socket",
-        help="Overrides the default socket for client mode.",
-        default="/tmp/sdmux.sock")
+
+    # These arguments were previously used for the client/service
+    # based method to grant USB-SD-Mux access to non-root users.
+    # The client/service model is no longer needed due to new udev
+    # rules and a change to how the /dev/sg* devices are accessed.
+    # Display a warning but do not fail when these are used so
+    # existing scripts do not break and can be upgraded gracefully.
+    parser.add_argument("-d", "--direct", help=argparse.SUPPRESS,
+                        action="store_true", default=None)
+    parser.add_argument("-c", "--client", help=argparse.SUPPRESS,
+                        action="store_true", default=None)
+    parser.add_argument("-s", "--socket", help=argparse.SUPPRESS,
+                        default=None)
 
     args = parser.parse_args()
 
-    if args.client is True and args.direct is True:
-        print("Can not run in direct and client mode at the same time. 
Exiting.", file=sys.stderr)
-        exit(1)
-
-    if args.client is True:
-        client_mode(args.sg, args.mode, args.socket)
-    elif args.direct is True:
-        direct_mode(args.sg, args.mode)
-    else:
-        if os.getresuid()[0] == 0:
-            direct_mode(args.sg, args.mode)
+    if any(arg is not None for arg in (args.direct, args.client, args.socket)):
+        print("usbsdmux: usage of -s/-c/-d arguments is deprecated "
+              "as the service/client split is no longer required. "
+              "Please upgrade your scripts to not supply either of these 
arguments",
+              file=sys.stderr)
+
+    ctl = UsbSdMux(args.sg)
+    mode = args.mode.lower()
+
+    try:
+        if mode == "off":
+            ctl.mode_disconnect()
+
+        elif mode in ("dut", "client"):
+            ctl.mode_DUT()
+
+        elif mode == "host":
+            ctl.mode_host()
+
+        elif mode == "get":
+            print(ctl.get_mode())
+
+    except FileNotFoundError as fnfe:
+        print(fnfe, file=sys.stderr)
+        sys.exit(1)
+    except PermissionError as perr:
+        print(perr, file=sys.stderr)
+        sys.exit(1)
+    except OSError as ose:
+        if ose.errno == errno.ENOTTY:
+            # ENOTTY is raised when an error occured when calling an ioctl
+            print(ose, file=sys.stderr)
+            print(
+                f"Does '{args.sg}' really point to an USB-SD-Mux?",
+                file=sys.stderr,
+            )
+            sys.exit(1)
         else:
-            client_mode(args.sg, args.mode, args.socket)
+            raise ose
+
 
 if __name__ == "__main__":
     main()
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/usbsdmux-0.1.8/usbsdmux/ctypehelper.py 
new/usbsdmux-0.2.1/usbsdmux/ctypehelper.py
--- old/usbsdmux-0.1.8/usbsdmux/ctypehelper.py  2019-12-16 16:01:52.000000000 
+0100
+++ new/usbsdmux-0.2.1/usbsdmux/ctypehelper.py  2021-07-21 10:29:57.000000000 
+0200
@@ -1,5 +1,23 @@
 #!/usr/bin/env python3
 
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+# Copyright (C) 2017 Pengutronix, Chris Fiege <entwickl...@pengutronix.de>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  
USA
+
 import ctypes
 import string
 """
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/usbsdmux-0.1.8/usbsdmux/pca9536.py 
new/usbsdmux-0.2.1/usbsdmux/pca9536.py
--- old/usbsdmux-0.1.8/usbsdmux/pca9536.py      2019-12-16 16:01:52.000000000 
+0100
+++ new/usbsdmux-0.2.1/usbsdmux/pca9536.py      2021-07-21 10:29:57.000000000 
+0200
@@ -1,5 +1,23 @@
 #!/usr/bin/env python3
 
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+# Copyright (C) 2017 Pengutronix, Chris Fiege <entwickl...@pengutronix.de>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  
USA
+
 from .usb2642i2c import Usb2642I2C
 
 
@@ -48,6 +66,12 @@
 
     self._usb.write_to(self._I2cAddr, [register, value])
 
+  def read_register(self, addr, len=1):
+    """
+    Returns a register of the Pca9536.
+    """
+    return self._usb.write_read_to(self._I2cAddr, [addr], len)
+
   def set_pin_to_output(self, pins):
     """
     Sets the corresponding pins as outputs.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/usbsdmux-0.1.8/usbsdmux/service.py 
new/usbsdmux-0.2.1/usbsdmux/service.py
--- old/usbsdmux-0.1.8/usbsdmux/service.py      2019-12-16 16:01:52.000000000 
+0100
+++ new/usbsdmux-0.2.1/usbsdmux/service.py      2021-07-21 10:29:57.000000000 
+0200
@@ -1,146 +1,38 @@
 #! /usr/bin/env python3
 
-from .usbsdmux import UsbSdMux
-import socket
-import time
-import argparse
-import json
-import os
-import sys
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+# Copyright (C) 2021 Pengutronix, Leonard G??hrs <entwickl...@pengutronix.de>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  
USA
 
 """
-This service is intended as systemd-socket-activated unit and provides an
+This service was intended as systemd-socket-activated unit and provided an
 interface to the USB-SD-Mux without the need for root privileges.
 
-The service uses a SOCK_SEQPACKET UNIX-socket for communication with the a
-client. Packets always contain a JSON-encoded dict as payload.
-
-From client to service:
-The service expects the following parameter inside the payload:
-* 'sg'   -- /dev/sg* - device to use to control the USB-SD-Mux
-* 'mode' -- Mode to set the USB-SD-Mux to
-
-For example:
-{"sg": "/dev/sg1", "mode": "dut"}
-
-From service to client:
-The service always answers with a payload like the following:
-* 'error' -- Boolean: True if an error occurred. False on success.
-* 'text'  -- Text that describes the result.
-             Contains the Text of an exception if one occurred.
+Usage of this service became obsolete in new releases that changed the
+way the /dev/sg* devices are accessed and that added new udev rules to
+directly grant device access to the users.
 
-For example:
-{"error": False, "text": "Success"}
+This file is kept here to notify users that have set up a systemd service.
 """
-# Default filedescriptor used by systemd to pass us a socket
-systemd_socket_fd = 3
-
-def create_answer(had_error=False, err_text=""):
-    """
-    Creates a JSON-formatted answer for socket-communication.
-
-    Arguments:
-    had_error -- Defines if the return value represents an error. Will be
-                 written into the 'error'-field of the answer.
-    err_text -- Free Text that will be passed to the client along with the
-                error state.
-    """
-    answer = dict()
-    answer["error"] = had_error
-    answer["text"] =  err_text
-    return json.dumps(answer)
-
-def process_request(raw_string):
-    """
-    Parses a message received from the communication-socket and tries to 
execute
-    the request.
-
-    This function will try to parse the message as JSON and expects the
-    following keys inside a dict:
-
-    * 'sg'   -- /dev/sg* - device to use to control the USB-SD-Mux
-    * 'mode' -- Mode to set the USB-SD-Mux to
-
 
-    Arguments:
-    raw_string -- Message recieved as string."""
-
-    try:
-        payload = json.loads(raw_string)
-        ctl = UsbSdMux(payload["sg"])
-
-        if payload["mode"].lower() == "off":
-            ctl.mode_disconnect()
-
-        elif payload["mode"].lower() == "dut" or\
-             payload["mode"].lower() == "client":
-            ctl.mode_DUT()
-
-        elif payload["mode"].lower() == "host":
-            ctl.mode_host()
-
-        else:
-            return create_answer(had_error=True, err_text="Unknown mode")
-
-        return create_answer(had_error=False, err_text="Success")
-
-    except Exception as e:
-        return create_answer(had_error=True, err_text=str(e))
+import sys
 
 def main():
-    parser = argparse.ArgumentParser()
-
-    parser.add_argument(
-        "-t",
-        "--timeout",
-        help="Time without connection before the service terminates in 
seconds.",
-        default=120,
-        type=int)
-    parser.add_argument(
-        "--socket",
-        help="Will use given socket for standalone-mode instead of 
socket-activation with systemd.")
-
-    args = parser.parse_args()
-
-    if args.socket is not None:
-        # try to create our own socket
-        sock_name = args.socket
-        try:
-            os.remove(sock_name)
-        except FileNotFoundError:
-            pass
-        except PermissionError as e:
-            print(e, file=sys.stderr)
-            print("Could not remove old socket. Correct access rights?", 
file=sys.stderr)
-            exit(-1)
-        sock = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET)
-        sock.bind(sock_name)
-        sock.listen(0)
-    else:
-        # get socket from systemd
-        sock = socket.fromfd(
-            systemd_socket_fd,
-            socket.AF_UNIX,
-            socket.SOCK_SEQPACKET)
-
-
-    sock.settimeout(1)
-    timeout = time.time() + args.timeout
-
-    # connection loop
-    while True:
-        try:
-            conn, addr = sock.accept()
-            answer = process_request(conn.recv(4096).decode())
-            conn.send(answer.encode())
-            conn.close()
-            timeout = time.time() + args.timeout
-        except socket.timeout:
-            pass
-
-        if time.time() > timeout:
-            break
-
-    # we need to close the socket if the created it ourselves:
-    if args.socket is not None:
-        sock.close()
+    print("The usage of usbsdmux-service is deprecated.", file=sys.stderr)
+    print("Access to USB-SD-Mux devices is now controlled by a new set of udev 
rules.", file=sys.stderr)
+    print("Please delete/deactivate the service calling this command.", 
file=sys.stderr)
+    exit(-1)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/usbsdmux-0.1.8/usbsdmux/usb2642eeprom.py 
new/usbsdmux-0.2.1/usbsdmux/usb2642eeprom.py
--- old/usbsdmux-0.1.8/usbsdmux/usb2642eeprom.py        2019-12-16 
16:01:52.000000000 +0100
+++ new/usbsdmux-0.2.1/usbsdmux/usb2642eeprom.py        2021-07-21 
10:29:57.000000000 +0200
@@ -1,11 +1,30 @@
 #!/usr/bin/env python3
 
-import struct
-import ctypes
-from .usb2642i2c import Usb2642I2C
-import time
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+# Copyright (C) 2017 Pengutronix, Chris Fiege <entwickl...@pengutronix.de>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  
USA
+
 import argparse
+import ctypes
+import struct
 import sys
+import time
+
+from .usb2642i2c import Usb2642I2C
 from .ctypehelper import string_to_microchip_unicode_uint8_array,\
   string_to_uint8_array, list_to_uint8_array, to_pretty_hex
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/usbsdmux-0.1.8/usbsdmux/usb2642i2c.py 
new/usbsdmux-0.2.1/usbsdmux/usb2642i2c.py
--- old/usbsdmux-0.1.8/usbsdmux/usb2642i2c.py   2019-12-16 16:01:52.000000000 
+0100
+++ new/usbsdmux-0.2.1/usbsdmux/usb2642i2c.py   2021-07-21 10:29:57.000000000 
+0200
@@ -1,5 +1,23 @@
 #!/usr/bin/env python3
 
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+# Copyright (C) 2017 Pengutronix, Chris Fiege <entwickl...@pengutronix.de>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  
USA
+
 import ctypes
 import fcntl
 from .ctypehelper import string_to_microchip_unicode_uint8_array,\
@@ -316,7 +334,7 @@
 #    print("SGIO:")
 #    print(self.to_pretty_hex(sgio))
 
-    with open(self.sg, 'r') as fh:
+    with open(self.sg, 'r+b', buffering=0) as fh:
       rc =  fcntl.ioctl(fh, self._SG_IO, sgio)
       if rc != 0:
         raise IoctlFailed("SG_IO ioctl() failed with non-zero exit-code {}"\
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/usbsdmux-0.1.8/usbsdmux/usbsdmux.py 
new/usbsdmux-0.2.1/usbsdmux/usbsdmux.py
--- old/usbsdmux-0.1.8/usbsdmux/usbsdmux.py     2019-12-16 16:01:52.000000000 
+0100
+++ new/usbsdmux-0.2.1/usbsdmux/usbsdmux.py     2021-07-21 10:29:57.000000000 
+0200
@@ -1,7 +1,25 @@
 #!/usr/bin/env python3
 
-from .pca9536 import Pca9536
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+# Copyright (C) 2017 Pengutronix, Chris Fiege <entwickl...@pengutronix.de>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  
USA
+
 import time
+from .pca9536 import Pca9536
 
 
 class UsbSdMux(object):
@@ -30,14 +48,21 @@
     """
     self._pca = Pca9536(sg)
 
-    # setting the output-values to defaults before enabling outputs on the
-    # GPIO-expander
-    self.mode_disconnect(wait=False)
-
-    # now enabling outputs
-    self._pca.set_pin_to_output(
-        Pca9536.gpio_0 | Pca9536.gpio_1 |
-        Pca9536.gpio_2 | Pca9536.gpio_3)
+  def get_mode(self):
+    """
+    Returns currently selected mode as string
+    """
+    val = self._pca.read_register(1)[0]
+
+    # If the SD-Card is disabled we do not need to check for the selected mode.
+    # PWR_disable and DAT_disable are always switched at the same time.
+    # Let's assume it is sufficient to check one of both.
+    if val & self._PWR_disable:
+      return "off"
+
+    if val & self._select_DUT:
+       return "dut"
+    return "host"
 
   def mode_disconnect(self, wait=True):
     """
@@ -48,10 +73,14 @@
     the sd-card is known to be close to zero
     """
 
+    # Set the output registers to known values and activate them afterwards
     self._pca.output_values(self._DAT_disable | self._PWR_disable |
                             self._select_HOST | self._card_removed)
+    self._pca.set_pin_to_output(Pca9536.gpio_0 | Pca9536.gpio_1 |
+                                Pca9536.gpio_2 | Pca9536.gpio_3)
 
-    time.sleep(1)
+    if wait:
+        time.sleep(1)
 
   def mode_DUT(self, wait=True):
     """

Reply via email to