diff --git a/AveryLabels.py b/AveryLabels.py index fea8374..27c2b3d 100644 --- a/AveryLabels.py +++ b/AveryLabels.py @@ -105,7 +105,8 @@ class AveryLabel: """ render loop""" assert callable(thing) or isinstance(thing, str) if isinstance(count, Iterator): - return self.render_iterator(thing, count) + self.render_iterator(thing, count) + return canv = self.canvas for i in range(offset + count): diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c443dc3 --- /dev/null +++ b/Dockerfile @@ -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 diff --git a/README.md b/README.md index 8efb2c7..bf5e635 100644 --- a/README.md +++ b/README.md @@ -33,12 +33,12 @@ Besides generating ASN labels with a QR Code the tool can also ![Label with highlight bar](docs/label-with-hbar.png) -### Example usage of ASN with colors: +### Example usage of ASN labels with colors: | number ranges | Meaning | Color | | ------------ | --------------------------------------- | ---------- | | 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 | | 300000 | Wife - important | green/red | | 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] 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._ -### Running the program +### Running the program from CLI Depending on your configuration either use `` ./asn-gen.py ... `` @@ -109,6 +110,10 @@ or `` python3 asn-gen.py ... `` +### Running the program from Docker + + + ### Output Filename If the filename is omitted the output defaults to diff --git a/asn-gen.py b/asn-gen.py index 038e484..9a2edd6 100755 --- a/asn-gen.py +++ b/asn-gen.py @@ -2,6 +2,7 @@ from functools import partial +import os from reportlab.lib.units import mm from reportlab.lib.units import toLength @@ -21,6 +22,8 @@ PROJECT_HOMEPAGE = "https://github.com/aborelis/ASN-Label-Generator" class LabelContext: + + """helper class to store context """ # pylint: disable=too-many-instance-attributes @@ -129,6 +132,13 @@ def render(context: LabelContext, c: canvas.Canvas, width: float, height: float) 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( @@ -155,7 +165,7 @@ def generate( # pylint: disable=unused-argument """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 number: number of labels to generate @@ -193,14 +203,11 @@ def generate( parm["labeltype"] = int(parm["labeltype"]) if parm["filename"] is None: - parm["filename"] = ( - "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" - ) + parm["filename"] = gen_filename(parm) + elif not parm["filename"].endswith(".pdf"): + parm["filename"] = os.path.join(parm["filename"], gen_filename(parm)) + + context = LabelContext(parm)