From 9b3e17997dfb79054bb6b7ed9c6720f3439bbf66 Mon Sep 17 00:00:00 2001 From: slashtechno <77907286+slashtechno@users.noreply.github.com> Date: Tue, 1 Aug 2023 10:43:03 -0500 Subject: [PATCH] Fix packaging --- .gitignore | 2 +- poetry.lock | 2 +- pyproject.toml | 6 +++--- .../__init__.py | 0 .../__main__.py | 15 +++++++++------ .../utils/__init__.py | 2 +- .../utils/delete.py | 2 +- .../utils/upload.py | 2 +- .../utils/utils.py | 0 9 files changed, 17 insertions(+), 14 deletions(-) rename {cloudflare_gateway_adblocking => src}/__init__.py (100%) rename {cloudflare_gateway_adblocking => src}/__main__.py (93%) rename {cloudflare_gateway_adblocking => src}/utils/__init__.py (51%) rename cloudflare_gateway_adblocking/utils/delete_adblock_zerotrust.py => src/utils/delete.py (98%) rename {cloudflare_gateway_adblocking => src}/utils/upload.py (99%) rename {cloudflare_gateway_adblocking => src}/utils/utils.py (100%) diff --git a/.gitignore b/.gitignore index 98fa8d5..56cf5bb 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,4 @@ blocklists/* !blocklists/.gitkeep tmp.py .venv -testtmp \ No newline at end of file +dist/ \ No newline at end of file diff --git a/poetry.lock b/poetry.lock index a1b7fdd..3d4cf19 100644 --- a/poetry.lock +++ b/poetry.lock @@ -230,4 +230,4 @@ dev = ["black (>=19.3b0)", "pytest (>=4.6.2)"] [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "843328e3217d5ebc1fbb55737ca6edc4d47894e2b1c48e5ab5f3fe0b6a27045c" +content-hash = "8737765a4f30f43f2314296861d56c04682f5632f54ecd7b2046b4d9591ed101" diff --git a/pyproject.toml b/pyproject.toml index 182bb16..168894c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,14 +1,14 @@ [tool.poetry] name = "cloudflare-gateway-adblocking" -version = "0.1.0" +version = "0.1.9" description = "Serverless adblocking via Cloudflare Zero Trust Gateway" authors = ["slastechno <77907286+slashtechno@users.noreply.github.com>"] license = "MIT" readme = "README.md" -packages = [{include = "cloudflare_gateway_adblocking"}] +packages = [{include = "src"}] [tool.poetry.scripts] -cloudflare-gateway-adblocking = "cloudflare_gateway_adblocking.__main__:cli" +cloudflare-gateway-adblocking = "src.__main__:main" [tool.poetry.dependencies] python = "^3.10" diff --git a/cloudflare_gateway_adblocking/__init__.py b/src/__init__.py similarity index 100% rename from cloudflare_gateway_adblocking/__init__.py rename to src/__init__.py diff --git a/cloudflare_gateway_adblocking/__main__.py b/src/__main__.py similarity index 93% rename from cloudflare_gateway_adblocking/__main__.py rename to src/__main__.py index 7471fb8..0c9becf 100644 --- a/cloudflare_gateway_adblocking/__main__.py +++ b/src/__main__.py @@ -1,6 +1,6 @@ from loguru import logger # Import the utils package -import utils +from . import utils import argparse import os @@ -11,7 +11,7 @@ from pathlib import Path TOKEN = None ACCOUNT_ID = None -def cli(): +def main(): # Setup logging logger.remove() # ^10 is a formatting directive to center with a padding of 10 @@ -98,7 +98,10 @@ def cli(): if TOKEN is None or ACCOUNT_ID is None: logger.error("No environment variables found. Please create a .env file or .envrc file") # noqa E501 exit(1) - args.func(args) + try : + args.func(args) + except AttributeError: + argparser.print_help() def upload_to_cloudflare(args): logger.info("Uploading to Cloudflare") @@ -112,10 +115,10 @@ def upload_to_cloudflare(args): def delete_from_cloudflare(args): logger.info("Deleting from Cloudflare") rules = utils.utils.get_gateway_rules(ACCOUNT_ID, TOKEN) - utils.delete_adblock_zerotrust.delete_adblock_policy(rules, ACCOUNT_ID, TOKEN) + utils.delete.delete_adblock_policy(rules, ACCOUNT_ID, TOKEN) lists = utils.utils.get_lists(ACCOUNT_ID, TOKEN) lists = utils.utils.filter_adblock_lists(lists) - utils.delete_adblock_zerotrust.delete_adblock_list(lists, ACCOUNT_ID, TOKEN) + utils.delete.delete_adblock_list(lists, ACCOUNT_ID, TOKEN) if __name__ == "__main__": - cli() + main() diff --git a/cloudflare_gateway_adblocking/utils/__init__.py b/src/utils/__init__.py similarity index 51% rename from cloudflare_gateway_adblocking/utils/__init__.py rename to src/utils/__init__.py index 5150c17..ed1e77e 100644 --- a/cloudflare_gateway_adblocking/utils/__init__.py +++ b/src/utils/__init__.py @@ -1,3 +1,3 @@ from .utils import * from .upload import * -from .delete_adblock_zerotrust import * +from .delete import * diff --git a/cloudflare_gateway_adblocking/utils/delete_adblock_zerotrust.py b/src/utils/delete.py similarity index 98% rename from cloudflare_gateway_adblocking/utils/delete_adblock_zerotrust.py rename to src/utils/delete.py index 4ba34a7..f87ce46 100644 --- a/cloudflare_gateway_adblocking/utils/delete_adblock_zerotrust.py +++ b/src/utils/delete.py @@ -1,7 +1,7 @@ # This is a scriprt to undo the changes made by adblock-zerotrust.py import requests -import utils +from . import utils def delete_adblock_list(lists: dict, account_id: str, token: str): diff --git a/cloudflare_gateway_adblocking/utils/upload.py b/src/utils/upload.py similarity index 99% rename from cloudflare_gateway_adblocking/utils/upload.py rename to src/utils/upload.py index 6b326f3..8f05c19 100644 --- a/cloudflare_gateway_adblocking/utils/upload.py +++ b/src/utils/upload.py @@ -1,5 +1,5 @@ import requests -import utils +from . import utils import pathlib diff --git a/cloudflare_gateway_adblocking/utils/utils.py b/src/utils/utils.py similarity index 100% rename from cloudflare_gateway_adblocking/utils/utils.py rename to src/utils/utils.py