Skip to content

Commit

Permalink
Update scripts and readme to use poetry as the default
Browse files Browse the repository at this point in the history
  • Loading branch information
erunks committed Feb 20, 2022
1 parent e8b1e29 commit 0ac67c2
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@

Since it seems inevitable that an ISP will suck at giving a reliable connection, I've decided to build this app to report all the internet outtages that occur.

### Prerequisits
- [Python 3.6+](https://www.python.org/downloads/)
- [Poetry](https://python-poetry.org/docs/#installation)

### Setup
1. Clone the repo onto a machine that will be running for the marjority of the time (I used an old Raspberry Pi for this)
2. Get Python3.6+ installed along with `pip`
3. Install the required modules with `python3 -m pip install -r requirements.txt`
3. Install the required modules with `poetry install`
4. Setup a MySQL database somewhere, and the `modem_events` and `outtages` table with the following SQL:
```
CREATE TABLE `outtages` (
Expand All @@ -31,7 +35,7 @@ Since it seems inevitable that an ISP will suck at giving a reliable connection,
6. Setup a cronjob to run the script, with `crontab -e` and append the following lines to the end of the file:
```
# This runs the app every minute. It is possible that this could miss some outtages if the app runs too quickly
*/1 * * * * cd <path_to_repo>/internet-status-reporter/ && flock -n /tmp/ISR.lck python3 app.py
*/1 * * * * cd <path_to_repo>/internet-status-reporter/ && flock -n /tmp/ISR.lck poetry run python app.py
# Note the `flock -n /tmp/ISR.lck` part of the cronjob abvoe makes it so that only one instance of the program is
# allowed to be run at a time. This is optional, but does provide more accurate reporting. If you decide to add
Expand Down
6 changes: 3 additions & 3 deletions scripts/generate_coverage.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
python3 -m coverage run --source=. -m unittest -v src/tests/*_test.py &&
python3 -m coverage xml &&
python3 -m coverage html
poetry run python -m coverage run --source=. -m unittest -v src/tests/*_test.py &&
poetry run python -m coverage xml &&
poetry run python -m coverage html
2 changes: 1 addition & 1 deletion scripts/run_tests.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
python3 -m unittest -v src/tests/*_test.py
poetry run python -m unittest -v src/tests/*_test.py
23 changes: 21 additions & 2 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
REQ_MET="Requirements met!"
PYTHON_MET=false
PIP_MET=false
POETRY_MET=false

PIP3_REGEX='^pip.+(python\ 3.[6-9].+)$'
PYTHON3_6_REGEX='^Python\ 3\.[6-9].+$'
Expand Down Expand Up @@ -48,8 +49,26 @@ if [ "$PIP_MET" != "true" ]; then
fi
fi

if [ "$PYTHON_MET" = "true" ] && [ "$PIP_MET" = "true" ]; then
if [ "$POETRY_MET" != "true" ]; then
echo "Checking if poetry is installed..."

POETRY_REGEX='^Poetry\ version\ (\d+\.?){3}$'
POETRY_VERSION="$(poetry --version)"
if [[ $POETRY_VERSION =~ $POETRY_REGEX ]]; then
echo $REQ_MET
POETRY_MET=true
else
echo "Poetry is not installed!"
echo "Installing poetry..."

$("curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python3 -")
exec bash
POETRY_MET=true
fi
fi

if [ "$PYTHON_MET" = "true" ] && [ "$PIP_MET" = "true" ] && [ "$POETRY_MET" = "true" ]; then
echo "Installing requirements..."
cd $DIR/..
python3 -m pip install -r requirements.txt
poetry install
fi
2 changes: 1 addition & 1 deletion scripts/update.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
git pull origin master && python3 -m pip install -r requirements.txt
git pull origin main && poetry install

0 comments on commit 0ac67c2

Please sign in to comment.