flinventory 0.6.1__py3-none-any.whl → 0.6.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
flinventory/constant.py CHANGED
@@ -283,3 +283,17 @@ def fix_deprecated_language_keys(
283
283
  )
284
284
  # else: new_key not in data
285
285
  data[new_key] = {language: data[key]}
286
+
287
+
288
+ class MissingProgramError(OSError):
289
+ """Error raised if an external program is called that does not exist."""
290
+
291
+ def __init__(self, program_name: str, *args):
292
+ """Create a MissingProgramError.
293
+
294
+ Args:
295
+ program_name: the name of the missing program
296
+ see OSError
297
+ """
298
+ super().__init__(*args)
299
+ self.program_name = program_name
@@ -13,6 +13,7 @@ from typing import Union, Iterable, Optional
13
13
 
14
14
  from .box import BoxedThing
15
15
  from .sign import Sign
16
+ import constant
16
17
 
17
18
  from . import thingtemplate_latex
18
19
 
@@ -23,6 +24,14 @@ TEMPLATE_POST = "signlist-footer.tex"
23
24
  TEMPLATE_SIGN = "sign.tex"
24
25
  DUMMY_IMAGE = "dummyImage.jpg"
25
26
  AUX_DIR = "latexAux"
27
+ LATEXMK_OPTIONS = [
28
+ "latexmk",
29
+ f"-aux-directory={AUX_DIR}",
30
+ "-pdf",
31
+ "-interaction=nonstopmode",
32
+ "-f",
33
+ ]
34
+ # only the tex file needs to be added to the list
26
35
 
27
36
  UNIT = "cm" # todo: replace by length_unit in options, includes scaling the constants
28
37
  # estimated by one example word
@@ -478,14 +487,30 @@ class SignPrinterLaTeX:
478
487
  return file_signs
479
488
 
480
489
  def create_signs_pdf(self, things: list[BoxedThing]):
481
- """Create a pdf and latex files with signs."""
490
+ """Create a pdf and latex files with signs.
491
+
492
+ Raises:
493
+ ProgramMissingError: if no latexmk is available
494
+ """
482
495
  self.save_signs_latex(things)
483
- latex = subprocess.run(
484
- ["latexmk", self.signs_file, f"-aux-directory={AUX_DIR}", "-pdf"],
485
- cwd=self.output_dir,
486
- capture_output=True,
487
- text=True,
488
- ) # text=True makes output a str instead of bytes
496
+ try:
497
+ latex = subprocess.run(
498
+ LATEXMK_OPTIONS + [self.signs_file],
499
+ cwd=self.output_dir,
500
+ capture_output=True,
501
+ text=True,
502
+ ) # text=True makes output a str instead of bytes
503
+ except FileNotFoundError as program_missing:
504
+ if program_missing.filename == LATEXMK_OPTIONS[0]:
505
+ raise constant.MissingProgramError(
506
+ LATEXMK_OPTIONS[0],
507
+ program_missing.errno,
508
+ f"Program {LATEXMK_OPTIONS[0]} missing.",
509
+ program_missing.filename,
510
+ program_missing.winerror,
511
+ ) from program_missing
512
+ else:
513
+ raise program_missing
489
514
  with open(
490
515
  os.path.join(self.output_dir, AUX_DIR, "latex_output.txt"), mode="w"
491
516
  ) as stdout_file:
@@ -507,6 +532,8 @@ class SignPrinterLaTeX:
507
532
  thing: the thing which sign should be created
508
533
  Returns:
509
534
  path of the created svg file. None if error
