Infiziert90/getnative

Output Directory Write Permission error for batches in Windows

Opened this issue · 5 comments

A minor inconvenience but I was hoping to generate a few graphs from different screenshots in a batch without having to move or rename files. The default behavior overwrites previously generated results so I thought I could set the output directory based on input file to separate them. Being able to name the output files would work better.
for %%a in ("*.png") do getnative "%%a" -k bicubic -b 0.33 -c 0.33 -min 400 -max 1200 -ar "16/9" -pf png -dir "E:/Editing/getnative/%%~na"
Gives the error

E:\Editing\getnative>getnative.exe "source" -k bicubic -b 0.33 -c 0.33 -min 400 -max 1200 -ar "16/9" -pf png -dir "E:/Editing/getnative/source"
Using imwri as source filter
Traceback (most recent call last):
File "", line 198, in _run_module_as_main
File "", line 88, in run_code
File "C:\Users\PC\AppData\Local\Programs\Python\Python311\Scripts\getnative.exe_main
.py", line 7, in
File "C:\Users\PC\AppData\Local\Programs\Python\Python311\Lib\site-packages\getnative\app.py", line 410, in main
_getnative()
File "C:\Users\PC\AppData\Local\Programs\Python\Python311\Lib\site-packages\getnative\app.py", line 383, in _getnative
loop.run_until_complete(
File "C:\Users\PC\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "C:\Users\PC\AppData\Local\Programs\Python\Python311\Lib\site-packages\getnative\app.py", line 300, in getnative
raise PermissionError(f"Missing write permissions: {output_dir}")
PermissionError: Missing write permissions: E:\Editing\getnative\source

Adding write permission to the batch file, adding admin privilege to getnative.exe, nor elevating command prompt worked.

Sorry for the late response

Can you use that exact path if you call getnative outside of a batch file?

Error persists in cmd:

E:\Editing\getnative>for %a in ("*jpg") do getnative %a -min 540 -max 1000 -pf png -dir "E:/Editing/getnative/%~na" >test.log

E:\Editing\getnative>getnative test.jpg -min 540 -max 1000 -pf png -dir "E:/Editing/getnative/test"  1>test.log
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\*\AppData\Local\Programs\Python\Python311\Scripts\getnative.exe\__main__.py", line 7, in <module>
  File "C:\Users\*\AppData\Local\Programs\Python\Python311\Lib\site-packages\getnative\app.py", line 410, in main
    _getnative()
  File "C:\Users\*\AppData\Local\Programs\Python\Python311\Lib\site-packages\getnative\app.py", line 383, in _getnative
    loop.run_until_complete(
  File "C:\Users\*\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\Users\*\AppData\Local\Programs\Python\Python311\Lib\site-packages\getnative\app.py", line 300, in getnative
    raise PermissionError(f"Missing write permissions: {output_dir}")
PermissionError: Missing write permissions: E:\Editing\getnative\test

I did work around it by writing a simple loop to rename the output before the next file is processed.

for %%a in ("*.png") do (
getnative.exe "%%a" -k bilinear -min 540 -max 1000 -pf png
getnative.exe "%%a" -min 540 -max 1000 -pf png
getnative.exe "%%a" -k bicubic -b 0 -c 0.5 -min 540 -max 1000 -pf png

cd E:/Editing/getnative/results
ren "f_0_Bilinear_ar_1.78_steps_1.png" "%%~na Bilinear.png"
ren "f_0_Bilinear_ar_1.78_steps_1.txt" "%%~na Bilinear.txt"
ren "f_0_Bicubic_b_0.33_c_0.33_ar_1.78_steps_1.png" "%%~na Mitchell.png"
ren "f_0_Bicubic_b_0.33_c_0.33_ar_1.78_steps_1.txt" "%%~na Mitchell.txt"
ren "f_0_Bicubic_b_0.00_c_0.50_ar_1.78_steps_1.png" "%%~na Catmull.png"
ren "f_0_Bicubic_b_0.00_c_0.50_ar_1.78_steps_1.txt" "%%~na Catmull.txt"
cd E:/Editing/getnative
)

On which loop iteration is this failing? This looks like there might still be a lock on the file from the previous iteration and it's just failing the permissions/access check on that

The first script fails with one iteration. Sorry that was a little confusing. The second script works fine as separately renaming and moving the files doesn't require giving getnative any new write permissions.

getnative/getnative/app.py

Lines 299 to 300 in fd8c737

if not os.access(output_dir, os.W_OK):
raise PermissionError(f"Missing write permissions: {output_dir}")

Can probably simply remove the permission check when it's this fragile and just have it fail later on when trying to actually write files. The error thrown then should be sufficiently accurate.