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 DEBUG = False
SAVE = True
### ###
# TEXTURES # TEXTURES
### ###

View File

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