Skip to content

Commit

Permalink
Add Build
Browse files Browse the repository at this point in the history
  • Loading branch information
smashedr committed Jul 2, 2024
1 parent 3915d82 commit 24bed1f
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 17 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ zipline_cli.*/
*.log
*.pyc
.coverage
.zipline
.zipline*
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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)
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -15,7 +15,7 @@
author_email='[email protected]',
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',
Expand Down
15 changes: 13 additions & 2 deletions zipline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))


Expand Down Expand Up @@ -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}'
Expand Down

0 comments on commit 24bed1f

Please sign in to comment.