From 24bed1f975dd49f9bc464a4888f8fb67b903849f Mon Sep 17 00:00:00 2001 From: Shane <6071159+smashedr@users.noreply.github.com> Date: Mon, 1 Jul 2024 17:50:34 -0700 Subject: [PATCH] Add Build --- .github/workflows/build.yaml | 40 ++++++++++++++++++++++++++++++++++++ .gitignore | 2 +- README.md | 26 ++++++++++++----------- setup.py | 4 ++-- zipline.py | 15 ++++++++++++-- 5 files changed, 70 insertions(+), 17 deletions(-) create mode 100644 .github/workflows/build.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..c3ee0e4 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,40 @@ +name: "Build" + +on: + workflow_dispatch: + release: + types: [published] + +jobs: + build: + name: "Build" + runs-on: ubuntu-latest + timeout-minutes: 5 + + steps: + - name: "Checkout" + uses: actions/checkout@v4 + + - name: "Setup Python 3.11" + uses: actions/setup-python@v4 + with: + python-version: "3.11" + + - name: "Build" + run: | + python -m build + + - name: "Upload to Actions" + uses: actions/upload-artifact@v4 + with: + name: artifacts + path: dist/ + + - name: "Upload to Release" + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: dist/* + tag: ${{ github.ref }} + overwrite: true + file_glob: true diff --git a/.gitignore b/.gitignore index 0f38d92..b24a29f 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,4 @@ zipline_cli.*/ *.log *.pyc .coverage -.zipline +.zipline* diff --git a/README.md b/README.md index baadb1a..5d4ffc0 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,21 @@ [![Discord](https://img.shields.io/discord/899171661457293343?logo=discord&logoColor=white&label=Discord&color=31c754)](https://discord.gg/wXy6m2X8wY) [![Issues](https://img.shields.io/github/issues-raw/cssnr/zipline-cli?logo=github&logoColor=white&label=Issues&color=31c754)](https://github.com/cssnr/zipline-cli/issues) [![Codacy](https://img.shields.io/codacy/grade/1eee626c47fa4e6fb8b1ed3efdd3e518?logo=codacy&logoColor=white&label=Codacy&color=31c754)](https://app.codacy.com/gh/cssnr/zipline-cli/dashboard) -[![Build](https://github.com/cssnr/zipline-cli/actions/workflows/test.yaml/badge.svg)](https://github.com/cssnr/zipline-cli/actions/workflows/test.yaml) +[![Test](https://github.com/cssnr/zipline-cli/actions/workflows/test.yaml/badge.svg)](https://github.com/cssnr/zipline-cli/actions/workflows/test.yaml) +[![Build](https://github.com/cssnr/zipline-cli/actions/workflows/build.yaml/badge.svg)](https://github.com/cssnr/zipline-cli/actions/workflows/build.yaml) +[![GitHub Release Version](https://img.shields.io/github/v/release/cssnr/zipline-cli?logo=github)](https://github.com/cssnr/zipline-cli/releases/latest) [![PyPI](https://img.shields.io/pypi/v/zipline-cli?logo=python&logoColor=white&label=PyPI)](https://pypi.org/project/zipline-cli/) [![](https://repository-images.githubusercontent.com/661201286/8dfadbc8-94c0-4eaa-88bd-7ee351859510)](https://github.com/cssnr/zipline-cli) # Zipline CLI -Python 3 CLI Uploader for Zipline. +Python 3 CLI Uploader for Zipline and Django Files. Zipline CLI is currently functional and **Under Active Development**. Please open a [Feature Request](https://github.com/cssnr/zipline-cli/discussions/new?category=feature-requests) for new features and submit an [Issue](https://github.com/cssnr/zipline-cli/issues/new) for any bugs you find. -* Zipline Docs: [https://zipline.diced.tech/](https://zipline.diced.tech/) +* Zipline: [https://zipline.diced.tech/](https://zipline.diced.tech/) +* Django Files: [https://django-files.github.io/](https://django-files.github.io/) ## Table of Contents @@ -96,13 +99,14 @@ Environment Variables are stored in the `.zipline` file in your home directory. * Location: `~/.zipline` or `$HOME/.zipline` -| Variable | Description | -|----------------|------------------------------------------------------------------------------| -| ZIPLINE_URL | URL to your Zipline Instance | -| ZIPLINE_TOKEN | Authorization Token from Zipline | -| ZIPLINE_EMBED | Set this enable Embed on your uploads | -| ZIPLINE_FORMAT | Output Format after upload. Variables: `{filename}`, `{url}` and `{raw_url}` | -| ZIPLINE_EXPIRE | See: https://zipline.diced.tech/docs/guides/upload-options#image-expiration | +| Variable | Description | +|----------------|---------------------------------------------------------------------------------------------------| +| ZIPLINE_URL | URL to your Zipline Instance | +| ZIPLINE_TOKEN | Authorization Token from Zipline | +| ZIPLINE_EMBED | Set this enable Embed on your uploads | +| ZIPLINE_FORMAT | Output Format after upload. Variables: `{filename}`, `{url}` and `{raw_url}` | +| ZIPLINE_EXPIRE | Zipline: https://zipline.diced.tech/docs/guides/upload-options#image-expiration | +| ZIPLINE_EXPIRE | Django Files: https://github.com/onegreyonewhite/pytimeparse2#pytimeparse2-time-expression-parser | See [.zipline.example](.zipline.example) for an example `.zipline` file. @@ -137,5 +141,3 @@ Still have questions, concerns, or comments? * [Feature Requests](https://github.com/cssnr/zipline-cli/discussions/categories/feature-requests) * [Helpdesk Q&A](https://github.com/cssnr/zipline-cli/discussions/categories/helpdesk-q-a) * [Discord](https://discord.gg/wXy6m2X8wY) - -> Zipline Guide: Hit That Fresh Nar Nar: [youtube.com/watch?v=bJHYo2aGWgE](https://www.youtube.com/watch?v=bJHYo2aGWgE) diff --git a/setup.py b/setup.py index 0468425..d6ea7ea 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ long_description = f.read() setup( - version='0.1.5', + version=os.environ.get('GITHUB_REF_NAME', '0.0.1'), name='zipline-cli', description='Python 3 CLI for Zipline', long_description=long_description, @@ -15,7 +15,7 @@ author_email='shane@sapps.me', py_modules=['zipline'], install_requires=['requests', 'python-decouple', 'python-dotenv'], - python_requires='>=3.6', + python_requires='>=3.8', include_package_data=True, zip_safe=False, platforms='any', diff --git a/zipline.py b/zipline.py index 8f244df..d7b4823 100644 --- a/zipline.py +++ b/zipline.py @@ -77,6 +77,16 @@ def send_file(self, file_name: str, file_object: Union[BinaryIO, TextIO], return ZipURL(r.json()['files'][0]) +def get_mode(file_path: str, blocksize: int = 512) -> str: + try: + with open(file_path, 'rb') as file: + chunk = file.read(blocksize) + chunk.decode('utf-8') + except UnicodeDecodeError: + return 'rb' + return 'r' + + def format_output(filename: str, url: ZipURL) -> str: """ Format URL Output @@ -94,7 +104,7 @@ def gen_rand(length: Optional[int] = 4) -> str: :param length: int: Length of Random String :return: str: Random String """ - length: int = length if not length < 0 else 4 + length: int = length if length >= 0 else 4 return ''.join(random.choice(string.ascii_letters) for _ in range(length)) @@ -198,7 +208,8 @@ def run() -> None: if not os.path.isfile(name): print(f'Warning: File Not Found: {name}') continue - with open(name, 'rb') as f: + mode = get_mode(name) + with open(name, mode) as f: # name, ext = os.path.splitext(os.path.basename(filename)) # ext = f'.{ext}' if ext else '' # name = f'{name}-{gen_rand(8)}{ext}'