agtic / chronos

5 stars 5 forks source link

Port from Python 2.7 to Python 3 #2

Open agtic opened 1 month ago

agtic commented 1 month ago

Port from Python 2.7 to Python 3

agtic commented 1 week ago

This code base is in need of modernization. An updated version of Raspbian in the container would also be helpful.

Car85 commented 1 week ago

Hello!

I am getting familiar with this application. I have successfully launched it locally with Docker using the following Dockerfile and entrypoint.sh.

FROM --platform=linux/arm raspbian/systemd:latest
workdir /home/chronos

RUN echo "deb http://legacy.raspbian.org/raspbian stretch main contrib non-free rpi" > /etc/apt/sources.list
run apt-get update -y && apt-get install python2.7 python-pip cron sqlite3 nginx libssl-dev vim -y
run useradd pi
run mkdir -p /home/pi/chronos_db
run CFLAGS="-I/usr/include/openssl" && LDFLAGS="-L/usr/lib/arm-linux-gnueabihf" && UWSGI_PROFILE_OVERRIDE=ssl=true && pip install -trusted-host pypi.org --trusted-host files.pythonhosted.or -I --no-binary=:all: --no-cache-dir uwsgi==2.0.20
run pip install flask pyserial pymodbus APScheduler==3.6.3
run pip install --upgrade setuptools
run pip install sqlalchemy python-socketio==0.4.1 socketIO_client six==1.15.0
run pip install gevent
run pip install python-engineio==3.11.2 python-socketio==4.4.0
run pip install gevent-websocket

run apt-get install python3 python3-pip socat -y

copy . .
copy chronos.sql /home/pi/chronos_db/
run python setup.py install
run rm /etc/nginx/sites-enabled/default
run ln -s /etc/nginx/sites-enabled/chronos_conf /etc/nginx/sites-enabled/default
RUN pip install uwsgi
run /usr/local/bin/uwsgi --ini /etc/uwsgi/apps-enabled/socketio_server.ini --pidfile /var/run/uwsgi/uwsgi-socketio.pid --daemonize /var/log/uwsgi/uwsgi-socketio.log
run chmod +x entrypoint.sh

entrypoint [ "./entrypoint.sh" ]
#!/bin/bash
set -e 

socat -d -d PTY,link=/tmp/ptyp0,raw,echo=0 PTY,link=/tmp/ttyp0,raw,echo=0 &
socat -d -d PTY,link=/tmp/ptyp1,raw,echo=0 PTY,link=/tmp/ttyp1,raw,echo=0 &
python2 working-sync-server.py /tmp/ttyp0 &

sudo chown pi:pi /tmp/ptyp0
sudo chown pi:pi /tmp/ptyp1
sudo chown -R pi:pi /home/pi

sleep 2
mkdir -p /var/log/uwsgi

/usr/local/bin/uwsgi --version

/usr/local/bin/uwsgi --ini /etc/uwsgi/apps-enabled/socketio_server.ini --pidfile /var/run/uwsgi/uwsgi-socketio.pid --daemonize /var/log/uwsgi/uwsgi-socketio.log

echo -e "YES\nt=100" > /tmp/water_in
echo -e "YES\nt=150" > /tmp/water_out

service uwsgi start
service nginx start
service chronos start

tail -f /dev/null

image

To approve a PR, the application would need to work without this installation in the Dockerfile, right?

apt-get install python2.7

Apart from updating Raspbian to the newest version known as Raspberry Pi OS.

https://www.raspberrypi.com/software/

Regards!

agtic commented 1 week ago

Hi thanks for looking at this.

Glad the docker build worked for you.

To approve a PR, the application would need to work without this installation in the Dockerfile, right?

apt-get install python2.7

Yes, that's correct.

agtic commented 1 week ago

Some suggestions from ChatGPT on how AI tools might make this easier

https://chatgpt.com/share/4d9c9346-8782-49f0-846a-47cc0e58a7e2

Car85 commented 1 week ago

Would you assign the issue to me? I'm focused on resolving it. @agtic

thank you!

agtic commented 1 week ago

Assigned as requested @Car85. Keep me posted on your progress. Also please monitor the progress on the other open issue on this repo to split the front and backend into separate repos: https://github.com/agtic/chronos/issues/1 @fardin-developer is working on it.

If you get stuck, it might make sense to wait until the other issue is completed.

Anshgrover23 commented 2 days ago

@agtic plss review my pr

agtic commented 2 days ago

@agtic plss review my pr

Thanks will take a look. Migh be a few days. It's a holiday in the US

Anshgrover23 commented 2 days ago

@agtic sure you can take your time. And let me know if any changes required I can do