import os
import subprocess
import datetime
time_start = datetime.datetime.now()
print time_start
BASEDIR = "/home/efg/2015/Kaggle/Plankton/"
# DIRWALK = [dirpath, direnames, filenames]
DIRWALK = [fileNameDir for fileNameDir in os.walk(BASEDIR)]
print DIRWALK[2][0]
print DIRWALK[15][0]
for i in [2,15]:
print i, DIRWALK[i][0], len(DIRWALK[i][2])
for j in range(len(DIRWALK[i][2])):
filename = DIRWALK[i][2][j]
if j > 0 and j % 2500 == 0:
print j, filename
basename = os.path.join(DIRWALK[i][0], filename.rsplit(".",2)[0])
# print j, filename
subprocess.check_output(["convert", basename+".jpg", basename+".tif"])
# Use print for debug
# print subprocess.check_output(["convert", basename+".jpg", basename+".tif"])
os.remove(basename+".jpg")
time_stop = datetime.datetime.now()
print time_stop
print (time_stop - time_start), "overall convert time"