Skip to content

Commit e881a6b

Browse files
authored
Merge pull request #14 from kimetrica/pep8-fixes
PEP8 fixes
2 parents aafd124 + ef66772 commit e881a6b

File tree

8 files changed

+24
-24
lines changed

8 files changed

+24
-24
lines changed

binary_database_files/manager.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import os
2-
31
from django.db import models
42

3+
54
class FileManager(models.Manager):
65
def get_from_name(self, name):
76
return self.get(name=name)

binary_database_files/models.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import print_function, unicode_literals
33

4-
import base64
5-
6-
import six
7-
84
from django.conf import settings
95
from django.db import models
106
from django.utils import timezone
@@ -16,8 +12,6 @@
1612
from binary_database_files.utils import write_file, is_fresh
1713
from binary_database_files.manager import FileManager
1814

19-
from . import settings as _settings
20-
2115

2216
@python_2_unicode_compatible
2317
class File(models.Model):

binary_database_files/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,21 @@
77
# to the local file system for faster serving.
88
DB_FILES_AUTO_EXPORT_DB_TO_FS = settings.DB_FILES_AUTO_EXPORT_DB_TO_FS = getattr(settings, 'DB_FILES_AUTO_EXPORT_DB_TO_FS', True)
99

10+
1011
def URL_METHOD_1(name):
1112
"""
1213
Construct file URL based on media URL.
1314
"""
1415
return os.path.join(settings.MEDIA_URL, name)
1516

17+
1618
def URL_METHOD_2(name):
1719
"""
1820
Construct file URL based on configured URL pattern.
1921
"""
2022
return reverse('database_file', kwargs={'name': name})
2123

