This commit is contained in:
Allen Short 2012-04-20 17:42:32 -07:00
Родитель 19043a4510
Коммит 3bea929b05
2 изменённых файлов: 2 добавлений и 60 удалений

Просмотреть файл

@ -1,59 +0,0 @@
import os
import sys
from django.core.files.storage import default_storage as storage
from django.core.management.base import BaseCommand
class Command(BaseCommand):
help = """Convert non-png files to png files. One time script,
for bug 731102, based heavily on the one in bug 593267."""
def handle(self, *args, **options):
from django.conf import settings
from amo.utils import resize_image
converted = 0
for path in (settings.COLLECTIONS_ICON_PATH, settings.PREVIEWS_PATH):
if not os.path.isdir(path):
sys.exit("Can't read pics path: %s" % path)
for root, dirs, files in storage.walk(path):
for file in files:
# Aside from 9 files missing extentsions entirely (!)
# everything is jpg or gif or png
if file[-4:] in ('.jpg', '.gif'):
name, _ = os.path.splitext(file)
oldfile = "%s/%s" % (root, file)
newfile = "%s/%s.png" % (root, name)
if storage.exists(newfile):
print "Removing pre-existing file: %s" % (newfile)
storage.delete(newfile)
print "Converting %s to %s" % (oldfile, newfile)
try:
resize_image(oldfile, newfile)
except IOError, e:
print "ERROR: (%s => %s) %s" % (oldfile, newfile, e)
converted += 1
if converted % 100 == 0:
print "Converted %s images..." % converted
elif file.endswith('.png'):
pass
else:
print "Not sure what to do with: %s" % file
# Thumbnails are already all .pngs so no need to adjust them
print """All done. Now you should run this SQL:
UPDATE collections
SET modified=NOW(),
icontype = "image/png" WHERE icontype !='';
UPDATE previews
SET modified=NOW(),
filetype = "image/png" WHERE filetype !='';
"""

Просмотреть файл

@ -5,6 +5,7 @@ from django.conf import settings
from django.core.files.storage import default_storage as storage from django.core.files.storage import default_storage as storage
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from amo.storage_utils import walk_storage
_loc_re = re.compile(r"""\\?(loc)\(.*?\)""", (re.M | re.S)) _loc_re = re.compile(r"""\\?(loc)\(.*?\)""", (re.M | re.S))
_exts = ('.py', '.html') _exts = ('.py', '.html')
@ -21,7 +22,7 @@ class Command(BaseCommand):
""" """
def handle(self, *args, **options): def handle(self, *args, **options):
count = 0 count = 0
for root, folders, files in storage.walk(_root): for root, folders, files in walk_storage(_root):
if not root.startswith(_subs): if not root.startswith(_subs):
continue continue