Skip to content

Commit

Permalink
better output name generation
Browse files Browse the repository at this point in the history
  • Loading branch information
eaydin committed May 21, 2017
1 parent da9206b commit 12b09d7
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion cr2fits/cr2fits.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import re
import datetime
from netpbmfile import NetpbmFile
import os.path
from io import BytesIO

except Exception as err:
Expand Down Expand Up @@ -199,7 +200,18 @@ def _generate_destination(self, filename, colorindex):
channel_name = "RAW"
else:
channel_name = self.colors[colorindex][0]
return filename.split('.')[0] + "-" + channel_name + ".fits"

filename = "".join(filename.split('.')[:-1])

writename = filename + "-" + channel_name + ".fits"
if os.path.isfile(writename):
for i in range(1, 9000000):
# Crashes after 9million files with same name but what the hell
writename = "{fn}-{ch}-{i}.fits".format(fn=filename,
ch=channel_name, i=i)
if not os.path.isfile(writename):
break
return writename

def write_fits(self, hdu, destination):
"""
Expand Down

0 comments on commit 12b09d7

Please sign in to comment.