24+
2225
URL_METHODS = (
2326
('URL_METHOD_1', URL_METHOD_1),
2427
('URL_METHOD_2', URL_METHOD_2),
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from django.db import models
22

3+
34
class Thing(models.Model):
45
upload = models.FileField(upload_to='i/special', max_length=500)

binary_database_files/tests/settings.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import os
2-
import sys
32

43
PROJECT_DIR = os.path.dirname(__file__)
54

65
DATABASES = {
7-
'default':{
6+
'default': {
87
'ENGINE': 'django.db.backends.sqlite3',
98
}
109
}
@@ -40,7 +39,7 @@
4039
'django.middleware.common.CommonMiddleware',
4140
'django.contrib.sessions.middleware.SessionMiddleware',
4241
'django.middleware.csrf.CsrfViewMiddleware',
43-
#'django.middleware.transaction.TransactionMiddleware',
42+
# 'django.middleware.transaction.TransactionMiddleware',
4443
'django.contrib.auth.middleware.AuthenticationMiddleware',
4544
'django.contrib.messages.middleware.MessageMiddleware',
4645
'django.middleware.locale.LocaleMiddleware',

binary_database_files/utils.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from django.conf import settings
88
from binary_database_files import settings as _settings
99

10+
1011
def is_fresh(name, content_hash):
1112
"""
1213
Returns true if the file exists on the local filesystem and matches the
@@ -34,19 +35,20 @@ def is_fresh(name, content_hash):
3435
local_content_hash = get_file_hash(fqfn)
3536
return local_content_hash == content_hash
3637

38+
3739
def get_hash_fn(name):
3840
"""
3941
Returns the filename for the hash file.
4042
"""
4143
fqfn = os.path.join(settings.MEDIA_ROOT, name)
4244
fqfn = os.path.normpath(fqfn)
43-
dirs, fn = os.path.split(fqfn)
44-
if not os.path.isdir(dirs):
45-
os.makedirs(dirs)
4645
fqfn_parts = os.path.split(fqfn)
46+
if not os.path.isdir(fqfn_parts[0]):
47+
os.makedirs(fqfn_parts[0])
4748
hash_fn = os.path.join(fqfn_parts[0], _settings.DB_FILES_DEFAULT_HASH_FN_TEMPLATE % fqfn_parts[1])
4849
return hash_fn
4950

51+
5052
def write_file(name, content, overwrite=False):
5153
"""
5254
Writes the given content to the relative filename under the MEDIA_ROOT.
@@ -55,9 +57,9 @@ def write_file(name, content, overwrite=False):
5557
fqfn = os.path.normpath(fqfn)
5658
if os.path.isfile(fqfn) and not overwrite:
5759
return
58-
dirs, fn = os.path.split(fqfn)
59-
if not os.path.isdir(dirs):
60-
os.makedirs(dirs)
60+
fqfn_parts = os.path.split(fqfn)
61+
if not os.path.isdir(fqfn_parts[0]):
62+
os.makedirs(fqfn_parts[0])
6163
open(fqfn, 'wb').write(content)
6264

6365
# Cache hash.
@@ -74,14 +76,15 @@ def write_file(name, content, overwrite=False):
7476
uname = getattr(settings, 'DATABASE_FILES_USER', None)
7577
gname = getattr(settings, 'DATABASE_FILES_GROUP', None)
7678
if gname:
77-
gname = ':'+gname
79+
gname = ':' + gname
7880
if uname:
79-
os.system('chown -RL %s%s "%s"' % (uname, gname, dirs))
81+
os.system('chown -RL %s%s "%s"' % (uname, gname, fqfn_parts[0]))
8082

8183
# Set permissions.
8284
perms = getattr(settings, 'DATABASE_FILES_PERMS', None)
8385
if perms:
84-
os.system('chmod -R %s "%s"' % (perms, dirs))
86+
os.system('chmod -R %s "%s"' % (perms, fqfn_parts[0]))
87+
8588

8689
def get_file_hash(fin, force_encoding=None, encoding=None, errors=None, chunk_size=128):
8790
"""
@@ -109,6 +112,7 @@ def get_file_hash(fin, force_encoding=None, encoding=None, errors=None, chunk_si
109112
h.update(text)
110113
return h.hexdigest()
111114

115+
112116
def get_text_hash_0004(text):
113117
"""
114118
Returns the hash of the given text.
@@ -119,6 +123,7 @@ def get_text_hash_0004(text):
119123
h.update(text.encode('utf-8', 'replace'))
120124
return h.hexdigest()
121125

126+
122127
def get_text_hash(text, force_encoding=None, encoding=None, errors=None):
123128
"""
124129
Returns the hash of the given text.

binary_database_files/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import base64
21
import mimetypes
3-
import os
42

53
from django.conf import settings
64
from django.http import Http404, HttpResponse
@@ -10,6 +8,7 @@
108

119
from binary_database_files.models import File
1210

11+
1312
@cache_control(max_age=86400)
1413
def serve(request, name):
1514
"""
@@ -23,6 +22,7 @@ def serve(request, name):
2322
response['Content-Length'] = f.size
2423
return response
2524

25+
2626
def serve_mixed(request, *args, **kwargs):
2727
"""
2828
First attempts to serve the file from the filesystem,

pylint.rc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ disable-msg-cat=I
8080
# W0401: wildcard import.
8181
# W0404: reimport check...this is sometimes wrong.
8282
# W0511: TODO check.
83-
# W0612: unused variable check.
8483
# W0613: unused argument check. Too vague.
8584
# W0614: wildcard import usage check.
8685
# W0704: empty except check.
@@ -104,7 +103,7 @@ disable-msg-cat=I
104103
# R0204: *Redefinition of %s type from %s to %s*
105104
# R0101: *Too many nested blocks (%s/%s)*
106105
# I0011: *Locally disabling %s (%s)*
107-
disable=C1001,C0103,R0201,W0212,W0614,W0401,W0704,E1101,W0142,R0904,R0913,W0404,R0903,W0232,C0111,W0613,W0612,W0511,W0104,R0902,R0921,R0401,E1103,C0303,W0311,C0330,F0401,E1002,E1120,R0901,W0611,E1123,C0302,R0801,R0914,R0912,R0915,W0703,E1003,E0202,W0201,W0221,C0325,R0916,R0204,R0101,I0011
106+
disable=C1001,C0103,R0201,W0212,W0614,W0401,W0704,E1101,W0142,R0904,R0913,W0404,R0903,W0232,C0111,W0613,W0511,W0104,R0902,R0921,R0401,E1103,C0303,W0311,C0330,F0401,E1002,E1120,R0901,W0611,E1123,C0302,R0801,R0914,R0912,R0915,W0703,E1003,E0202,W0201,W0221,C0325,R0916,R0204,R0101,I0011
108107

109108
[REPORTS]
110109

0 commit comments

Comments
 (0)