mirror of
https://github.com/aborelis/ASN-Label-Generator.git
synced 2026-03-14 08:33:28 +00:00
smaller improvements and inital Docker support
This commit is contained in:
parent
b3494b15f6
commit
de48bf919a
4 changed files with 41 additions and 13 deletions
|
|
@ -105,7 +105,8 @@ class AveryLabel:
|
||||||
""" render loop"""
|
""" render loop"""
|
||||||
assert callable(thing) or isinstance(thing, str)
|
assert callable(thing) or isinstance(thing, str)
|
||||||
if isinstance(count, Iterator):
|
if isinstance(count, Iterator):
|
||||||
return self.render_iterator(thing, count)
|
self.render_iterator(thing, count)
|
||||||
|
return
|
||||||
|
|
||||||
canv = self.canvas
|
canv = self.canvas
|
||||||
for i in range(offset + count):
|
for i in range(offset + count):
|
||||||
|
|
|
||||||
15
Dockerfile
Normal file
15
Dockerfile
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
FROM python:3
|
||||||
|
|
||||||
|
WORKDIR /asn-gen
|
||||||
|
|
||||||
|
COPY requirements.txt ./
|
||||||
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
VOLUME ["/out"]
|
||||||
|
|
||||||
|
CMD [ "python", "./asn-gen.py"]
|
||||||
|
|
||||||
|
|
||||||
|
# docker exec -it $(docker run -d --rm debian:unstable bash -c "apt-get update && apt-get upgrade -y && sleep 86400") bash
|
||||||
11
README.md
11
README.md
|
|
@ -33,12 +33,12 @@ Besides generating ASN labels with a QR Code the tool can also
|
||||||

|

|
||||||
|
|
||||||
|
|
||||||
### Example usage of ASN with colors:
|
### Example usage of ASN labels with colors:
|
||||||
|
|
||||||
| number ranges | Meaning | Color |
|
| number ranges | Meaning | Color |
|
||||||
| ------------ | --------------------------------------- | ---------- |
|
| ------------ | --------------------------------------- | ---------- |
|
||||||
| 000000 | Me - normal docs (shorter term storage) | blue |
|
| 000000 | Me - normal docs (shorter term storage) | blue |
|
||||||
| 100000 | Me - imporatant / (long term storage) | blue/red |
|
| 100000 | Me - imporatant (long term storage) | blue/red |
|
||||||
| 200000 | Wife - normal | green |
|
| 200000 | Wife - normal | green |
|
||||||
| 300000 | Wife - important | green/red |
|
| 300000 | Wife - important | green/red |
|
||||||
| 400000 | Child 1 - normal | yellow |
|
| 400000 | Child 1 - normal | yellow |
|
||||||
|
|
@ -62,6 +62,7 @@ Other Avery (or competitor's) label sizes can be added to `labelInfo` in `AveryL
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
$ ./asn-gen.py -h
|
||||||
Usage: asn-gen.py [OPTIONS] [filename]
|
Usage: asn-gen.py [OPTIONS] [filename]
|
||||||
|
|
||||||
ASN Label Generator
|
ASN Label Generator
|
||||||
|
|
@ -100,7 +101,7 @@ _**Recommendation:** do test prints on normal paper before printing to the actua
|
||||||
|
|
||||||
_**Note**: Make sure to set print size to 100%, not fit to page or similar._
|
_**Note**: Make sure to set print size to 100%, not fit to page or similar._
|
||||||
|
|
||||||
### Running the program
|
### Running the program from CLI
|
||||||
Depending on your configuration either use
|
Depending on your configuration either use
|
||||||
|
|
||||||
`` ./asn-gen.py ... ``
|
`` ./asn-gen.py ... ``
|
||||||
|
|
@ -109,6 +110,10 @@ or
|
||||||
|
|
||||||
`` python3 asn-gen.py ... ``
|
`` python3 asn-gen.py ... ``
|
||||||
|
|
||||||
|
### Running the program from Docker
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Output Filename
|
### Output Filename
|
||||||
If the filename is omitted the output defaults to
|
If the filename is omitted the output defaults to
|
||||||
|
|
||||||
|
|
|
||||||
25
asn-gen.py
25
asn-gen.py
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
from reportlab.lib.units import mm
|
from reportlab.lib.units import mm
|
||||||
from reportlab.lib.units import toLength
|
from reportlab.lib.units import toLength
|
||||||
|
|
@ -22,6 +23,8 @@ PROJECT_HOMEPAGE = "https://github.com/aborelis/ASN-Label-Generator"
|
||||||
|
|
||||||
class LabelContext:
|
class LabelContext:
|
||||||
|
|
||||||
|
"""helper class to store context """
|
||||||
|
|
||||||
# pylint: disable=too-many-instance-attributes
|
# pylint: disable=too-many-instance-attributes
|
||||||
|
|
||||||
def __init__(self, data):
|
def __init__(self, data):
|
||||||
|
|
@ -129,6 +132,13 @@ def render(context: LabelContext, c: canvas.Canvas, width: float, height: float)
|
||||||
c.restoreState()
|
c.restoreState()
|
||||||
|
|
||||||
|
|
||||||
|
def gen_filename(parm):
|
||||||
|
"""generates filename from parameters"""
|
||||||
|
return '-'.join(['label',
|
||||||
|
str(parm["labeltype"]), parm["prefix"],
|
||||||
|
str(parm["first_asn"]).zfill(parm["num_digits"]),
|
||||||
|
str(parm["first_asn"] + parm["number"]).zfill(parm["num_digits"])
|
||||||
|
])+'.pdf'
|
||||||
|
|
||||||
|
|
||||||
def generate(
|
def generate(
|
||||||
|
|
@ -155,7 +165,7 @@ def generate(
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
"""ASN Label Generator
|
"""ASN Label Generator
|
||||||
|
|
||||||
:param filename: output filename of PDF file generated
|
:param filename: output filename of PDF file generated, if .pdf extension is missing the string will be used as directory
|
||||||
:param labeltype: Type of label, e.g. 4731, get a list of supported labels with --labels
|
:param labeltype: Type of label, e.g. 4731, get a list of supported labels with --labels
|
||||||
:param number: number of labels to generate
|
:param number: number of labels to generate
|
||||||
|
|
||||||
|
|
@ -193,14 +203,11 @@ def generate(
|
||||||
parm["labeltype"] = int(parm["labeltype"])
|
parm["labeltype"] = int(parm["labeltype"])
|
||||||
|
|
||||||
if parm["filename"] is None:
|
if parm["filename"] is None:
|
||||||
parm["filename"] = (
|
parm["filename"] = gen_filename(parm)
|
||||||
"label-"
|
elif not parm["filename"].endswith(".pdf"):
|
||||||
+ str(parm["labeltype"])+ "-"
|
parm["filename"] = os.path.join(parm["filename"], gen_filename(parm))
|
||||||
+ parm["prefix"]+ "-"
|
|
||||||
+ str(parm["first_asn"]).zfill(parm["num_digits"])+ "-"
|
|
||||||
+ str(parm["first_asn"] + parm["number"]).zfill(parm["num_digits"])
|
|
||||||
+ ".pdf"
|
|
||||||
)
|
|
||||||
|
|
||||||
context = LabelContext(parm)
|
context = LabelContext(parm)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue