modify doDir to import images in sequence if files have numbers in them
This commit is contained in:
parent
7a707b3966
commit
be96f40582
|
@ -1,6 +1,7 @@
|
||||||
from models import *
|
from models import *
|
||||||
from django.core.files import File
|
from django.core.files import File
|
||||||
from glob import glob
|
from glob import glob
|
||||||
|
import re
|
||||||
|
|
||||||
def importFile(filePath, project):
|
def importFile(filePath, project):
|
||||||
f = File(open(filePath))
|
f = File(open(filePath))
|
||||||
|
@ -13,8 +14,11 @@ def importFile(filePath, project):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def doDir(dirpath, project):
|
def doDir(dirpath, project, ext='JPG'):
|
||||||
for f in glob("%s/*" % dirpath):
|
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)
|
importFile(f, project)
|
||||||
print "all done"
|
print "all done"
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue
Block a user