Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
fdw-forks
django-database-files
Commits
7a3c5a9e
Commit
7a3c5a9e
authored
Aug 21, 2012
by
chris
Browse files
Fixing hashing functions to be consistent in Python2.6. Added management
command to regenerate hashes.
parent
8d21c83a
Changes
5
Hide whitespace changes
Inline
Side-by-side
database_files/__init__.py
View file @
7a3c5a9e
VERSION
=
(
0
,
1
,
7
)
VERSION
=
(
0
,
1
,
8
)
__version__
=
'.'
.
join
(
map
(
str
,
VERSION
))
\ No newline at end of file
database_files/management/commands/database_files_rehash.py
0 → 100644
View file @
7a3c5a9e
from
optparse
import
make_option
from
django.conf
import
settings
from
django.core.management.base
import
BaseCommand
,
CommandError
from
database_files.models
import
File
class
Command
(
BaseCommand
):
args
=
''
help
=
'Regenerates hashes for all files.'
option_list
=
BaseCommand
.
option_list
+
(
# make_option('--dryrun',
# action='store_true',
# dest='dryrun',
# default=False,
# help='If given, only displays the names of orphaned files ' + \
# 'and does not delete them.'),
)
def
handle
(
self
,
*
args
,
**
options
):
tmp_debug
=
settings
.
DEBUG
settings
.
DEBUG
=
False
dryrun
=
options
[
'dryrun'
]
try
:
q
=
File
.
objects
.
all
()
total
=
q
.
count
()
i
=
1
for
f
in
q
:
print
'%i of %i: %s'
%
(
i
,
total
,
f
.
name
)
f
.
_content_hash
=
None
f
.
save
()
i
+=
1
finally
:
settings
.
DEBUG
=
tmp_debug
database_files/tests/tests.py
View file @
7a3c5a9e
# -*- coding: utf-8 -*-
import
os
import
StringIO
...
...
@@ -74,16 +75,44 @@ class DatabaseFilesTestCase(TestCase):
self
.
assertEqual
(
os
.
path
.
isfile
(
fqfn
),
False
)
def
test_hash
(
self
):
media_dir
=
os
.
path
.
join
(
DIR
,
'media/i/special'
)
# Create test file.
media_dir
=
os
.
path
.
join
(
DIR
,
'media/i/special'
)
if
not
os
.
path
.
isdir
(
media_dir
):
os
.
makedirs
(
media_dir
)
fqfn
=
os
.
path
.
join
(
media_dir
,
'test.txt'
)
open
(
fqfn
,
'wb'
).
write
(
'hello
\n
many things are here
\n
and then this'
)
f_hash
=
utils
.
get_file_hash
(
fqfn
)
t_hash
=
utils
.
get_text_hash
(
open
(
fqfn
,
'rb'
).
read
())
print
f_hash
print
t_hash
self
.
assertEqual
(
f_hash
,
t_hash
)
image_content
=
'
\x89
PNG
\r\n\x1a\n\x00\x00\x00\r
IHDR
\x00\x00\x00
2
\x00\x00\x00
9
\x08\x06\x00\x00\x00
t
\xf8
xr
\x00\x00\x00\x01
sRGB
\x00\xae\xce\x1c\xe9\x00\x00\x00\x06
bKGD
\x00\xff\x00\xff\x00\xff\xa0\xbd\xa7\x93\x00\x00\x00\t
pHYs
\x00\x00\x1e\xc2\x00\x00\x1e\xc2\x01
n
\xd0
u>
\x00\x00\x00\x07
tIME
\x07\xdc\x08\x15\r
0
\x02\xc7\x0f
^
\x14\x00\x00\x0e
NIDATh
\xde\xd5\x9a
ytTU
\x9e\xc7
?
\xf7\xbd
WkRd
\x0f\x01\x12\x02
!
\xc8\x12
0,
\r
6
\xb2
#
\x10\xa2
(
\xee
K
\xdb
:n
\xd3\xca\xd0\xb4
6
\x8b\xf6\xc0
9=
\xd3
v
\xdb\xa7\x91\xb8\xb5
L
\xab\xe3\xb8\xb5\x8c\xbd\x88\x83\xda
-
\x84\xc4\xb8
4
\x13\x10
F
\x01\r\xb2
%
\x01
C
\t
Y
\x8a
$UIj{
\xef\xce\x1f\xaf\xaa\x92\x90\x80
@
\xc0\xa6\xef
9uRU
\xa9\xba\xf7\xf7\xbd\xdf\xdf\xfe
+
\xb8
Xk
\xc1\x8a
D
\xe6
/K
\x03
\x7f
%
\x17
{)
\x17
kcUU/s%
\xa6\xbc
e[
\xf8
h6
\x9b\xd7
B
\xfe\x8a\x7f
L
\xe9
)I
\t\xd3\'
O
\x9c
-
\xe2\x07\xfc\x89\x9c\xd9
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f6
w
\xe1\xc1
,l
\xe9\xcb
/
\x1f\xba\xb1\xd3\x85\xd2\xf9\xcb\xe6
a
\x8f
y
\x00\x8b
c
\x06\x8a\x9a\x86\xaa
u
\x02\xea\xda\x97\x95\x12\x02
!
\x90\x92
!
\xe9
I
\x0c
K
\x8d\'\xc6
n&
\x9e\x1d\x81\xa0
lm
\x0f\x88\x1a
o
\x90\xea\x9a\x16\xd3\xb8
m
\xf6
]
\xb4
T
\x7f\xc0
7
\xbb\x9f\xe5\xcb\xbf\xb8\xcf\xa4
J
\xe7\x0f\x04\xe8\xe6\xf2
.
\x9b\xa9
0db.
\xf6\x98\x19\x08\xe5\x1a
Tm
\x0e\x8a
EE
\xb3
t
\x8f
;]
\xca\x80
hW]
\xb3\x85\xdf\x0b\x81
4
\xaa\x11\xca\x16\x8c\xc0
fj
\x0e
l
\xa7\xf4\xf5\xda\x1e
g
\x9d\xd5\x80\xf1
|
\xd6\xfc
eP
\xf4\xb4\xf9
|
\xd6\x83\x02\xab\xd3\x81\xd5\x11\x83\x94\x93\x90\xc6
,T
\xcb
8
\x14
5
\x1b
EI
\x02\xe1
D
\x08\x15
)C
\x08\xc5\x83
P
\xeb\x08
u
\xec
#
\x14\xdc\x89\xc5\xbe\x05\xa8\xa2\xb9\xa6\x83
O^
\n\xf4\xa5
D
\xf8\x7f
M
\xdd
#
\x1d\xf5
i
\xe0
U
\x00\x00\x00\x00
IEND
\xae
B`
\x82
'
fqfn
=
os
.
path
.
join
(
media_dir
,
'image.png'
)
open
(
fqfn
,
'wb'
).
write
(
image_content
)
hashes
=
set
()
h
=
utils
.
get_text_hash
(
image_content
)
hashes
.
add
(
h
);
print
h
h
=
utils
.
get_file_hash
(
fqfn
)
hashes
.
add
(
h
);
print
h
h
=
utils
.
get_text_hash
(
open
(
fqfn
,
'rb'
).
read
())
hashes
.
add
(
h
);
print
h
h
=
utils
.
get_text_hash
(
open
(
fqfn
,
'r'
).
read
())
hashes
.
add
(
h
);
print
h
print
'Hashes:'
,
len
(
hashes
)
# Create test file.
self
.
assertEqual
(
len
(
hashes
),
1
)
image_content
=
u
'aあä'
fqfn
=
os
.
path
.
join
(
media_dir
,
'test.txt'
)
open
(
fqfn
,
'wb'
).
write
(
image_content
.
encode
(
'utf-8'
))
hashes
=
set
()
h
=
utils
.
get_text_hash
(
image_content
)
hashes
.
add
(
h
);
print
h
h
=
utils
.
get_file_hash
(
fqfn
)
hashes
.
add
(
h
);
print
h
h
=
utils
.
get_text_hash
(
open
(
fqfn
,
'rb'
).
read
())
hashes
.
add
(
h
);
print
h
h
=
utils
.
get_text_hash
(
open
(
fqfn
,
'r'
).
read
())
hashes
.
add
(
h
);
print
h
print
'Hashes:'
,
len
(
hashes
)
self
.
assertEqual
(
len
(
hashes
),
1
)
class
DatabaseFilesViewTestCase
(
TestCase
):
fixtures
=
[
'test_data.json'
]
...
...
database_files/utils.py
View file @
7a3c5a9e
...
...
@@ -5,6 +5,10 @@ import hashlib
from
django.conf
import
settings
DEFAULT_ENFORCE_ENCODING
=
getattr
(
settings
,
'DB_FILES_DEFAULT_ENFORCE_ENCODING'
,
True
)
DEFAULT_ENCODING
=
getattr
(
settings
,
'DB_FILES_DEFAULT_ENCODING'
,
'ascii'
)
DEFAULT_ERROR_METHOD
=
getattr
(
settings
,
'DB_FILES_DEFAULT_ERROR_METHOD'
,
'ignore'
)
def
is_fresh
(
name
,
content_hash
):
"""
Returns true if the file exists on the local filesystem and matches the
...
...
@@ -45,20 +49,42 @@ def write_file(name, content, overwrite=False):
if
perms
:
os
.
system
(
'chmod -R %s "%s"'
%
(
perms
,
dirs
))
def
get_file_hash
(
fin
):
#def get_file_hash(fin):
# """
# Iteratively builds a file hash without loading the entire file into memory.
# """
# if isinstance(fin, basestring):
# fin = open(fin)
# h = hashlib.sha512()
# for text in fin.readlines():
# if not isinstance(text, unicode):
# text = unicode(text, encoding='utf-8', errors='replace')
# h.update(text.encode('utf-8', 'replace'))
# return h.hexdigest()
def
get_file_hash
(
fin
,
force_encoding
=
DEFAULT_ENFORCE_ENCODING
,
encoding
=
DEFAULT_ENCODING
,
errors
=
DEFAULT_ERROR_METHOD
):
"""
Iteratively builds a file hash without loading the entire file into memory.
"""
if
isinstance
(
fin
,
basestring
):
fin
=
open
(
fin
)
fin
=
open
(
fin
,
'r'
)
h
=
hashlib
.
sha512
()
for
text
in
fin
.
readlines
():
if
not
isinstance
(
text
,
unicode
):
text
=
unicode
(
text
,
encoding
=
'utf-8'
,
errors
=
'replace'
)
h
.
update
(
text
.
encode
(
'utf-8'
,
'replace'
))
while
1
:
text
=
fin
.
read
(
1000
)
if
not
text
:
break
if
force_encoding
:
if
not
isinstance
(
text
,
unicode
):
text
=
unicode
(
text
,
encoding
=
encoding
,
errors
=
errors
)
h
.
update
(
text
.
encode
(
encoding
,
errors
))
else
:
h
.
update
(
text
)
return
h
.
hexdigest
()
def
get_text_hash
(
text
):
def
get_text_hash
_0004
(
text
):
"""
Returns the hash of the given text.
"""
...
...
@@ -68,4 +94,18 @@ def get_text_hash(text):
h
.
update
(
text
.
encode
(
'utf-8'
,
'replace'
))
return
h
.
hexdigest
()
get_text_hash_0004
=
get_text_hash
def
get_text_hash
(
text
,
force_encoding
=
DEFAULT_ENFORCE_ENCODING
,
encoding
=
DEFAULT_ENCODING
,
errors
=
DEFAULT_ERROR_METHOD
):
"""
Returns the hash of the given text.
"""
h
=
hashlib
.
sha512
()
if
force_encoding
:
if
not
isinstance
(
text
,
unicode
):
text
=
unicode
(
text
,
encoding
=
encoding
,
errors
=
errors
)
h
.
update
(
text
.
encode
(
encoding
,
errors
))
else
:
h
.
update
(
text
)
return
h
.
hexdigest
()
setup.py
View file @
7a3c5a9e
...
...
@@ -23,6 +23,7 @@ class TestCommand(Command):
pass
def
run
(
self
):
os
.
system
(
'django-admin.py test --pythonpath=. --settings=database_files.tests.settings tests'
)
#os.system('django-admin.py test --pythonpath=. --settings=database_files.tests.settings tests.DatabaseFilesTestCase.test_hash')
setup
(
name
=
'django-database-files'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment