Do not create cache folder if no-cache option
This commit is contained in:
1 parent
c3c1af113c
commit
36e7dfaa0e
3 files changed
+35
-29
No files matched your search
@@ -12,7 +12,6 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import hashlib
|
|
||||||
import os
|
import os
|
||||||
import pickle
|
import pickle
|
||||||
|
|
||||||
@@ -41,11 +40,3 @@ class Cache(dict):
|
|||||||
def save(self):
|
def save(self):
|
||||||
with open(self.filename, "wb") as f:
|
with open(self.filename, "wb") as f:
|
||||||
pickle.dump(self, f, protocol=2)
|
pickle.dump(self, f, protocol=2)
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def md5(path):
|
|
||||||
hash_md5 = hashlib.md5()
|
|
||||||
with open(path, "rb") as f:
|
|
||||||
for chunk in iter(lambda: f.read(4096), b""):
|
|
||||||
hash_md5.update(chunk)
|
|
||||||
return hash_md5.hexdigest()
|
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import hashlib
|
||||||
|
|
||||||
from django_migration_linter.utils import split_migration_path
|
from django_migration_linter.utils import split_migration_path
|
||||||
|
|
||||||
|
|
||||||
@@ -10,3 +12,10 @@ class Migration(object):
|
|||||||
if not isinstance(other, Migration):
|
if not isinstance(other, Migration):
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
return self.abs_path < other.abs_path
|
return self.abs_path < other.abs_path
|
||||||
|
|
||||||
|
def get_md5hash(self):
|
||||||
|
hash_md5 = hashlib.md5()
|
||||||
|
with open(self.abs_path, "rb") as f:
|
||||||
|
for chunk in iter(lambda: f.read(4096), b""):
|
||||||
|
hash_md5.update(chunk)
|
||||||
|
return hash_md5.hexdigest()
|
||||||
@@ -61,9 +61,9 @@ class MigrationLinter(object):
|
|||||||
self.nb_total = 0
|
self.nb_total = 0
|
||||||
|
|
||||||
# Initialise cache. Read from old, write to new to prune old entries.
|
# Initialise cache. Read from old, write to new to prune old entries.
|
||||||
|
if not self.no_cache:
|
||||||
self.old_cache = Cache(self.django_path, self.cache_path)
|
self.old_cache = Cache(self.django_path, self.cache_path)
|
||||||
self.new_cache = Cache(self.django_path, self.cache_path)
|
self.new_cache = Cache(self.django_path, self.cache_path)
|
||||||
if not self.no_cache:
|
|
||||||
self.old_cache.load()
|
self.old_cache.load()
|
||||||
|
|
||||||
def lint_migration(self, migration):
|
def lint_migration(self, migration):
|
||||||
@@ -72,22 +72,9 @@ class MigrationLinter(object):
|
|||||||
print("({0}, {1})... ".format(app_name, migration_name), end="")
|
print("({0}, {1})... ".format(app_name, migration_name), end="")
|
||||||
self.nb_total += 1
|
self.nb_total += 1
|
||||||
|
|
||||||
md5hash = self.old_cache.md5(migration.abs_path)
|
md5hash = migration.get_md5hash()
|
||||||
if md5hash in self.old_cache:
|
if not self.no_cache and md5hash in self.old_cache:
|
||||||
if self.old_cache[md5hash]["result"] == "IGNORE":
|
self.lint_cached_migration(md5hash)
|
||||||
print("IGNORE (cached)")
|
|
||||||
self.nb_ignored += 1
|
|
||||||
elif self.old_cache[md5hash]["result"] == "OK":
|
|
||||||
print("OK (cached)")
|
|
||||||
self.nb_valid += 1
|
|
||||||
else:
|
|
||||||
print("ERR (cached)")
|
|
||||||
self.nb_erroneous += 1
|
|
||||||
|
|
||||||
if "errors" in self.old_cache[md5hash]:
|
|
||||||
self.print_errors(self.old_cache[md5hash]["errors"])
|
|
||||||
|
|
||||||
self.new_cache[md5hash] = self.old_cache[md5hash]
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.should_ignore_migration(app_name, migration_name):
|
if self.should_ignore_migration(app_name, migration_name):
|
||||||
@@ -101,20 +88,39 @@ class MigrationLinter(object):
|
|||||||
|
|
||||||
if analysis_result["ignored"]:
|
if analysis_result["ignored"]:
|
||||||
print("IGNORE")
|
print("IGNORE")
|
||||||
self.new_cache[md5hash] = {"result": "IGNORE"}
|
|
||||||
self.nb_ignored += 1
|
self.nb_ignored += 1
|
||||||
|
if not self.no_cache:
|
||||||
|
self.new_cache[md5hash] = {"result": "IGNORE"}
|
||||||
return
|
return
|
||||||
|
|
||||||
if not errors:
|
if not errors:
|
||||||
print("OK")
|
print("OK")
|
||||||
self.new_cache[md5hash] = {"result": "OK"}
|
|
||||||
self.nb_valid += 1
|
self.nb_valid += 1
|
||||||
|
if not self.no_cache:
|
||||||
|
self.new_cache[md5hash] = {"result": "OK"}
|
||||||
return
|
return
|
||||||
|
|
||||||
print("ERR")
|
print("ERR")
|
||||||
self.new_cache[md5hash] = {"result": "ERR", "errors": errors}
|
|
||||||
self.nb_erroneous += 1
|
self.nb_erroneous += 1
|
||||||
self.print_errors(errors)
|
self.print_errors(errors)
|
||||||
|
if not self.no_cache:
|
||||||
|
self.new_cache[md5hash] = {"result": "ERR", "errors": errors}
|
||||||
|
|
||||||
|
def lint_cached_migration(self, md5hash):
|
||||||
|
cached_value = self.old_cache[md5hash]
|
||||||
|
if cached_value["result"] == "IGNORE":
|
||||||
|
print("IGNORE (cached)")
|
||||||
|
self.nb_ignored += 1
|
||||||
|
elif cached_value["result"] == "OK":
|
||||||
|
print("OK (cached)")
|
||||||
|
self.nb_valid += 1
|
||||||
|
else:
|
||||||
|
print("ERR (cached)")
|
||||||
|
self.nb_erroneous += 1
|
||||||
|
if "errors" in cached_value:
|
||||||
|
self.print_errors(cached_value["errors"])
|
||||||
|
|
||||||
|
self.new_cache[md5hash] = cached_value
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def print_errors(errors):
|
def print_errors(errors):
|
||||||
|
|||||||
Reference in new issue
Block a user