some utility functions to deal with the mess of files
This commit is contained in:
parent
e388776b47
commit
bf1651c22b
42
edgware/files/file_utils.py
Normal file
42
edgware/files/file_utils.py
Normal file
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user