From bf1651c22bfa1af2bcfd01437a01f48763f52750 Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 9 May 2011 21:06:36 +0530 Subject: [PATCH] some utility functions to deal with the mess of files --- edgware/files/file_utils.py | 42 +++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 edgware/files/file_utils.py diff --git a/edgware/files/file_utils.py b/edgware/files/file_utils.py new file mode 100644 index 0000000..ecae4d6 --- /dev/null +++ b/edgware/files/file_utils.py @@ -0,0 +1,42 @@ +from models import File +import os + +def clean_nulls(): + x = [] + for f in File.objects.all(): + try: + fil = f.file.url + if not fil.startswith("/static"): + print fil + except ValueError: + f.delete() + +def clean_relative_links(): + for f in File.objects.all(): + if f.file.url.startswith("/srv"): + new_url = f.file.url.replace("/srv/edgware/edgware/static/", "") + print "%s CHANGED TO %s" % (f.file.url, new_url,) + f.file = new_url + f.save() + print "woohoo!" + +def file_exists(): + exists = 0 + not_found = 0 + for f in File.objects.all(): + if os.path.exists(f.file.path): + exists += 1 + else: + not_found +=1 + print "exist: %d \n" % exists + print "do not exist: %d" % not_found + + +def manage_types(): + videos = 0 + audios = 0 + images = 0 + + for f in File.objects.all(): + typ = f.type +