mirror of
https://github.com/fergalmoran/dss.git
synced 2026-01-01 14:39:10 +00:00
Rewrote orphan mp3 management command
This commit is contained in:
@@ -1,14 +1,31 @@
|
||||
from dircache import listdir
|
||||
import logging
|
||||
import os
|
||||
import shutil
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.core.management.base import NoArgsCommand
|
||||
from os.path import isfile, join
|
||||
from dss import settings
|
||||
from spa.models import Mix
|
||||
|
||||
logger = logging.getLogger('spa')
|
||||
|
||||
|
||||
class Command(NoArgsCommand):
|
||||
def handle(self, *args, **options):
|
||||
candidates = Mix.objects.all()
|
||||
for mix in candidates:
|
||||
file = mix.get_absolute_path(prefix="expired/")
|
||||
if os.path.exists(file):
|
||||
new = mix.get_absolute_path()
|
||||
shutil.move(file, new)
|
||||
try:
|
||||
mixes_path = join(settings.MEDIA_ROOT, "mixes")
|
||||
expired_path = join(settings.MEDIA_ROOT, "mixes/expired")
|
||||
files = [f for f in listdir(mixes_path) if isfile(join(mixes_path, f))]
|
||||
|
||||
for f in files:
|
||||
uid = os.path.splitext(f)[0]
|
||||
try:
|
||||
Mix.objects.get(uid=uid)
|
||||
except Mix.DoesNotExist:
|
||||
new_file = os.path.join(expired_path, os.path.basename(f))
|
||||
os.rename(f, new_file)
|
||||
print "Moved %s to %s" % (f, new_file)
|
||||
except Exception, ex:
|
||||
logger.log(logger.WARNING, "Error: %s" % ex.message)
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ def app(request):
|
||||
context['ua_html'] = \
|
||||
"""<div class="alert alert-block alert-warning">
|
||||
<button type="button" class="close" data-dismiss="alert">
|
||||
<i class="fa fa-close"></i>
|
||||
<i class="fa fa-times"></i>
|
||||
</button>
|
||||
<i class="fa fa-eye"></i>
|
||||
<strong>Hello Firefox user.</strong> If you are having any problems with the site, please do a
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
<div class="space-6"></div>
|
||||
<div class="body-content col-md-9">
|
||||
<div class="row">
|
||||
<div class="ua-message col-md-9">{{ ua_html|safe }}</div>
|
||||
<div class="ua-message">{{ ua_html|safe }}</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div id="content"></div>
|
||||
|
||||
Reference in New Issue
Block a user