From 3bfaf4dd18f6a91cc07e7a19163f7d76739fca3b Mon Sep 17 00:00:00 2001 From: Ale Vilar Date: Thu, 12 Sep 2024 15:36:55 -0300 Subject: [PATCH 1/3] refactor: Update build workflow to include separate specifications for Windows and Linux builds and improve artifact upload process --- .github/workflows/desktop.build.yml | 136 +++++++++++++++++- buildozer.spec | 6 +- fiscalberry-lin.spec | 2 +- fiscalberry-win.spec | 2 +- requirements.cli.txt | 1 - requirements.kivy.txt | 1 - requirements.txt | 1 - setup.py | 1 - src/{fiscalberry_app => }/assets/bg.jpg | Bin .../assets/connected.png | Bin .../assets/disconnected.png | Bin .../assets/fiscalberry.ico | Bin .../assets/fiscalberry.jpg | Bin .../assets/fiscalberry.png | Bin src/{fiscalberry_app => }/assets/lion.ico | Bin src/{fiscalberry_app => }/assets/lion.jpg | Bin src/{fiscalberry_app => }/assets/lion.png | Bin src/cli.py | 16 +-- src/common/__init__.py | 1 + src/{ => common}/fiscalberry_sio.py | 32 ++--- src/fiscalberryservice.android.py | 2 +- src/main.py | 34 +++-- src/ui/__init__.py | 0 src/{fiscalberry_app => ui}/fiscalberry.kv | 0 .../fiscalberry_app.py | 2 +- 25 files changed, 183 insertions(+), 54 deletions(-) rename src/{fiscalberry_app => }/assets/bg.jpg (100%) rename src/{fiscalberry_app => }/assets/connected.png (100%) rename src/{fiscalberry_app => }/assets/disconnected.png (100%) rename src/{fiscalberry_app => }/assets/fiscalberry.ico (100%) rename src/{fiscalberry_app => }/assets/fiscalberry.jpg (100%) rename src/{fiscalberry_app => }/assets/fiscalberry.png (100%) rename src/{fiscalberry_app => }/assets/lion.ico (100%) rename src/{fiscalberry_app => }/assets/lion.jpg (100%) rename src/{fiscalberry_app => }/assets/lion.png (100%) create mode 100644 src/common/__init__.py rename src/{ => common}/fiscalberry_sio.py (73%) create mode 100644 src/ui/__init__.py rename src/{fiscalberry_app => ui}/fiscalberry.kv (100%) rename src/{fiscalberry_app => ui}/fiscalberry_app.py (98%) diff --git a/.github/workflows/desktop.build.yml b/.github/workflows/desktop.build.yml index c9e8abf7f5..03198a700e 100644 --- a/.github/workflows/desktop.build.yml +++ b/.github/workflows/desktop.build.yml @@ -1,12 +1,10 @@ name: Build Desktop Ejecutables - on Release -on: - push: - branches: - - main +on: push jobs: build-windows: + if: ${{ github.ref != 'refs/heads/main' }} runs-on: windows-latest steps: @@ -45,6 +43,7 @@ jobs: path: dist/fiscalberry-win.exe build-linux: + if: ${{ github.ref != 'refs/heads/main' }} runs-on: ubuntu-latest steps: @@ -87,6 +86,7 @@ jobs: path: dist/fiscalberry-lin gather-artifacts: + if: ${{ github.ref != 'refs/heads/main' }} runs-on: ubuntu-latest needs: [build-windows, build-linux] @@ -115,8 +115,132 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - tag_name: v1.0.2 - release_name: Release v1.0.2 + tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} + draft: false + prerelease: false + + - name: Set upload URL + run: echo "UPLOAD_URL=${{ steps.create_release.outputs.upload_url }}" >> $GITHUB_ENV + + - name: Upload Windows executable to release + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ env.UPLOAD_URL }} + asset_path: ./artifacts/fiscalberry-win.exe + build-windows: + runs-on: windows-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.12.4' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pyinstaller + + - name: Install escpos all modules includes win32 printing module if windows SO + run: | + pip install 'python-escpos[all]' + + - name: Install socketio client + run: | + pip install 'python-socketio[client]' + + - name: Install project dependencies + run: | + pip install -r requirements.cli.txt + + - name: Build windows executable + run: pyinstaller fiscalberry-win.spec + + - name: Upload executable + uses: actions/upload-artifact@v4 + with: + name: fiscalberry-win + path: dist/fiscalberry-win.exe + + build-linux: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.12.4' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pyinstaller + + - name: Install escpos all modules includes win32 printing module if windows SO + run: | + sudo apt-get install libcups2-dev + pip install 'python-escpos[all]' + + - name: Install socketio client + run: | + pip install 'python-socketio[client]' + + - name: Install project dependencies + run: | + pip install -r requirements.cli.txt + + - name: Build executable + run: pyinstaller fiscalberry-lin.spec + + - name: List dist directory (debugging) + run: ls -la dist + + - name: Upload executable + uses: actions/upload-artifact@v4 + with: + name: fiscalberry-lin + path: dist/fiscalberry-lin + + gather-artifacts: + runs-on: ubuntu-latest + needs: [build-windows, build-linux] + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Download Windows artifact + uses: actions/download-artifact@v4 + with: + name: fiscalberry-win + path: ./artifacts + + - name: Download Linux artifact + uses: actions/download-artifact@v4 + with: + name: fiscalberry-lin + path: ./artifacts + + - name: List artifacts directory (debugging) + run: ls -la ./artifacts + + - name: Create GitHub Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} draft: false prerelease: false diff --git a/buildozer.spec b/buildozer.spec index 3dc31069d9..3b40469399 100644 --- a/buildozer.spec +++ b/buildozer.spec @@ -16,7 +16,7 @@ source.dir = src #source.include_exts = py,png,jpg,kv,atlas # (list) List of inclusions using pattern matching -source.include_patterns = src/fiscalberry_app/assets/* +source.include_patterns = src/assets/* # (list) Source files to exclude (let empty to not exclude anything) #source.exclude_exts = spec @@ -44,10 +44,10 @@ requirements = python3,kivy,python-escpos,python-socketio,simple-websocket,uuid, # requirements.source.kivy = ../../kivy # (str) Presplash of the application -presplash.filename = %(source.dir)s/fiscalberry_app/assets/fiscalberry.png +presplash.filename = %(source.dir)s/assets/fiscalberry.png # (str) Icon of the application -icon.filename = %(source.dir)s/fiscalberry_app/assets/fiscalberry.png +icon.filename = %(source.dir)s/assets/fiscalberry.png # (list) Supported orientations # Valid options are: landscape, portrait, portrait-reverse or landscape-reverse diff --git a/fiscalberry-lin.spec b/fiscalberry-lin.spec index 3de279a20f..5a5e825139 100644 --- a/fiscalberry-lin.spec +++ b/fiscalberry-lin.spec @@ -35,5 +35,5 @@ exe = EXE( target_arch=None, codesign_identity=None, entitlements_file=None, - icon=['src/fiscalberry_app/assets/fiscalberry.ico'], + icon=['src/assets/fiscalberry.ico'], ) diff --git a/fiscalberry-win.spec b/fiscalberry-win.spec index 6fa4249976..de18e26357 100644 --- a/fiscalberry-win.spec +++ b/fiscalberry-win.spec @@ -35,5 +35,5 @@ exe = EXE( target_arch=None, codesign_identity=None, entitlements_file=None, - icon=['src/fiscalberry_app/assets/fiscalberry.ico'], + icon=['src/assets/fiscalberry.ico'], ) diff --git a/requirements.cli.txt b/requirements.cli.txt index e80ea09ba4..16702032a9 100644 --- a/requirements.cli.txt +++ b/requirements.cli.txt @@ -7,5 +7,4 @@ aiohttp==3.10.2 argparse==1.4.0 uuid==1.30 appdirs==1.4.4 -python-dotenv==1.0.1 platformdirs==4.2.2 \ No newline at end of file diff --git a/requirements.kivy.txt b/requirements.kivy.txt index bd54d62d88..6567c356b0 100644 --- a/requirements.kivy.txt +++ b/requirements.kivy.txt @@ -7,6 +7,5 @@ aiohttp==3.10.2 argparse==1.4.0 uuid==1.30 appdirs==1.4.4 -python-dotenv==1.0.1 platformdirs==4.2.2 kivy==2.3.0 diff --git a/requirements.txt b/requirements.txt index ca97d22266..a3cdcd6f7e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -25,7 +25,6 @@ wsproto==1.2.0 aiohttp==3.10.2 argparse==1.4.0 uuid==1.30 -python-dotenv==1.0.1 platformdirs==4.2.2 kivy==2.3.0 cython==3.0.11 diff --git a/setup.py b/setup.py index 20a677ccd9..a1b847f09b 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,6 @@ 'uuid==1.30', 'appdirs==1.4.4', 'kivy==2.3.0', - 'python-dotenv==1.0.1', 'platformdirs==4.2.2', ], entry_points={ diff --git a/src/fiscalberry_app/assets/bg.jpg b/src/assets/bg.jpg similarity index 100% rename from src/fiscalberry_app/assets/bg.jpg rename to src/assets/bg.jpg diff --git a/src/fiscalberry_app/assets/connected.png b/src/assets/connected.png similarity index 100% rename from src/fiscalberry_app/assets/connected.png rename to src/assets/connected.png diff --git a/src/fiscalberry_app/assets/disconnected.png b/src/assets/disconnected.png similarity index 100% rename from src/fiscalberry_app/assets/disconnected.png rename to src/assets/disconnected.png diff --git a/src/fiscalberry_app/assets/fiscalberry.ico b/src/assets/fiscalberry.ico similarity index 100% rename from src/fiscalberry_app/assets/fiscalberry.ico rename to src/assets/fiscalberry.ico diff --git a/src/fiscalberry_app/assets/fiscalberry.jpg b/src/assets/fiscalberry.jpg similarity index 100% rename from src/fiscalberry_app/assets/fiscalberry.jpg rename to src/assets/fiscalberry.jpg diff --git a/src/fiscalberry_app/assets/fiscalberry.png b/src/assets/fiscalberry.png similarity index 100% rename from src/fiscalberry_app/assets/fiscalberry.png rename to src/assets/fiscalberry.png diff --git a/src/fiscalberry_app/assets/lion.ico b/src/assets/lion.ico similarity index 100% rename from src/fiscalberry_app/assets/lion.ico rename to src/assets/lion.ico diff --git a/src/fiscalberry_app/assets/lion.jpg b/src/assets/lion.jpg similarity index 100% rename from src/fiscalberry_app/assets/lion.jpg rename to src/assets/lion.jpg diff --git a/src/fiscalberry_app/assets/lion.png b/src/assets/lion.png similarity index 100% rename from src/fiscalberry_app/assets/lion.png rename to src/assets/lion.png diff --git a/src/cli.py b/src/cli.py index b88550e389..77d7d2d422 100644 --- a/src/cli.py +++ b/src/cli.py @@ -3,12 +3,13 @@ import os import logging -from dotenv import load_dotenv -load_dotenv() +from common.Configberry import Configberry + +configberry = Configberry() +environment = configberry.config.get("SERVIDOR", "environment", fallback="production") # configuro logger segun ambiente -environment = os.getenv('ENVIRONMENT', 'production') if environment == 'development': print("* * * * * Modo de desarrollo * * * * *") logging.basicConfig(level=logging.DEBUG) @@ -22,14 +23,12 @@ # importo el modulo que se encarga de la comunicacion con el servidor -from fiscalberry_sio import FiscalberrySio +from common.fiscalberry_sio import FiscalberrySio from common.discover import send_discover_in_thread -from common.Configberry import Configberry -def main(): - configberry = Configberry() +def start(): while True: logger.info("Preparando Fiscalberry Server") @@ -42,5 +41,6 @@ def main(): logger.warning("Termino ejecucion de server socketio?.. reconectando en 5s") time.sleep(5) + if __name__ == "__main__": - main() + start() \ No newline at end of file diff --git a/src/common/__init__.py b/src/common/__init__.py new file mode 100644 index 0000000000..194a2ae935 --- /dev/null +++ b/src/common/__init__.py @@ -0,0 +1 @@ +# archivo init del modulo common \ No newline at end of file diff --git a/src/fiscalberry_sio.py b/src/common/fiscalberry_sio.py similarity index 73% rename from src/fiscalberry_sio.py rename to src/common/fiscalberry_sio.py index 43a24d5278..889303ad96 100644 --- a/src/fiscalberry_sio.py +++ b/src/common/fiscalberry_sio.py @@ -34,7 +34,7 @@ class FiscalberrySio(): stop_event = threading.Event() def __init__(self, sockeiIoServer, uuid, namespaces = ["/paxaprinter"]) -> None: - self.sio = socketio.Client(reconnection=True, reconnection_attempts=0, reconnection_delay=2, reconnection_delay_max=15, logger=sioLogger, engineio_logger=False) + self.sio = socketio.Client(reconnection=True, reconnection_attempts=0, reconnection_delay=2, reconnection_delay_max=15, logger=sioLogger, engineio_logger=sioLogger) self.sockeiIoServer = sockeiIoServer self.uuid = uuid @@ -65,24 +65,18 @@ def start_only_status_in_thread(self) -> threading.Thread: return self.thread def __run(self): - while not self.stop_event.is_set(): - try: - self.sio.connect(self.sockeiIoServer, namespaces=self.namespaces, headers={"X_UUID":self.uuid}) - logger.info("Iniciado SioClient en %s con uuid %s" % (self.sockeiIoServer, self.uuid)) - self.sio.wait() - - except socketio.exceptions.ConnectionError as e: - logger.error(f"socketio Connection error: {e}") - self.sio.disconnect() - except Exception as e: - self.sio.disconnect() - logger.error(f"An unexpected error occurred: {e}") - - logger.info("FiscalberrySio: stopped, reconectando en 3s") - for i in range(3, 0, -1): - time.sleep(1) - logger.info(f"FiscalberrySio: stopped, reconectando en {i}s") - + try: + logger.info("FiscalberrySio: ******************************* CONECTANDO *******************************") + self.sio.connect(self.sockeiIoServer, namespaces=self.namespaces, headers={"X_UUID":self.uuid}) + logger.info("Iniciado SioClient en %s con uuid %s" % (self.sockeiIoServer, self.uuid)) + self.sio.wait() + + except socketio.exceptions.ConnectionError as e: + logger.error(f"socketio Connection error: {e}") + self.sio.disconnect() + except Exception as e: + self.sio.disconnect() + logger.error(f"An unexpected error occurred: {e}") def start_print_server(self): diff --git a/src/fiscalberryservice.android.py b/src/fiscalberryservice.android.py index efecfb743d..1689c95c80 100644 --- a/src/fiscalberryservice.android.py +++ b/src/fiscalberryservice.android.py @@ -11,7 +11,7 @@ # importo el modulo que se encarga de la comunicacion con el servidor -from fiscalberry_sio import FiscalberrySio +from common.fiscalberry_sio import FiscalberrySio from common.discover import send_discover_in_thread from common.Configberry import Configberry diff --git a/src/main.py b/src/main.py index fb1aa682d9..9310a1395c 100755 --- a/src/main.py +++ b/src/main.py @@ -2,14 +2,14 @@ import os import logging -from dotenv import load_dotenv -load_dotenv() +from common.Configberry import Configberry -__version__ = "0.1.0" +configberry = Configberry() + +environment = configberry.config.get("SERVIDOR", "environment", fallback="production") # Configuro logger según ambiente -environment = os.getenv('ENVIRONMENT', 'production') if environment == 'development': print("* * * * * Modo de desarrollo * * * * *") logging.basicConfig(level=logging.DEBUG) @@ -18,13 +18,27 @@ logging.basicConfig(level=logging.WARNING) -from fiscalberry_app.fiscalberry_app import FiscalberryApp +import sys -if __name__ == "__main__": +__version__ = "0.1.0" - # Crear la aplicación Kivy - app = FiscalberryApp() - # Ejecutar la aplicación Kivy - app.run() +if __name__ == "__main__": + + if len(sys.argv) > 1 and sys.argv[1] == "cli": + import cli as cli + + cli.start() + + else: + from ui.fiscalberry_app import FiscalberryApp + + # Llamar a la función que maneja la interfaz de usuario + start_ui() + # Crear la aplicación Kivy + app = FiscalberryApp() + + # Ejecutar la aplicación Kivy + app.run() + diff --git a/src/ui/__init__.py b/src/ui/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/fiscalberry_app/fiscalberry.kv b/src/ui/fiscalberry.kv similarity index 100% rename from src/fiscalberry_app/fiscalberry.kv rename to src/ui/fiscalberry.kv diff --git a/src/fiscalberry_app/fiscalberry_app.py b/src/ui/fiscalberry_app.py similarity index 98% rename from src/fiscalberry_app/fiscalberry_app.py rename to src/ui/fiscalberry_app.py index 3a7aeb1182..73b7d1128b 100644 --- a/src/fiscalberry_app/fiscalberry_app.py +++ b/src/ui/fiscalberry_app.py @@ -60,7 +60,7 @@ def __init__(self, **kwargs): class FiscalberryApp(App): - assetpath = os.path.dirname(os.path.abspath(__file__)) + assetpath = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) background_image = StringProperty(f"{assetpath}/assets/bg.jpg") logo_image = StringProperty(f"{assetpath}/assets/fiscalberry.png") From f75683813a0a829020490c504d10e8bdbb428a99 Mon Sep 17 00:00:00 2001 From: Ale Vilar Date: Thu, 12 Sep 2024 15:39:21 -0300 Subject: [PATCH 2/3] refactor: Update build workflow to include separate specifications for Windows and Linux builds and improve artifact upload process --- .github/workflows/desktop.build.yml | 127 ---------------------------- 1 file changed, 127 deletions(-) diff --git a/.github/workflows/desktop.build.yml b/.github/workflows/desktop.build.yml index 03198a700e..ac0bd13b58 100644 --- a/.github/workflows/desktop.build.yml +++ b/.github/workflows/desktop.build.yml @@ -3,133 +3,6 @@ name: Build Desktop Ejecutables - on Release on: push jobs: - build-windows: - if: ${{ github.ref != 'refs/heads/main' }} - runs-on: windows-latest - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.12.4' - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install pyinstaller - - - name: Install escpos all modules includes win32 printing module if windows SO - run: | - pip install 'python-escpos[all]' - - - name: Install socketio client - run: | - pip install 'python-socketio[client]' - - - name: Install project dependencies - run: | - pip install -r requirements.cli.txt - - - name: Build windows executable - run: pyinstaller fiscalberry-win.spec - - - name: Upload executable - uses: actions/upload-artifact@v4 - with: - name: fiscalberry-win - path: dist/fiscalberry-win.exe - - build-linux: - if: ${{ github.ref != 'refs/heads/main' }} - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.12.4' - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install pyinstaller - - - name: Install escpos all modules includes win32 printing module if windows SO - run: | - sudo apt-get install libcups2-dev - pip install 'python-escpos[all]' - - - name: Install socketio client - run: | - pip install 'python-socketio[client]' - - - name: Install project dependencies - run: | - pip install -r requirements.cli.txt - - - name: Build executable - run: pyinstaller fiscalberry-lin.spec - - - name: List dist directory (debugging) - run: ls -la dist - - - name: Upload executable - uses: actions/upload-artifact@v4 - with: - name: fiscalberry-lin - path: dist/fiscalberry-lin - - gather-artifacts: - if: ${{ github.ref != 'refs/heads/main' }} - runs-on: ubuntu-latest - needs: [build-windows, build-linux] - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Download Windows artifact - uses: actions/download-artifact@v4 - with: - name: fiscalberry-win - path: ./artifacts - - - name: Download Linux artifact - uses: actions/download-artifact@v4 - with: - name: fiscalberry-lin - path: ./artifacts - - - name: List artifacts directory (debugging) - run: ls -la ./artifacts - - - name: Create GitHub Release - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: ${{ github.ref }} - release_name: Release ${{ github.ref }} - draft: false - prerelease: false - - - name: Set upload URL - run: echo "UPLOAD_URL=${{ steps.create_release.outputs.upload_url }}" >> $GITHUB_ENV - - - name: Upload Windows executable to release - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ env.UPLOAD_URL }} - asset_path: ./artifacts/fiscalberry-win.exe build-windows: runs-on: windows-latest From 0fc0e95c7e3f35f37a22c44978eb18c9fae77671 Mon Sep 17 00:00:00 2001 From: Ale Vilar Date: Thu, 12 Sep 2024 15:53:48 -0300 Subject: [PATCH 3/3] refactor: Update build workflow to specify tag and release name for v1.0.3 --- .github/workflows/desktop.build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/desktop.build.yml b/.github/workflows/desktop.build.yml index ac0bd13b58..f7c776c5ea 100644 --- a/.github/workflows/desktop.build.yml +++ b/.github/workflows/desktop.build.yml @@ -112,8 +112,8 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - tag_name: ${{ github.ref }} - release_name: Release ${{ github.ref }} + tag_name: v1.0.3 + release_name: Release v1.0.3 draft: false prerelease: false