Commit 40195f0b authored by chris's avatar chris
Browse files

Modified file dump command to update hash upon write and allow targeting

of specific files.
parent 739ed082
VERSION = (0, 1, 10)
VERSION = (0, 1, 11)
__version__ = '.'.join(map(str, VERSION))
\ No newline at end of file
......@@ -6,8 +6,9 @@ from django.core.management.base import BaseCommand, CommandError
from database_files.models import File
class Command(BaseCommand):
args = ''
help = 'Regenerates hashes for all files.'
args = '<filename 1> <filename 2> ... <filename N>'
help = 'Regenerates hashes for files. If no filenames given, ' + \
'rehashes everything.'
option_list = BaseCommand.option_list + (
# make_option('--dryrun',
# action='store_true',
......@@ -22,9 +23,11 @@ class Command(BaseCommand):
settings.DEBUG = False
try:
q = File.objects.all()
if args:
q = q.filter(name__in=args)
total = q.count()
i = 1
for f in q:
for f in q.iterator():
print '%i of %i: %s' % (i, total, f.name)
f._content_hash = None
f.save()
......
......@@ -75,7 +75,7 @@ class File(models.Model):
if verbose:
print 'Checking %i total files...' % (total,)
i = 0
for (file_id, name, content_hash) in q:
for (file_id, name, content_hash) in q.iterator():
i += 1
if verbose and not i % 100:
print '%i of %i' % (i, total)
......@@ -88,6 +88,8 @@ class File(models.Model):
file.name,
file.content,
overwrite=True)
file._content_hash = None
file.save()
finally:
if debug:
settings.DEBUG = tmp_debug
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment