From 9012e159871b6ecc555b149b40fce15dc8f092fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Bori?= Date: Wed, 27 Aug 2025 18:59:29 +0200 Subject: [PATCH] Added a `pyproject.toml` file to package the Python project --- .gitignore | 3 + README.md | 6 +- botany/__init__.py | 0 {art => botany/art}/agave1.txt | 0 {art => botany/art}/agave2.txt | 0 {art => botany/art}/agave3.txt | 0 {art => botany/art}/aloe1.txt | 0 {art => botany/art}/aloe2.txt | 0 {art => botany/art}/aloe3.txt | 0 {art => botany/art}/baobab1.txt | 0 {art => botany/art}/baobab2.txt | 0 {art => botany/art}/baobab3.txt | 0 {art => botany/art}/bee.txt | 0 {art => botany/art}/brugmansia1.txt | 0 {art => botany/art}/brugmansia2.txt | 0 {art => botany/art}/brugmansia3.txt | 0 {art => botany/art}/cactus1.txt | 0 {art => botany/art}/cactus2.txt | 0 {art => botany/art}/cactus3.txt | 0 {art => botany/art}/columbine1.txt | 0 {art => botany/art}/columbine2.txt | 0 {art => botany/art}/columbine3.txt | 0 {art => botany/art}/daffodil1.txt | 0 {art => botany/art}/daffodil2.txt | 0 {art => botany/art}/daffodil3.txt | 0 {art => botany/art}/fern1.txt | 0 {art => botany/art}/fern2.txt | 0 {art => botany/art}/fern3.txt | 0 {art => botany/art}/ficus1.txt | 0 {art => botany/art}/ficus2.txt | 0 {art => botany/art}/ficus3.txt | 0 {art => botany/art}/flytrap1.txt | 0 {art => botany/art}/flytrap2.txt | 0 {art => botany/art}/flytrap3.txt | 0 {art => botany/art}/hemp1.txt | 0 {art => botany/art}/hemp2.txt | 0 {art => botany/art}/hemp3.txt | 0 {art => botany/art}/iris1.txt | 0 {art => botany/art}/iris2.txt | 0 {art => botany/art}/iris3.txt | 0 {art => botany/art}/jackolantern.txt | 0 {art => botany/art}/jadeplant1.txt | 0 {art => botany/art}/jadeplant2.txt | 0 {art => botany/art}/jadeplant3.txt | 0 {art => botany/art}/lithops1.txt | 0 {art => botany/art}/lithops2.txt | 0 {art => botany/art}/lithops3.txt | 0 {art => botany/art}/moon.txt | 0 {art => botany/art}/moss1.txt | 0 {art => botany/art}/moss2.txt | 0 {art => botany/art}/moss3.txt | 0 {art => botany/art}/pachypodium1.txt | 0 {art => botany/art}/pachypodium2.txt | 0 {art => botany/art}/pachypodium3.txt | 0 {art => botany/art}/palm1.txt | 0 {art => botany/art}/palm2.txt | 0 {art => botany/art}/palm3.txt | 0 {art => botany/art}/pansy1.txt | 0 {art => botany/art}/pansy2.txt | 0 {art => botany/art}/pansy3.txt | 0 {art => botany/art}/poppy1.txt | 0 {art => botany/art}/poppy2.txt | 0 {art => botany/art}/poppy3.txt | 0 {art => botany/art}/rip.txt | 0 {art => botany/art}/sage1.txt | 0 {art => botany/art}/sage2.txt | 0 {art => botany/art}/sage3.txt | 0 {art => botany/art}/seed.txt | 0 {art => botany/art}/seedling.txt | 0 {art => botany/art}/snapdragon1.txt | 0 {art => botany/art}/snapdragon2.txt | 0 {art => botany/art}/snapdragon3.txt | 0 {art => botany/art}/sun.txt | 0 {art => botany/art}/sunflower1.txt | 0 {art => botany/art}/sunflower2.txt | 0 {art => botany/art}/sunflower3.txt | 0 {art => botany/art}/template.txt | 0 botany/botany.py | 61 +++++++++++++++++ botany-view.py => botany/botany_view.py | 11 ++-- completer.py => botany/completer.py | 0 botany.py => botany/data_manager.py | 65 ++----------------- menu_screen.py => botany/menu_screen.py | 12 ++-- plant.py => botany/plant.py | 6 +- pyproject.toml | 56 ++++++++++++++++ .../clear_weekly_users.py | 11 +++- scripts/pre_build.sh | 30 +++++++++ testsql.py => scripts/testsql.py | 10 ++- 87 files changed, 192 insertions(+), 79 deletions(-) create mode 100644 botany/__init__.py rename {art => botany/art}/agave1.txt (100%) rename {art => botany/art}/agave2.txt (100%) rename {art => botany/art}/agave3.txt (100%) rename {art => botany/art}/aloe1.txt (100%) rename {art => botany/art}/aloe2.txt (100%) rename {art => botany/art}/aloe3.txt (100%) rename {art => botany/art}/baobab1.txt (100%) rename {art => botany/art}/baobab2.txt (100%) rename {art => botany/art}/baobab3.txt (100%) rename {art => botany/art}/bee.txt (100%) rename {art => botany/art}/brugmansia1.txt (100%) rename {art => botany/art}/brugmansia2.txt (100%) rename {art => botany/art}/brugmansia3.txt (100%) rename {art => botany/art}/cactus1.txt (100%) rename {art => botany/art}/cactus2.txt (100%) rename {art => botany/art}/cactus3.txt (100%) rename {art => botany/art}/columbine1.txt (100%) rename {art => botany/art}/columbine2.txt (100%) rename {art => botany/art}/columbine3.txt (100%) rename {art => botany/art}/daffodil1.txt (100%) rename {art => botany/art}/daffodil2.txt (100%) rename {art => botany/art}/daffodil3.txt (100%) rename {art => botany/art}/fern1.txt (100%) rename {art => botany/art}/fern2.txt (100%) rename {art => botany/art}/fern3.txt (100%) rename {art => botany/art}/ficus1.txt (100%) rename {art => botany/art}/ficus2.txt (100%) rename {art => botany/art}/ficus3.txt (100%) rename {art => botany/art}/flytrap1.txt (100%) rename {art => botany/art}/flytrap2.txt (100%) rename {art => botany/art}/flytrap3.txt (100%) rename {art => botany/art}/hemp1.txt (100%) rename {art => botany/art}/hemp2.txt (100%) rename {art => botany/art}/hemp3.txt (100%) rename {art => botany/art}/iris1.txt (100%) rename {art => botany/art}/iris2.txt (100%) rename {art => botany/art}/iris3.txt (100%) rename {art => botany/art}/jackolantern.txt (100%) rename {art => botany/art}/jadeplant1.txt (100%) rename {art => botany/art}/jadeplant2.txt (100%) rename {art => botany/art}/jadeplant3.txt (100%) rename {art => botany/art}/lithops1.txt (100%) rename {art => botany/art}/lithops2.txt (100%) rename {art => botany/art}/lithops3.txt (100%) rename {art => botany/art}/moon.txt (100%) rename {art => botany/art}/moss1.txt (100%) rename {art => botany/art}/moss2.txt (100%) rename {art => botany/art}/moss3.txt (100%) rename {art => botany/art}/pachypodium1.txt (100%) rename {art => botany/art}/pachypodium2.txt (100%) rename {art => botany/art}/pachypodium3.txt (100%) rename {art => botany/art}/palm1.txt (100%) rename {art => botany/art}/palm2.txt (100%) rename {art => botany/art}/palm3.txt (100%) rename {art => botany/art}/pansy1.txt (100%) rename {art => botany/art}/pansy2.txt (100%) rename {art => botany/art}/pansy3.txt (100%) rename {art => botany/art}/poppy1.txt (100%) rename {art => botany/art}/poppy2.txt (100%) rename {art => botany/art}/poppy3.txt (100%) rename {art => botany/art}/rip.txt (100%) rename {art => botany/art}/sage1.txt (100%) rename {art => botany/art}/sage2.txt (100%) rename {art => botany/art}/sage3.txt (100%) rename {art => botany/art}/seed.txt (100%) rename {art => botany/art}/seedling.txt (100%) rename {art => botany/art}/snapdragon1.txt (100%) rename {art => botany/art}/snapdragon2.txt (100%) rename {art => botany/art}/snapdragon3.txt (100%) rename {art => botany/art}/sun.txt (100%) rename {art => botany/art}/sunflower1.txt (100%) rename {art => botany/art}/sunflower2.txt (100%) rename {art => botany/art}/sunflower3.txt (100%) rename {art => botany/art}/template.txt (100%) create mode 100755 botany/botany.py rename botany-view.py => botany/botany_view.py (94%) rename completer.py => botany/completer.py (100%) rename botany.py => botany/data_manager.py (79%) mode change 100755 => 100644 rename menu_screen.py => botany/menu_screen.py (99%) rename plant.py => botany/plant.py (98%) create mode 100644 pyproject.toml rename clear_weekly_users.py => scripts/clear_weekly_users.py (65%) mode change 100644 => 100755 create mode 100755 scripts/pre_build.sh rename testsql.py => scripts/testsql.py (92%) mode change 100644 => 100755 diff --git a/.gitignore b/.gitignore index b99deb4..4d44c74 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,6 @@ garden_file.dat garden_file.json sqlite/ *.swp +build +*.egg-info +.venv diff --git a/README.md b/README.md index 132cb0e..8640cd3 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,11 @@ Check in and water your plant every 24h to keep it growing. 5 days without water *"We do not 'come into' this world; we come out of it, as leaves from a tree." - Alan Watts* ## getting started -botany is designed for unix-based systems. Clone into a local directory using `$ git clone https://github.com/jifunks/botany.git`. +botany is designed for unix-based systems. Install it with pip using `$ python3 -m pip install git+https://github.com/jifunks/botany`. -Run with `$ python3 botany.py`. +By default, the game directory path is `/usr/share/botany`. Feel free to use [scripts/pre_build.sh](scripts/pre_build.sh) to modify it, it implies to clone this git repository. -*Note - botany.py must initially be run by the user who cloned/unzipped botany.py - this initializes the shared data file permissions.* +Run with `$ botany`. Water your seed to get started. You can come and go as you please and your plant continues to grow. diff --git a/botany/__init__.py b/botany/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/art/agave1.txt b/botany/art/agave1.txt similarity index 100% rename from art/agave1.txt rename to botany/art/agave1.txt diff --git a/art/agave2.txt b/botany/art/agave2.txt similarity index 100% rename from art/agave2.txt rename to botany/art/agave2.txt diff --git a/art/agave3.txt b/botany/art/agave3.txt similarity index 100% rename from art/agave3.txt rename to botany/art/agave3.txt diff --git a/art/aloe1.txt b/botany/art/aloe1.txt similarity index 100% rename from art/aloe1.txt rename to botany/art/aloe1.txt diff --git a/art/aloe2.txt b/botany/art/aloe2.txt similarity index 100% rename from art/aloe2.txt rename to botany/art/aloe2.txt diff --git a/art/aloe3.txt b/botany/art/aloe3.txt similarity index 100% rename from art/aloe3.txt rename to botany/art/aloe3.txt diff --git a/art/baobab1.txt b/botany/art/baobab1.txt similarity index 100% rename from art/baobab1.txt rename to botany/art/baobab1.txt diff --git a/art/baobab2.txt b/botany/art/baobab2.txt similarity index 100% rename from art/baobab2.txt rename to botany/art/baobab2.txt diff --git a/art/baobab3.txt b/botany/art/baobab3.txt similarity index 100% rename from art/baobab3.txt rename to botany/art/baobab3.txt diff --git a/art/bee.txt b/botany/art/bee.txt similarity index 100% rename from art/bee.txt rename to botany/art/bee.txt diff --git a/art/brugmansia1.txt b/botany/art/brugmansia1.txt similarity index 100% rename from art/brugmansia1.txt rename to botany/art/brugmansia1.txt diff --git a/art/brugmansia2.txt b/botany/art/brugmansia2.txt similarity index 100% rename from art/brugmansia2.txt rename to botany/art/brugmansia2.txt diff --git a/art/brugmansia3.txt b/botany/art/brugmansia3.txt similarity index 100% rename from art/brugmansia3.txt rename to botany/art/brugmansia3.txt diff --git a/art/cactus1.txt b/botany/art/cactus1.txt similarity index 100% rename from art/cactus1.txt rename to botany/art/cactus1.txt diff --git a/art/cactus2.txt b/botany/art/cactus2.txt similarity index 100% rename from art/cactus2.txt rename to botany/art/cactus2.txt diff --git a/art/cactus3.txt b/botany/art/cactus3.txt similarity index 100% rename from art/cactus3.txt rename to botany/art/cactus3.txt diff --git a/art/columbine1.txt b/botany/art/columbine1.txt similarity index 100% rename from art/columbine1.txt rename to botany/art/columbine1.txt diff --git a/art/columbine2.txt b/botany/art/columbine2.txt similarity index 100% rename from art/columbine2.txt rename to botany/art/columbine2.txt diff --git a/art/columbine3.txt b/botany/art/columbine3.txt similarity index 100% rename from art/columbine3.txt rename to botany/art/columbine3.txt diff --git a/art/daffodil1.txt b/botany/art/daffodil1.txt similarity index 100% rename from art/daffodil1.txt rename to botany/art/daffodil1.txt diff --git a/art/daffodil2.txt b/botany/art/daffodil2.txt similarity index 100% rename from art/daffodil2.txt rename to botany/art/daffodil2.txt diff --git a/art/daffodil3.txt b/botany/art/daffodil3.txt similarity index 100% rename from art/daffodil3.txt rename to botany/art/daffodil3.txt diff --git a/art/fern1.txt b/botany/art/fern1.txt similarity index 100% rename from art/fern1.txt rename to botany/art/fern1.txt diff --git a/art/fern2.txt b/botany/art/fern2.txt similarity index 100% rename from art/fern2.txt rename to botany/art/fern2.txt diff --git a/art/fern3.txt b/botany/art/fern3.txt similarity index 100% rename from art/fern3.txt rename to botany/art/fern3.txt diff --git a/art/ficus1.txt b/botany/art/ficus1.txt similarity index 100% rename from art/ficus1.txt rename to botany/art/ficus1.txt diff --git a/art/ficus2.txt b/botany/art/ficus2.txt similarity index 100% rename from art/ficus2.txt rename to botany/art/ficus2.txt diff --git a/art/ficus3.txt b/botany/art/ficus3.txt similarity index 100% rename from art/ficus3.txt rename to botany/art/ficus3.txt diff --git a/art/flytrap1.txt b/botany/art/flytrap1.txt similarity index 100% rename from art/flytrap1.txt rename to botany/art/flytrap1.txt diff --git a/art/flytrap2.txt b/botany/art/flytrap2.txt similarity index 100% rename from art/flytrap2.txt rename to botany/art/flytrap2.txt diff --git a/art/flytrap3.txt b/botany/art/flytrap3.txt similarity index 100% rename from art/flytrap3.txt rename to botany/art/flytrap3.txt diff --git a/art/hemp1.txt b/botany/art/hemp1.txt similarity index 100% rename from art/hemp1.txt rename to botany/art/hemp1.txt diff --git a/art/hemp2.txt b/botany/art/hemp2.txt similarity index 100% rename from art/hemp2.txt rename to botany/art/hemp2.txt diff --git a/art/hemp3.txt b/botany/art/hemp3.txt similarity index 100% rename from art/hemp3.txt rename to botany/art/hemp3.txt diff --git a/art/iris1.txt b/botany/art/iris1.txt similarity index 100% rename from art/iris1.txt rename to botany/art/iris1.txt diff --git a/art/iris2.txt b/botany/art/iris2.txt similarity index 100% rename from art/iris2.txt rename to botany/art/iris2.txt diff --git a/art/iris3.txt b/botany/art/iris3.txt similarity index 100% rename from art/iris3.txt rename to botany/art/iris3.txt diff --git a/art/jackolantern.txt b/botany/art/jackolantern.txt similarity index 100% rename from art/jackolantern.txt rename to botany/art/jackolantern.txt diff --git a/art/jadeplant1.txt b/botany/art/jadeplant1.txt similarity index 100% rename from art/jadeplant1.txt rename to botany/art/jadeplant1.txt diff --git a/art/jadeplant2.txt b/botany/art/jadeplant2.txt similarity index 100% rename from art/jadeplant2.txt rename to botany/art/jadeplant2.txt diff --git a/art/jadeplant3.txt b/botany/art/jadeplant3.txt similarity index 100% rename from art/jadeplant3.txt rename to botany/art/jadeplant3.txt diff --git a/art/lithops1.txt b/botany/art/lithops1.txt similarity index 100% rename from art/lithops1.txt rename to botany/art/lithops1.txt diff --git a/art/lithops2.txt b/botany/art/lithops2.txt similarity index 100% rename from art/lithops2.txt rename to botany/art/lithops2.txt diff --git a/art/lithops3.txt b/botany/art/lithops3.txt similarity index 100% rename from art/lithops3.txt rename to botany/art/lithops3.txt diff --git a/art/moon.txt b/botany/art/moon.txt similarity index 100% rename from art/moon.txt rename to botany/art/moon.txt diff --git a/art/moss1.txt b/botany/art/moss1.txt similarity index 100% rename from art/moss1.txt rename to botany/art/moss1.txt diff --git a/art/moss2.txt b/botany/art/moss2.txt similarity index 100% rename from art/moss2.txt rename to botany/art/moss2.txt diff --git a/art/moss3.txt b/botany/art/moss3.txt similarity index 100% rename from art/moss3.txt rename to botany/art/moss3.txt diff --git a/art/pachypodium1.txt b/botany/art/pachypodium1.txt similarity index 100% rename from art/pachypodium1.txt rename to botany/art/pachypodium1.txt diff --git a/art/pachypodium2.txt b/botany/art/pachypodium2.txt similarity index 100% rename from art/pachypodium2.txt rename to botany/art/pachypodium2.txt diff --git a/art/pachypodium3.txt b/botany/art/pachypodium3.txt similarity index 100% rename from art/pachypodium3.txt rename to botany/art/pachypodium3.txt diff --git a/art/palm1.txt b/botany/art/palm1.txt similarity index 100% rename from art/palm1.txt rename to botany/art/palm1.txt diff --git a/art/palm2.txt b/botany/art/palm2.txt similarity index 100% rename from art/palm2.txt rename to botany/art/palm2.txt diff --git a/art/palm3.txt b/botany/art/palm3.txt similarity index 100% rename from art/palm3.txt rename to botany/art/palm3.txt diff --git a/art/pansy1.txt b/botany/art/pansy1.txt similarity index 100% rename from art/pansy1.txt rename to botany/art/pansy1.txt diff --git a/art/pansy2.txt b/botany/art/pansy2.txt similarity index 100% rename from art/pansy2.txt rename to botany/art/pansy2.txt diff --git a/art/pansy3.txt b/botany/art/pansy3.txt similarity index 100% rename from art/pansy3.txt rename to botany/art/pansy3.txt diff --git a/art/poppy1.txt b/botany/art/poppy1.txt similarity index 100% rename from art/poppy1.txt rename to botany/art/poppy1.txt diff --git a/art/poppy2.txt b/botany/art/poppy2.txt similarity index 100% rename from art/poppy2.txt rename to botany/art/poppy2.txt diff --git a/art/poppy3.txt b/botany/art/poppy3.txt similarity index 100% rename from art/poppy3.txt rename to botany/art/poppy3.txt diff --git a/art/rip.txt b/botany/art/rip.txt similarity index 100% rename from art/rip.txt rename to botany/art/rip.txt diff --git a/art/sage1.txt b/botany/art/sage1.txt similarity index 100% rename from art/sage1.txt rename to botany/art/sage1.txt diff --git a/art/sage2.txt b/botany/art/sage2.txt similarity index 100% rename from art/sage2.txt rename to botany/art/sage2.txt diff --git a/art/sage3.txt b/botany/art/sage3.txt similarity index 100% rename from art/sage3.txt rename to botany/art/sage3.txt diff --git a/art/seed.txt b/botany/art/seed.txt similarity index 100% rename from art/seed.txt rename to botany/art/seed.txt diff --git a/art/seedling.txt b/botany/art/seedling.txt similarity index 100% rename from art/seedling.txt rename to botany/art/seedling.txt diff --git a/art/snapdragon1.txt b/botany/art/snapdragon1.txt similarity index 100% rename from art/snapdragon1.txt rename to botany/art/snapdragon1.txt diff --git a/art/snapdragon2.txt b/botany/art/snapdragon2.txt similarity index 100% rename from art/snapdragon2.txt rename to botany/art/snapdragon2.txt diff --git a/art/snapdragon3.txt b/botany/art/snapdragon3.txt similarity index 100% rename from art/snapdragon3.txt rename to botany/art/snapdragon3.txt diff --git a/art/sun.txt b/botany/art/sun.txt similarity index 100% rename from art/sun.txt rename to botany/art/sun.txt diff --git a/art/sunflower1.txt b/botany/art/sunflower1.txt similarity index 100% rename from art/sunflower1.txt rename to botany/art/sunflower1.txt diff --git a/art/sunflower2.txt b/botany/art/sunflower2.txt similarity index 100% rename from art/sunflower2.txt rename to botany/art/sunflower2.txt diff --git a/art/sunflower3.txt b/botany/art/sunflower3.txt similarity index 100% rename from art/sunflower3.txt rename to botany/art/sunflower3.txt diff --git a/art/template.txt b/botany/art/template.txt similarity index 100% rename from art/template.txt rename to botany/art/template.txt diff --git a/botany/botany.py b/botany/botany.py new file mode 100755 index 0000000..6358e2c --- /dev/null +++ b/botany/botany.py @@ -0,0 +1,61 @@ + +from botany import menu_screen as ms +from botany.plant import Plant +from botany.data_manager import DataManager + +# TODO: +# - switch from personal data file to row in DB +# - is threading necessary? +# - use a different curses window for plant, menu, info window, score + +# notes from vilmibm + +# there are threads. +# - life thread. sleeps a variable amount of time based on generation bonus. increases tick count (ticks == score). +# - screen: sleeps 1s per loop. draws interface (including plant). for seeing score/plant change without user input. +# meanwhile, the main thread handles input and redraws curses as needed. + +# affordance index +# - main screen +# navigable menu, plant, score, etc +# - water +# render a visualization of moistness; allow to water +# - look +# print a description of plant with info below rest of UI +# - garden +# runs a paginated view of every plant on the computer below rest of UI. to return to menu navigation must hit q. +# - visit +# runs a prompt underneath UI where you can see who recently visited you and type in a name to visit. must submit the prompt to get back to menu navigation. +# - instructions +# prints some explanatory text below the UI +# - exit +# quits program + +# part of the complexity of all this is everything takes place in one curses window; thus, updates must be manually synchronized across the various logical parts of the screen. +# ideally, multiple windows would be used: +# - the menu. it doesn't change unless the plant dies OR the plant hits stage 5, then "harvest" is dynamically added. +# - the plant viewer. this is updated in "real time" as the plant grows. +# - the status display: score and plant description +# - the infow window. updated by visit/garden/instructions/look + + + +def main(): + my_data = DataManager() + # if plant save file exists + if my_data.check_plant(): + my_plant = my_data.load_plant() + # otherwise create new plant + else: + my_plant = Plant(my_data.savefile_path) + my_data.data_write_json(my_plant) + # my_plant is either a fresh plant or an existing plant at this point + my_plant.start_life(my_data) + + ms.main(my_plant, my_data) + my_data.save_plant(my_plant) + my_data.data_write_json(my_plant) + my_data.update_garden_db(my_plant) + +if __name__ == '__main__': + main() diff --git a/botany-view.py b/botany/botany_view.py similarity index 94% rename from botany-view.py rename to botany/botany_view.py index 9f1d42f..4ff3f22 100755 --- a/botany-view.py +++ b/botany/botany_view.py @@ -1,8 +1,8 @@ -#!/usr/bin/env python3 - +import os import datetime -from botany import * +from botany.plant import Plant +from botany.data_manager import DataManager def ascii_render(filename): # Prints ASCII art from file at given coordinates @@ -58,7 +58,7 @@ def draw_plant_ascii(this_plant): this_filename = plant_art_list[this_plant.species]+'3.txt' ascii_render(this_filename) -if __name__ == '__main__': +def main(): my_data = DataManager() # if plant save file exists if my_data.check_plant(): @@ -68,3 +68,6 @@ def draw_plant_ascii(this_plant): my_plant = Plant(my_data.savefile_path) my_data.data_write_json(my_plant) draw_plant_ascii(my_plant) + +if __name__ == '__main__': + main() diff --git a/completer.py b/botany/completer.py similarity index 100% rename from completer.py rename to botany/completer.py diff --git a/botany.py b/botany/data_manager.py old mode 100755 new mode 100644 similarity index 79% rename from botany.py rename to botany/data_manager.py index 4e07fe4..8efbddb --- a/botany.py +++ b/botany/data_manager.py @@ -1,52 +1,14 @@ -#!/usr/bin/env python3 - import time import pickle import json import os import getpass -import threading import errno import sqlite3 -import menu_screen as ms -from plant import Plant - -# TODO: -# - switch from personal data file to row in DB -# - is threading necessary? -# - use a different curses window for plant, menu, info window, score - -# notes from vilmibm - -# there are threads. -# - life thread. sleeps a variable amount of time based on generation bonus. increases tick count (ticks == score). -# - screen: sleeps 1s per loop. draws interface (including plant). for seeing score/plant change without user input. -# meanwhile, the main thread handles input and redraws curses as needed. - -# affordance index -# - main screen -# navigable menu, plant, score, etc -# - water -# render a visualization of moistness; allow to water -# - look -# print a description of plant with info below rest of UI -# - garden -# runs a paginated view of every plant on the computer below rest of UI. to return to menu navigation must hit q. -# - visit -# runs a prompt underneath UI where you can see who recently visited you and type in a name to visit. must submit the prompt to get back to menu navigation. -# - instructions -# prints some explanatory text below the UI -# - exit -# quits program -# part of the complexity of all this is everything takes place in one curses window; thus, updates must be manually synchronized across the various logical parts of the screen. -# ideally, multiple windows would be used: -# - the menu. it doesn't change unless the plant dies OR the plant hits stage 5, then "harvest" is dynamically added. -# - the plant viewer. this is updated in "real time" as the plant grows. -# - the status display: score and plant description -# - the infow window. updated by visit/garden/instructions/look +GAME_DIR = "/usr/share/botany" -class DataManager(object): +class DataManager: # handles user data, puts a .botany dir in user's home dir (OSX/Linux) # handles shared data with sqlite db # TODO: .dat save should only happen on mutation, water, death, exit, @@ -56,7 +18,9 @@ class DataManager(object): user_dir = os.path.expanduser("~") botany_dir = os.path.join(user_dir,'.botany') - game_dir = os.path.dirname(os.path.realpath(__file__)) + + game_dir = os.getenv("BOTANY_GAME_DIR") or GAME_DIR + this_user = getpass.getuser() savefile_name = this_user + '_plant.dat' @@ -283,21 +247,4 @@ def harvest_plant(self, this_plant): with open(self.harvest_json_path, 'w') as outfile: json.dump(this_harvest, outfile) - return new_file_check - -if __name__ == '__main__': - my_data = DataManager() - # if plant save file exists - if my_data.check_plant(): - my_plant = my_data.load_plant() - # otherwise create new plant - else: - my_plant = Plant(my_data.savefile_path) - my_data.data_write_json(my_plant) - # my_plant is either a fresh plant or an existing plant at this point - my_plant.start_life(my_data) - - ms.main(my_plant, my_data) - my_data.save_plant(my_plant) - my_data.data_write_json(my_plant) - my_data.update_garden_db(my_plant) + return new_file_check \ No newline at end of file diff --git a/menu_screen.py b/botany/menu_screen.py similarity index 99% rename from menu_screen.py rename to botany/menu_screen.py index ed95043..5b754fa 100644 --- a/menu_screen.py +++ b/botany/menu_screen.py @@ -10,13 +10,11 @@ import string import threading import time -from typing import TYPE_CHECKING -import completer -from plant import Plant -if TYPE_CHECKING: - from botany import DataManager +from botany import completer +from botany.plant import Plant +from botany.data_manager import DataManager class CursedMenu(object): @@ -638,9 +636,7 @@ def build_latest_visitor_output(self, visitors): return [visitor_line] def get_weekly_visitors(self): - game_dir = os.path.dirname(os.path.realpath(__file__)) - garden_db_path = os.path.join(game_dir, 'sqlite/garden_db.sqlite') - conn = sqlite3.connect(garden_db_path) + conn = sqlite3.connect(DataManager.garden_db_path) c = conn.cursor() c.execute("SELECT * FROM visitors WHERE garden_name = '{}' ORDER BY weekly_visits".format(self.plant.owner)) visitor_data = c.fetchall() diff --git a/plant.py b/botany/plant.py similarity index 98% rename from plant.py rename to botany/plant.py index 420d701..0dde9c7 100644 --- a/plant.py +++ b/botany/plant.py @@ -5,6 +5,9 @@ import time import uuid import getpass +import sqlite3 + +from botany.data_manager import DataManager class Plant: # This is your plant! @@ -198,8 +201,7 @@ def dead_check(self): return self.dead def update_visitor_db(self, visitor_names): - game_dir = os.path.dirname(os.path.realpath(__file__)) - garden_db_path = os.path.join(game_dir, 'sqlite/garden_db.sqlite') + garden_db_path = os.path.join(DataManager.garden_db_path) conn = sqlite3.connect(garden_db_path) for name in (visitor_names): c = conn.cursor() diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..be50c4b --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,56 @@ +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" + +[project] +name = "botany" +version = "0.0.1" +requires-python = ">=3" +authors = [ + {name = "Jake Funke", email = "jifunks@gmail.com"} +] +maintainers = [ + {name = "Jake Funke", email = "jifunks@gmail.com"} +] +description = "A command line, realtime, community plant buddy." +readme = "README.md" +license = "ISC" +license-files = ["LICENSE"] +keywords = [ + "plant", + "virtual", + "garden", + "cli", + "curses", + "pet", + "tilde", +] +classifiers = [ + "Programming Language :: Python", + "Environment :: Console", + "Environment :: Console :: Curses", + "Topic :: Games/Entertainment", + "Topic :: Games/Entertainment :: Simulation", + "Topic :: Multimedia :: Graphics", + "Topic :: System :: Shells", + "Topic :: Terminals", + "Operating System :: POSIX", + "Operating System :: Unix", +] + +[project.scripts] +botany = "botany.botany:main" +botany-view = "botany.botany_view:main" + +[project.urls] +Homepage = "https://github.com/jifunks/botany" +Documentation = "https://github.com/jifunks/botany" +Repository = "https://github.com/jifunks/botany" +"Bug Tracker" = "https://github.com/jifunks/botany/issues" + +[tool.setuptools] +packages = ["botany"] +include-package-data = true + +[tool.setuptools.package-data] +botany = ["art/*.txt"] diff --git a/clear_weekly_users.py b/scripts/clear_weekly_users.py old mode 100644 new mode 100755 similarity index 65% rename from clear_weekly_users.py rename to scripts/clear_weekly_users.py index 2e4308b..afa478e --- a/clear_weekly_users.py +++ b/scripts/clear_weekly_users.py @@ -1,8 +1,15 @@ +#!/usr/bin/env python3 + import os import sqlite3 -game_dir = os.path.dirname(os.path.realpath(__file__)) -garden_db_path = os.path.join(game_dir, 'sqlite/garden_db.sqlite') +from sys import argv + +argc = len(argv) + +game_dir = "/usr/share/botany" +garden_db_path = os.path.join(game_dir, 'sqlite/garden_db.sqlite') if argc <= 1 else argv[1] + conn = sqlite3.connect(garden_db_path) c = conn.cursor() c.execute("DELETE FROM visitors") diff --git a/scripts/pre_build.sh b/scripts/pre_build.sh new file mode 100755 index 0000000..e091e0a --- /dev/null +++ b/scripts/pre_build.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +set -e + +readonly GAME_DIR=${1} +readonly CURRENT_DIR=$(dirname ${0}) +readonly PROJECT_ROOT_DIR=${PROJECT_ROOT_DIR:-"${CURRENT_DIR}/.."} + +if [ "$#" -ne 1 ] +then + echo "Usage example: ${0} \"/srv/botany\"" + exit 1 +fi + +if ! command -v sed &> /dev/null +then + echo "The script needs the 'sed' program." >&2 + exit 1 +fi + + +mkdir -p "${GAME_DIR}" +chmod 755 "${GAME_DIR}" +echo "The directory '${GAME_DIR}' has been initialized." + +sed -i -e \ + "s|GAME_DIR = \".*\"|GAME_DIR = \"${GAME_DIR}\"|g"\ + "${PROJECT_ROOT_DIR}/botany/data_manager.py" + +echo "The game directory value has been successfully substitued with '${GAME_DIR}'." diff --git a/testsql.py b/scripts/testsql.py old mode 100644 new mode 100755 similarity index 92% rename from testsql.py rename to scripts/testsql.py index 6080d42..34fa01c --- a/testsql.py +++ b/scripts/testsql.py @@ -1,6 +1,14 @@ +#!/usr/bin/env python3 + +import os import sqlite3 -garden_db_path = "sqlite/garden_db.sqlite" +from sys import argv + +argc = len(argv) + +game_dir = "/usr/share/botany" +garden_db_path = os.path.join(game_dir, 'sqlite/garden_db.sqlite') if argc <= 1 else argv[1] def init_database(): #TODO: does this need permissions?