modify doDir to import images in sequence if files have numbers in them

This commit is contained in:
Sanj 2012-10-06 16:43:10 +05:30
parent 7a707b3966
commit be96f40582

View File

@ -1,6 +1,7 @@
from models import *
from django.core.files import File
from glob import glob
import re
def importFile(filePath, project):
f = File(open(filePath))
@ -13,8 +14,11 @@ def importFile(filePath, project):
return
def doDir(dirpath, project):
for f in glob("%s/*" % dirpath):
def doDir(dirpath, project, ext='JPG'):
fileList = glob("%s/*.%s" % (dirpath, ext,))
sortedList = sorted(fileList, key=lambda f: int(re.findall(r'\d+', f)[0])) #if there's numbers in the filename, use them as indexes to order by.
print sortedList
for f in sortedList:
importFile(f, project)
print "all done"
return