Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Python3 #17

Open
jstolarek opened this issue Jan 12, 2022 · 13 comments
Open

Migrate to Python3 #17

jstolarek opened this issue Jan 12, 2022 · 13 comments

Comments

@jstolarek
Copy link

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.

@sargunv
Copy link
Contributor

sargunv commented Mar 17, 2022

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

@sargunv
Copy link
Contributor

sargunv commented Mar 17, 2022

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

@jstolarek
Copy link
Author

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.

@sairuk
Copy link

sairuk commented Dec 4, 2022

@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

@sargunv
Copy link
Contributor

sargunv commented Dec 4, 2022

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

@sairuk
Copy link

sairuk commented Dec 5, 2022

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

@sargunv
Copy link
Contributor

sargunv commented Dec 5, 2022

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

sargunv added a commit to sargunv/dreampi that referenced this issue Dec 25, 2022
@sargunv
Copy link
Contributor

sargunv commented Dec 26, 2022

@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.

@sargunv
Copy link
Contributor

sargunv commented Dec 26, 2022

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

@sairuk
Copy link

sairuk commented Dec 26, 2022

Amazing, thanks @sargunv

@ABelliqueux
Copy link

ABelliqueux commented Apr 27, 2023

@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 )

@sargunv
Copy link
Contributor

sargunv commented Apr 27, 2023

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.

@ABelliqueux
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants