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)) __version__ = '.'.join(map(str, VERSION))
\ No newline at end of file
...@@ -6,8 +6,9 @@ from django.core.management.base import BaseCommand, CommandError ...@@ -6,8 +6,9 @@ from django.core.management.base import BaseCommand, CommandError
from database_files.models import File from database_files.models import File
class Command(BaseCommand): class Command(BaseCommand):
args = '' args = '<filename 1> <filename 2> ... <filename N>'
help = 'Regenerates hashes for all files.' help = 'Regenerates hashes for files. If no filenames given, ' + \
'rehashes everything.'
option_list = BaseCommand.option_list + ( option_list = BaseCommand.option_list + (
# make_option('--dryrun', # make_option('--dryrun',
# action='store_true', # action='store_true',
...@@ -22,9 +23,11 @@ class Command(BaseCommand): ...@@ -22,9 +23,11 @@ class Command(BaseCommand):
settings.DEBUG = False settings.DEBUG = False
try: try:
q = File.objects.all() q = File.objects.all()
if args:
q = q.filter(name__in=args)
total = q.count() total = q.count()
i = 1 i = 1
for f in q: for f in q.iterator():
print '%i of %i: %s' % (i, total, f.name) print '%i of %i: %s' % (i, total, f.name)
f._content_hash = None f._content_hash = None
f.save() f.save()
......
...@@ -75,7 +75,7 @@ class File(models.Model): ...@@ -75,7 +75,7 @@ class File(models.Model):
if verbose: if verbose:
print 'Checking %i total files...' % (total,) print 'Checking %i total files...' % (total,)
i = 0 i = 0
for (file_id, name, content_hash) in q: for (file_id, name, content_hash) in q.iterator():
i += 1 i += 1
if verbose and not i % 100: if verbose and not i % 100:
print '%i of %i' % (i, total) print '%i of %i' % (i, total)
...@@ -88,6 +88,8 @@ class File(models.Model): ...@@ -88,6 +88,8 @@ class File(models.Model):
file.name, file.name,
file.content, file.content,
overwrite=True) overwrite=True)
file._content_hash = None
file.save()
finally: finally:
if debug: if debug:
settings.DEBUG = tmp_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