Commit f21f6eaf authored by fred's avatar fred

get local/remote base path from settings

parent e85ca8c7
from django.conf import settings
class AppSettings:
def get_setting(self, setting, default=None):
return settings.getattr('NONSTOP_' + setting, default)
@property
def REMOTE_BASE_PATH(self):
return self.get_setting('REMOTE_BASE_PATH', '/srv/soma/nonstop/')
@property
def LOCAL_BASE_PATH(self):
return self.get_setting('LOCAL_BASE_PATH', '/media/nonstop/')
app_settings = AppSettings()
......@@ -5,10 +5,9 @@ from django.core.management.base import BaseCommand, CommandError
from django.utils.text import slugify
from ...models import NonstopFile, Track, Artist
from ...app_settings import app_settings
from emissions.models import Nonstop
LOCAL_BASE_PATH = '/media/nonstop/'
REMOTE_BASE_PATH = '/srv/soma/nonstop/'
tranche_slug_mapping = {
'Acouphene': 'acouphene',
......@@ -35,15 +34,15 @@ class Command(BaseCommand):
continue
count = NonstopFile.objects.filter(**kwargs).count()
for i, nonstopfile in enumerate(NonstopFile.objects.filter(**kwargs)):
filepath = nonstopfile.filepath.replace(REMOTE_BASE_PATH, LOCAL_BASE_PATH)
filepath = nonstopfile.filepath.replace(app_settings.REMOTE_BASE_PATH, app_settings.LOCAL_BASE_PATH)
if self.verbose:
print(i, count, filepath)
short_filepath = filepath[len(LOCAL_BASE_PATH):]
short_filepath = filepath[len(app_settings.LOCAL_BASE_PATH):]
if short_filepath.startswith('SPOTS'):
continue
if not os.path.exists(filepath):
if self.verbose and short_filepath.startswith('Tranches'):
print('missing file:', filepath[len(LOCAL_BASE_PATH):])
print('missing file:', filepath[len(app_settings.LOCAL_BASE_PATH):])
continue
if self.verbose:
print(short_filepath)
......
......@@ -11,8 +11,8 @@ from django.dispatch import receiver
from django.utils.timezone import now
from django.utils.translation import ugettext_lazy as _
REMOTE_BASE_PATH = '/srv/soma/nonstop/'
LOCAL_BASE_PATH = '/media/nonstop/'
from .app_settings import app_settings
TRANCHE_SLUG_DIR_MAPPING = {
'acouphene': 'Acouphene',
......@@ -26,6 +26,8 @@ TRANCHE_SLUG_DIR_MAPPING = {
'up-beat-tempo': 'Up_Beat_Tempo',
}
class Artist(models.Model):
name = models.CharField(_('Name'), max_length=255)
......@@ -120,7 +122,7 @@ class Track(models.Model):
if not zone.slug in TRANCHE_SLUG_DIR_MAPPING:
continue
zone_dir = TRANCHE_SLUG_DIR_MAPPING[zone.slug]
zone_path = os.path.join(LOCAL_BASE_PATH, 'Tranches', zone_dir, filename)
zone_path = os.path.join(app_settings.LOCAL_BASE_PATH, 'Tranches', zone_dir, filename)
if zone in current_zones:
if not os.path.exists(zone_path):
os.symlink(os.path.join('..', '..', nonstop_file.short), zone_path)
......@@ -137,16 +139,16 @@ class NonstopFile(models.Model):
@property
def short(self):
return self.filepath[len(REMOTE_BASE_PATH):]
return self.filepath[len(app_settings.REMOTE_BASE_PATH):]
def set_track_filepath(self, filepath):
self.filepath = os.path.join(REMOTE_BASE_PATH, 'tracks', filepath)
self.filepath = os.path.join(app_settings.REMOTE_BASE_PATH, 'tracks', filepath)
self.filename = os.path.basename(filepath)
def get_local_filepath(self):
if not self.short:
return None
return os.path.join(LOCAL_BASE_PATH, self.short)
return os.path.join(app_settings.LOCAL_BASE_PATH, self.short)
class SomaLogLine(models.Model):
......@@ -196,7 +198,7 @@ class Jingle(models.Model):
def get_local_filepath(self):
if not self.short:
return None
return os.path.join(LOCAL_BASE_PATH, 'SPOTS', self.short)
return os.path.join(app_settings.LOCAL_BASE_PATH, 'SPOTS', self.short)
@property
def title(self):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment