Kazade/dreampi

Migrate to Python3

jstolarek opened this issue · 13 comments

DreamPi scripts are written using Python 2. That version of Python is no longer maintained and is being dropped by Linux distributions. In particular, it is no longer possible to use DreamPi scripts on latest RaspberryPi OS Bullseye since it only ships with Python 3. DreamPi scripts should be updated to use Python 3 instead of 2.

I've successfully ported this to Python 3 here: https://github.com/sargunv/dreampi/tree/python3

It's working when installed onto the pre-configured dreampi image, going to try to figure out how to get this working on a fresh Raspbian install next and document it, and then dockerize if possible

Sounds awesome, thanks. I've managed to set up DreamPi on a fresh Raspbian OS Buster a while back. Rough steps are as follows:

  1. Install dependencies:
    # apt-get install dnsmasq dnsutils libnetfilter-queue-dev libnetfilter-queue1 ppp arping nftables tcpd wvdial 
    
  2. Get the DreamPi repo:
    $ git clone https://github.com/Kazade/dreampi
    $ cd dreampi
    
  3. Install packages from the repo:
    # dpkg -i arm/*.deb
    
  4. Put DreamPi files into a system directory:
    # mkdir /usr/local/share/dreampi
    # cp *.py dial-tone.wav /usr/local/share/dreampi
    # ln -s /usr/local/share/dreampi/dreampi.py /usr/local/bin/dreampi
    # chown -R root:root /usr/local/share/dreampi/
    
  5. Activate scripts used to launch system services:
    # cp etc/init.d/dreampi /etc/init.d/
    # cp etc/systemd/system/dreampi.service /etc/systemd/system/
    
  6. Put this configuration in /etc/dnsmasq.d/dreampi.conf:
    domain-needed
    bogus-priv
    server=46.101.91.123
    no-resolv
    no-hosts
    cache-size=500
    log-queries
    
    I think only the first four are relevant, the last three are most likely redundant but I haven't verified this.

At this point you need to test whether the dreampi script launches correctly. dreampi --no-daemon is useful for seeing the logs.

@sargunv and @jstolarek thanks for this, we've implemented a combination of the above into our RetroNAS project and it works OK for the testing I have done (quake 3).

There is some refinement we could probably do, for now our RetroNAS project can be converted to a dreampi based on your work. Thanks again

Nice, I've been intending to set up RetroNAS on my network soon, glad to know my work helped out there!

i've opened #19 to try and get this moving to an official vers so i can clean up our installer oneday, otherwise i might just fork it and mod it. I like the idea of this being available as a option across a wide range of SBCs.

@sargunv do you think you can pull in the requirements.txt from mine and incorporate it into your branch? i'd rather have the option of running the pip ver than hope packages are available where applicable. If it needs cleaning up go for it and the requirements.txt makes that easy to id deps.

https://raw.githubusercontent.com/sairuk/dreampi/master/requirements.txt

the dcnow etc packages being deb atm force us to be on a deb based os but i'm hoping thats not always the case.

it'd be cool if we could build the SBC images in a workflow eventually and provide artifacts to folks. eventually merging in the additional netlink tunnel changes from @eaudunord and whatever else comes along

Sure thing, I'll pull in your requirements.txt and take a look at those conflicts mentioned in the PR, probably tonight

@sairuk Totally forgot about this, but I've just gone ahead and added your requirements.txt and resolved merge conflicts on https://github.com/sargunv/dreampi/tree/python3.

and updated the README to use pip and the requirements.txt in a virtualenv instead of apt packages

Amazing, thanks @sargunv

@sargunv I suspect the systemd unit file would need to be updated to use the python venv ? Right now, after following the readme and the instructions from #17 (comment) , I'm getting :

Apr 27 20:02:38 raspberrypi systemd[1]: Started DreamPi Service.
Apr 27 20:02:39 raspberrypi dreampi[1810]: Traceback (most recent call last):
Apr 27 20:02:39 raspberrypi dreampi[1810]:   File "/usr/local/bin/dreampi", line 16, in <module>
Apr 27 20:02:39 raspberrypi dreampi[1810]:     import sh
Apr 27 20:02:39 raspberrypi dreampi[1810]: ModuleNotFoundError: No module named 'sh'
Apr 27 20:02:39 raspberrypi systemd[1]: dreampi.service: Main process exited, code=exited, status=1/FAILURE
Apr 27 20:02:39 raspberrypi systemd[1]: dreampi.service: Failed with result 'exit-code'.
Apr 27 20:02:39 raspberrypi systemd[1]: dreampi.service: Consumed 1.490s CPU time.

(It works fine when using the packaged versions )

Yeah if you're running it from that init script, you'll want to either install the Python deps globally or edit the init script to use the venv.

Ok, I was able to start the systemd unit after editing it with:

sudo systemctl --full edit dreampi.service

Replace :
ExecStart=/usr/local/bin/dreampi --no-daemon
with :
ExecStart=/home/pi/venv/bin/python /usr/local/bin/dreampi --no-daemon