Merge branch 'v2.3' into bugfix/batch-logfile-format

This commit is contained in:
blessedcoolant 2023-03-24 18:10:00 +13:00 committed by GitHub
commit 7377855c02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -30,14 +30,17 @@ class PngWriter:
prefix = self._unused_prefix()
else:
with open(next_prefix_file,'r') as file:
prefix=int(file.readline() or int(self._unused_prefix())-1)
prefix+=1
prefix = 0
try:
prefix=int(file.readline())
except (TypeError, ValueError):
prefix=self._unused_prefix()
with open(next_prefix_file,'w') as file:
file.write(str(prefix))
file.write(str(prefix+1))
return f'{prefix:06}'
# gives the next unique prefix in outdir
def _unused_prefix(self):
def _unused_prefix(self)->int:
# sort reverse alphabetically until we find max+1
dirlist = sorted(os.listdir(self.outdir), reverse=True)
# find the first filename that matches our pattern or return 000000.0.png
@ -45,8 +48,7 @@ class PngWriter:
(f for f in dirlist if re.match('^(\d+)\..*\.png', f)),
'0000000.0.png',
)
basecount = int(existing_name.split('.', 1)[0]) + 1
return f'{basecount:06}'
return int(existing_name.split('.', 1)[0]) + 1
# saves image named _image_ to outdir/name, writing metadata from prompt
# returns full path of output