Added conf.SAVE parameter to select if you want the database involved or not

This commit is contained in:
Felipe Martín 2013-05-27 16:13:53 +02:00
parent 5fa96a08bb
commit 1c27064369
2 changed files with 33 additions and 29 deletions

View File

@ -1,5 +1,7 @@
DEBUG = False
SAVE = True
###
# TEXTURES
###

View File

@ -31,22 +31,23 @@ for path in conf.TEXTURES_PATHS:
# GO!
for f in listdir(path):
if isfile(join(path, f)):
# Copy original image
destiny_path = '../../minecraftcodex/database/static/%s' % join(path, f).\
replace('jarfile/', '')
destiny = open(destiny_path, 'w+')
destiny.write(open(join(path, f)).read())
destiny.close()
# making more sizes for the site
try:
modified = Image.open(destiny_path)
for multiplier in conf.TEXTURES_EXTRA_SIZES_MULTIPLIER:
sizes = (modified.size[0] * multiplier, modified.size[1] * multiplier)
modified_path = destiny_path.replace('.png', '_x%d.png' % multiplier)
resized = modified.resize(sizes, Image.NEAREST)
resized.save(modified_path, 'PNG')
except IOError:
pass
if conf.SAVE:
# Copy original image
destiny_path = '../../minecraftcodex/database/static/%s' % join(path, f).\
replace('jarfile/', '')
destiny = open(destiny_path, 'w+')
destiny.write(open(join(path, f)).read())
destiny.close()
# making more sizes for the site
try:
modified = Image.open(destiny_path)
for multiplier in conf.TEXTURES_EXTRA_SIZES_MULTIPLIER:
sizes = (modified.size[0] * multiplier, modified.size[1] * multiplier)
modified_path = destiny_path.replace('.png', '_x%d.png' % multiplier)
resized = modified.resize(sizes, Image.NEAREST)
resized.save(modified_path, 'PNG')
except IOError:
pass
TEXTURES.append(
GameTexture(
@ -56,19 +57,20 @@ for path in conf.TEXTURES_PATHS:
)
)
for texture in TEXTURES:
try:
item = Texture.objects.get(
name=texture.name,
type=texture.type
)
except Texture.DoesNotExist:
item = Texture(
name=texture.name,
type=texture.type,
image=texture.path
)
item.save()
if conf.SAVE:
for texture in TEXTURES:
try:
item = Texture.objects.get(
name=texture.name,
type=texture.type
)
except Texture.DoesNotExist:
item = Texture(
name=texture.name,
type=texture.type,
image=texture.path
)
item.save()
print(' => Summary')
new_old_data = {}