mirror of
https://github.com/entropia/paperless-asn-qr-codes.git
synced 2024-06-02 23:10:02 +00:00
Compare commits
7 commits
5793e43629
...
4d7c9d57bf
Author | SHA1 | Date | |
---|---|---|---|
4d7c9d57bf | |||
c6a82af9d9 | |||
278046ae90 | |||
279a3ee0ea | |||
267c5c7011 | |||
14cd97e1e2 | |||
d95dea4196 |
87
.github/workflows/publish.yaml
vendored
Normal file
87
.github/workflows/publish.yaml
vendored
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI
|
||||||
|
# based on https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows
|
||||||
|
|
||||||
|
on: push
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: Build distribution 📦
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0 # fetch all history for tags, allowing to build proper dev version
|
||||||
|
- run: pipx install hatch
|
||||||
|
- run: hatch build
|
||||||
|
- name: Store the distribution packages
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: python-package-distributions
|
||||||
|
path: dist/
|
||||||
|
|
||||||
|
publish-to-pypi:
|
||||||
|
name: >-
|
||||||
|
Publish Python 🐍 distribution 📦 to PyPI
|
||||||
|
if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main' # only publish to PyPI on tag pushes or dev version for main
|
||||||
|
needs:
|
||||||
|
- build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
environment:
|
||||||
|
name: pypi
|
||||||
|
url: https://pypi.org/p/paperless-asn-qr-codes
|
||||||
|
permissions:
|
||||||
|
id-token: write # IMPORTANT: mandatory for trusted publishing
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Download all the dists
|
||||||
|
uses: actions/download-artifact@v3
|
||||||
|
with:
|
||||||
|
name: python-package-distributions
|
||||||
|
path: dist/
|
||||||
|
- name: Publish distribution 📦 to PyPI
|
||||||
|
uses: pypa/gh-action-pypi-publish@release/v1
|
||||||
|
|
||||||
|
github-release:
|
||||||
|
name: >-
|
||||||
|
Sign the Python 🐍 distribution 📦 with Sigstore
|
||||||
|
and upload them to GitHub Release
|
||||||
|
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
|
||||||
|
needs:
|
||||||
|
- publish-to-pypi
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write # IMPORTANT: mandatory for making GitHub Releases
|
||||||
|
id-token: write # IMPORTANT: mandatory for sigstore
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Download all the dists
|
||||||
|
uses: actions/download-artifact@v3
|
||||||
|
with:
|
||||||
|
name: python-package-distributions
|
||||||
|
path: dist/
|
||||||
|
- name: Sign the dists with Sigstore
|
||||||
|
uses: sigstore/gh-action-sigstore-python@v1.2.3
|
||||||
|
with:
|
||||||
|
inputs: >-
|
||||||
|
./dist/*.tar.gz
|
||||||
|
./dist/*.whl
|
||||||
|
- name: Create GitHub Release
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ github.token }}
|
||||||
|
run: >-
|
||||||
|
gh release create
|
||||||
|
'${{ github.ref_name }}'
|
||||||
|
--repo '${{ github.repository }}'
|
||||||
|
--notes ""
|
||||||
|
- name: Upload artifact signatures to GitHub Release
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ github.token }}
|
||||||
|
# Upload to GitHub Release using the `gh` CLI.
|
||||||
|
# `dist/` contains the built packages, and the
|
||||||
|
# sigstore-produced signatures and certificates.
|
||||||
|
run: >-
|
||||||
|
gh release upload
|
||||||
|
'${{ github.ref_name }}' dist/**
|
||||||
|
--repo '${{ github.repository }}'
|
44
README.md
44
README.md
|
@ -1,7 +1,7 @@
|
||||||
# paperless-asn-qr-codes
|
# paperless-asn-qr-codes
|
||||||
|
|
||||||
`paperless-asn-qr-codes` is a command line utility for generating ASN labels
|
`paperless-asn-qr-codes` is a command line utility for generating ASN labels
|
||||||
for paperless with both a human readable representation, as well as a QR code
|
for paperless with both a human-readable representation, as well as a QR code
|
||||||
for machine consumption. The labels are Avery 4731 labels.
|
for machine consumption. The labels are Avery 4731 labels.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
@ -10,10 +10,44 @@ for machine consumption. The labels are Avery 4731 labels.
|
||||||
pip install paperless-asn-qr-codes
|
pip install paperless-asn-qr-codes
|
||||||
```
|
```
|
||||||
|
|
||||||
## Supported Sheets
|
## Usage
|
||||||
Some different sheet types are supported with the `--format` argument, however, not all are tested.
|
|
||||||
|
|
||||||
Default is Avery L4731.
|
```
|
||||||
|
usage: paperless-asn-qr-codes [-h] [--format {averyL4731,avery5160,avery5161,avery5163,avery5167,avery5371}] [--border] start_asn output_file
|
||||||
|
|
||||||
|
CLI Tool for generating paperless ASN labels with QR codes
|
||||||
|
|
||||||
|
positional arguments:
|
||||||
|
start_asn The value of the first ASN
|
||||||
|
output_file The output file to write to (default: labels.pdf)
|
||||||
|
|
||||||
|
options:
|
||||||
|
-h, --help show this help message and exit
|
||||||
|
--format {averyL4731,avery5160,avery5161,avery5163,avery5167,avery5371}, -f {averyL4731,avery5160,avery5161,avery5163,avery5167,avery5371}
|
||||||
|
--digits DIGITS, -d DIGITS
|
||||||
|
Number of digits in the ASN (default: 7, produces 'ASN0000001')
|
||||||
|
--border, -b Display borders around labels, useful for debugging the printer alignment
|
||||||
|
```
|
||||||
|
|
||||||
|
### Mandatory arguments
|
||||||
|
|
||||||
|
- `<start_asn>`: The value of the first ASN to generate
|
||||||
|
|
||||||
|
### Optional arguments
|
||||||
|
|
||||||
|
- `<output_file>`: The name of the output file to write to (default: labels.pdf)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
- `-h`, `--help`: Shows the help message
|
||||||
|
- `-f`, `--format`: Selects the format of the output sheet (see [Supported Sheets](#supported-sheets))
|
||||||
|
- `-d`, `--digits`: Specifies the number of digits in the ASN (e.g. for the default number 7, the ASN will look like 'ASN0000001')
|
||||||
|
- `-b`, `--border`: Generates the borders around the labels to help debug alignment issues (see [Tips & Tricks](#tips--tricks))
|
||||||
|
|
||||||
|
## Supported Sheets
|
||||||
|
Some different sheet types are supported with the `-f`/`--format` argument, however, not all are tested.
|
||||||
|
|
||||||
|
The default is Avery L4731.
|
||||||
|
|
||||||
Currently tested and known working are:
|
Currently tested and known working are:
|
||||||
- Avery L4731 (DIN A4 Labels)
|
- Avery L4731 (DIN A4 Labels)
|
||||||
|
@ -21,7 +55,7 @@ Currently tested and known working are:
|
||||||
## Tips & Tricks
|
## Tips & Tricks
|
||||||
|
|
||||||
In case your printer has alignment issues, you can generate a PDF with borders around the labels by using the
|
In case your printer has alignment issues, you can generate a PDF with borders around the labels by using the
|
||||||
`--border` option.
|
`-b`/`--border` option.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,8 @@ from dataclasses import dataclass, KW_ONLY
|
||||||
from collections.abc import Iterator
|
from collections.abc import Iterator
|
||||||
from reportlab.pdfgen import canvas
|
from reportlab.pdfgen import canvas
|
||||||
from reportlab.lib.pagesizes import LETTER, A4
|
from reportlab.lib.pagesizes import LETTER, A4
|
||||||
from reportlab.lib.units import mm
|
from reportlab.lib.units import mm, inch
|
||||||
|
|
||||||
|
|
||||||
# Usage:
|
# Usage:
|
||||||
# label = AveryLabels.AveryLabel(5160)
|
# label = AveryLabels.AveryLabel(5160)
|
||||||
|
@ -67,9 +68,9 @@ labelInfo: dict[str, LabelInfo] = {
|
||||||
"avery5167": LabelInfo(
|
"avery5167": LabelInfo(
|
||||||
labels_horizontal=4,
|
labels_horizontal=4,
|
||||||
labels_vertical=20,
|
labels_vertical=20,
|
||||||
label_size=(126, 36),
|
label_size=(1.75 * inch, 0.5 * inch),
|
||||||
gutter_size=(0, 0),
|
gutter_size=(0.3 * inch, 0),
|
||||||
margin=(54, 36),
|
margin=(0.3 * inch, 0.5 * inch),
|
||||||
pagesize=LETTER,
|
pagesize=LETTER,
|
||||||
),
|
),
|
||||||
# 3.5 x 2 business cards
|
# 3.5 x 2 business cards
|
||||||
|
|
|
@ -2,12 +2,14 @@ import argparse
|
||||||
|
|
||||||
from reportlab.lib.units import mm
|
from reportlab.lib.units import mm
|
||||||
from reportlab_qrcode import QRCodeImage
|
from reportlab_qrcode import QRCodeImage
|
||||||
|
|
||||||
from paperless_asn_qr_codes import avery_labels
|
from paperless_asn_qr_codes import avery_labels
|
||||||
|
|
||||||
|
|
||||||
def render(c, x, y):
|
def render(c, x, y):
|
||||||
global startASN
|
global startASN
|
||||||
barcode_value = f"ASN{startASN:07d}"
|
global digits
|
||||||
|
barcode_value = f"ASN{startASN:0{digits}d}"
|
||||||
startASN = startASN + 1
|
startASN = startASN + 1
|
||||||
|
|
||||||
qr = QRCodeImage(barcode_value, size=y * 0.9)
|
qr = QRCodeImage(barcode_value, size=y * 0.9)
|
||||||
|
@ -21,19 +23,25 @@ def main():
|
||||||
prog="paperless-asn-qr-codes",
|
prog="paperless-asn-qr-codes",
|
||||||
description="CLI Tool for generating paperless ASN labels with QR codes",
|
description="CLI Tool for generating paperless ASN labels with QR codes",
|
||||||
)
|
)
|
||||||
parser.add_argument("start_asn")
|
parser.add_argument("start_asn", type=int, help="The value of the first ASN")
|
||||||
parser.add_argument("output_file")
|
parser.add_argument("output_file", type=str, default="labels.pdf", help="The output file to write to (default: labels.pdf)")
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--format", choices=avery_labels.labelInfo.keys(), default="averyL4731"
|
"--format", "-f", choices=avery_labels.labelInfo.keys(), default="averyL4731"
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--digits", "-d", default=7, help="Number of digits in the ASN (default: 7, produces 'ASN0000001')", type=int
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--border",
|
"--border",
|
||||||
|
"-b",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help="Display borders around labels, useful for debugging the printer alignment",
|
help="Display borders around labels, useful for debugging the printer alignment",
|
||||||
)
|
)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
global startASN
|
global startASN
|
||||||
|
global digits
|
||||||
startASN = int(args.start_asn)
|
startASN = int(args.start_asn)
|
||||||
|
digits = int(args.digits)
|
||||||
label = avery_labels.AveryLabel(args.format, args.border)
|
label = avery_labels.AveryLabel(args.format, args.border)
|
||||||
label.open(args.output_file)
|
label.open(args.output_file)
|
||||||
# by default, we render all labels possible on a single sheet
|
# by default, we render all labels possible on a single sheet
|
||||||
|
|
|
@ -11,6 +11,7 @@ license = "GPL-3.0"
|
||||||
keywords = []
|
keywords = []
|
||||||
authors = [
|
authors = [
|
||||||
{ name = "Jan Christian Grünhage", email = "jan.christian@gruenhage.xyz" },
|
{ name = "Jan Christian Grünhage", email = "jan.christian@gruenhage.xyz" },
|
||||||
|
{ name = "margau", email = "dev@marvingaube.de" },
|
||||||
]
|
]
|
||||||
classifiers = [
|
classifiers = [
|
||||||
"Development Status :: 4 - Beta",
|
"Development Status :: 4 - Beta",
|
||||||
|
|
Loading…
Reference in a new issue