yaqwsx / PcbDraw

Convert your KiCAD board into a nicely looking 2D drawing suitable for pinout diagrams
MIT License
1.13k stars 90 forks source link

Permission denied wand.exceptions.BlobError: unable to open image on win32 #83

Closed joric closed 2 years ago

joric commented 2 years ago

On Windows 10 I get the following:

@echo off
call C:\Progra~1\KiCad\6.0\bin\kicad-cmd.bat
cd /d %~dp0
set out=.build
set pcb=nrfmicro.kicad_pcb
mkdir %out% >nul 2>&1

kikit fab jlcpcb --no-assembly --no-drc %pcb% %out%
pcbdraw --dpi 800 --filter "" %pcb% nrfmicro-devel-front.png

************************************
* KiCad 6.0 Command Prompt
************************************
You may now invoke python or pip targeting kicad's install
Traceback (most recent call last):
  File "C:\Program Files\KiCad\6.0\bin\Lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Program Files\KiCad\6.0\bin\Lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\user\Documents\KiCad\6.0\3rdparty\Python39\Scripts\pcbdraw.exe\__main__.py", line 7, in <module>
  File "C:\Users\user\Documents\KiCad\6.0\3rdparty\Python39\site-packages\pcbdraw\pcbdraw.py", line 960, in main
    svg_to_bitmap(tmp_f.name, args.output, dpi=args.dpi)
  File "C:\Users\user\Documents\KiCad\6.0\3rdparty\Python39\site-packages\pcbdraw\pcbdraw.py", line 670, in svg_to_bitmap
    image.read(filename=infile, resolution=dpi)
  File "C:\Users\user\Documents\KiCad\6.0\3rdparty\Python39\site-packages\wand\image.py", line 9815, in read
    self.raise_exception()
  File "C:\Users\user\Documents\KiCad\6.0\3rdparty\Python39\site-packages\wand\resource.py", line 222, in raise_exception
    raise e
wand.exceptions.BlobError: unable to open image 'C:\Users\user\AppData\Local\Temp\tmpb_e3sb2a.svg': Permission denied @ error/blob.c/OpenBlob/3527

Figures this is the issue with temp file on windows.

Patch:

--- ./pcbdraw.orig.py   2022-01-03 02:35:20.298551600 +0500
+++ ./pcbdraw.py    2022-01-03 02:33:43.296554700 +0500
@@ -952,12 +952,14 @@
         document.write(args.output)
         postprocess_svg(args.output, args.shrink)
     else:
-        with tempfile.NamedTemporaryFile(suffix=".svg") as tmp_f:
+        with tempfile.NamedTemporaryFile(suffix=".svg", delete=False) as tmp_f:
             document.write(tmp_f)
             tmp_f.flush()
             postprocess_svg(tmp_f.name, args.shrink)
             tmp_f.flush()
             svg_to_bitmap(tmp_f.name, args.output, dpi=args.dpi)
+            tmp_f.close()
+            os.unlink(tmp_f.name)

 if __name__ == '__main__':
     main()