535
+ Raises:
536
+ ProgramMissingError: if latexmk or pdf2svg is not available
510
537
  """
511
538
  tex = self.create_latex_single_sign(thing)
512
539
  tex_hash = str(abs(hash(tex)))
@@ -521,12 +548,24 @@ class SignPrinterLaTeX:
521
548
  return file_svg
522
549
  with open(path_tex, mode="w") as file_tex_f:
523
550
  file_tex_f.write(tex)
524
- latex = subprocess.run(
525
- ["latexmk", file_tex, f"-aux-directory={AUX_DIR}", "-pdf"],
526
- cwd=self.output_dir,
527
- capture_output=True,
528
- text=True,
529
- ) # text=True makes output a str instead of bytes
551
+ try:
552
+ latex = subprocess.run(
553
+ LATEXMK_OPTIONS + [file_tex],
554
+ cwd=self.output_dir,
555
+ capture_output=True,
556
+ text=True,
557
+ ) # text=True makes output a str instead of bytes
558
+ except FileNotFoundError as program_missing:
559
+ if program_missing.filename == LATEXMK_OPTIONS[0]:
560
+ raise constant.MissingProgramError(
561
+ LATEXMK_OPTIONS[0],
562
+ program_missing.errno,
563
+ f"Program {LATEXMK_OPTIONS[0]} missing.",
564
+ program_missing.filename,
565
+ program_missing.winerror,
566
+ ) from program_missing
567
+ else:
568
+ raise program_missing
530
569
  with open(
531
570
  os.path.join(self.output_dir, AUX_DIR, f"latex_output_{tex_hash}.txt"),
532
571
  mode="w",
@@ -546,11 +585,23 @@ class SignPrinterLaTeX:
546
585
  self.logger.error(error_message)
547
586
  print(error_message)
548
587
  return None
549
- svg = subprocess.run(
550
- ["pdf2svg", path_pdf, path_svg],
551
- capture_output=True,
552
- text=True,
553
- ) # text=True makes output a str instead of bytes
588
+ try:
589
+ svg = subprocess.run(
590
+ ["pdf2svg", path_pdf, path_svg],
591
+ capture_output=True,
592
+ text=True,
593
+ ) # text=True makes output a str instead of bytes
594
+ except FileNotFoundError as program_missing:
595
+ if program_missing.filename == "pdf2svg":
596
+ raise constant.MissingProgramError(
597
+ "pdf2svg",
598
+ program_missing.errno,
599
+ "Program pdf2svg missing.",
600
+ program_missing.filename,
601
+ program_missing.winerror,
602
+ ) from program_missing
603
+ else:
604
+ raise program_missing
554
605
  with open(
555
606
  os.path.join(self.output_dir, AUX_DIR, f"svg_output_{tex_hash}.txt"),
556
607
  mode="w",
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: flinventory
3
- Version: 0.6.1
3
+ Version: 0.6.3
4
4
  Summary: An inventory system for self-help repair shops
5
5
  Author-Email: flukx <flinventory-flukx@612211124.xyz>
6
6
  License: GPL3
@@ -1,18 +1,18 @@
1
- flinventory-0.6.1.dist-info/METADATA,sha256=o8gLB774_aSvpZRmX5VwJ4XcVRCmm-hzQbGKaEQDPmk,4907
2
- flinventory-0.6.1.dist-info/WHEEL,sha256=tSfRZzRHthuv7vxpI4aehrdN9scLjk-dCJkPLzkHxGg,90
3
- flinventory-0.6.1.dist-info/entry_points.txt,sha256=De3jjbHfy68_ZrwdjywlgrSUCn4QhqZGI0CJJt9S8_c,78
4
- flinventory-0.6.1.dist-info/licenses/LICENSE,sha256=9c-AWlAEeFMmn1aODEfabsw2he-SpQeykurYw-KqSdw,34478
1
+ flinventory-0.6.3.dist-info/METADATA,sha256=nOBNNUxpd1398oquOYvcKheoGbu00MQ4-0h6B4--NU0,4907
2
+ flinventory-0.6.3.dist-info/WHEEL,sha256=tSfRZzRHthuv7vxpI4aehrdN9scLjk-dCJkPLzkHxGg,90
3
+ flinventory-0.6.3.dist-info/entry_points.txt,sha256=De3jjbHfy68_ZrwdjywlgrSUCn4QhqZGI0CJJt9S8_c,78
4
+ flinventory-0.6.3.dist-info/licenses/LICENSE,sha256=9c-AWlAEeFMmn1aODEfabsw2he-SpQeykurYw-KqSdw,34478
5
5
  flinventory/__init__.py,sha256=0HTGxw9J-2KnbxQbzX6HH-Pztkp0BEjiHANhndfbtYM,270
6
6
  flinventory/__main__.py,sha256=5U_RxWDlnhzlC98RaE8SkejjiYjv27OLdm5DPYgL4Gw,1295
7
7
  flinventory/box.py,sha256=rk7yrAjVdxcrpvmTMt3jkMVOAoQNJfqoSig9U2S3yJ0,10480
8
- flinventory/constant.py,sha256=pPNCwScLon_MOKL9_jjD_sxqB7Q2WW6rZqtrBl7SyWk,10283
8
+ flinventory/constant.py,sha256=4qb7gX-pQdr7fGq25dTkESe6B53yi4yILOF4Y8KtWk0,10672
9
9
  flinventory/datacleanup.py,sha256=_CImmWJhq5uKz21jJQUqKYoQfbHEYA0000RyPRt5BI0,11363
10
10
  flinventory/defaulted_data.py,sha256=KAy6V2KLcifLg7zHBFnx_eFLp31sCWih1Btp6cE0bQc,21585
11
11
  flinventory/generate_labels.py,sha256=wjlyta9gowWOLvVfOVUQ8Ktpv3eg85JbAfDzI4Ok2V4,8476
12
12
  flinventory/inventory_io.py,sha256=OWThcf9nzeZNqvNpzQiBhESQAnVXC7hUA8DEVzq-w-Y,12561
13
13
  flinventory/location.py,sha256=UgJlbno16ipuFa4yUZK3SLrid70ACwE5He9Dd4P2SMU,16875
14
14
  flinventory/sign.py,sha256=8G7fsne3Nsf8zZKKTUl40uWMNsWIv7FYV2KcqBR2MQI,5515
15
- flinventory/signprinter_latex.py,sha256=mPu7C1AxOW3-qdA0XFkAhk9w5Z32nnRcZPD38kaqYDU,22940
15
+ flinventory/signprinter_latex.py,sha256=3-5fUKYT4uzR8lEIsfMg4meJMgP_oiHQmqAzrNN7dgs,24819
16
16
  flinventory/thing.py,sha256=86fXj3RwTbkCdVVWrbyO-VEW_e5lKJlV8PPt1Xf8ejY,5079
17
17
  flinventory/thingtemplate_latex/.gitignore,sha256=DTF250Ttj8O2lxrQBwMNrQ73rWPvdwCytipfZSLFtlU,51
18
18
  flinventory/thingtemplate_latex/dummyImage.jpg,sha256=bIBH5Lrxlr5qJ42nP1cpJXPRNGLOwyEuzwXFSvNwTSk,147857
@@ -20,4 +20,4 @@ flinventory/thingtemplate_latex/sign.tex,sha256=cVlOjImuS97Gf19MGW27HiP6Uw8JNnob
20
20
  flinventory/thingtemplate_latex/signlist-footer.tex,sha256=LcZw5__h8SqgMmYxs5oLbXLaFTQlx_X5rtYnpxwUh9Y,14
21
21
  flinventory/thingtemplate_latex/signlist-header.tex,sha256=F1J4aSPq6QO_Ved4Zn7-rytP1vDkdWTqjjtGJpe_FDg,297
22
22
  flinventory/thingtemplate_latex/signs-example.tex,sha256=J6eCcPhP0Xklgn8xnSenDOvjzmc_NGmakWU4RGbeUtM,3090
23
- flinventory-0.6.1.dist-info/RECORD,,
23
+ flinventory-0.6.3.dist-info/RECORD,,