diff --git a/teamplayer/Makefile b/teamplayer/Makefile index 5f38dc1..a6bf90b 100644 --- a/teamplayer/Makefile +++ b/teamplayer/Makefile @@ -6,7 +6,7 @@ PGVER = 9.2 INSTALL = install AVAHI := NO -M4_DEFS += -D TP_USER=$(TP_USER) -D TP_HOME=$(TP_HOME) -D TP_DB=$(TP_DB) +M4_DEFS += -D TP_USER=$(TP_USER) -D TP_HOME=$(TP_HOME) -D TP_DB=$(TP_DB) -D TP_HOSTNAME=$(HOSTNAME) M4C = $(M4) $(M4_DEFS) inroot := chroot $(CHROOT) @@ -20,7 +20,7 @@ preinstall: $(inroot) eselect python set python2.7 $(inroot) python-updater -postinstall: $(post_files) $(SCROBBLER_AUTH) +postinstall: $(post_files) $(SCROBBLER_AUTH) urls.py $(inroot) $(EMERGE) -n $(USEPKG) dev-db/postgresql-server:$(PGVER) $(inroot) passwd -d postgres echo 'PG_INITDB_OPTS="--locale=en_US.UTF-8"' >> $(CHROOT)/etc/conf.d/postgresql-$(PGVER) @@ -34,15 +34,23 @@ ifeq ($(AVAHI),YES) cp teamplayer.service $(CHROOT)/etc/avahi/services $(inroot) ln -sf /etc/init.d/avahi-daemon $(rcdefault)/avahi-daemon endif + $(inroot) $(EMERGE) -1n $(USEPKG) dev-python/virtualenv $(inroot) getent passwd $(TP_USER) || \ $(inroot) useradd -c "Teamplayer Server" -G postgres -U -d $(TP_HOME) $(TP_USER) rm -rf $(CHROOT)/$(TP_HOME) - hg clone --pull $(TP_REPO) $(CHROOT)/$(TP_HOME) + mkdir -p $(CHROOT)/$(TP_HOME) + hg clone --pull $(TP_REPO) $(CHROOT)/$(TP_HOME)/teamplayer cp bash_profile $(CHROOT)$(TP_HOME)/.bash_profile - $(inroot) mkdir -p /etc/teamplayer - $(M4C) settings_local.py > $(CHROOT)/etc/teamplayer/settings_local.py + $(inroot) virtualenv-2.7 $(TP_HOME) + $(inroot) bash -c ". $(TP_HOME)/bin/activate ; pip install -e $(TP_HOME)/teamplayer" + $(inroot) bash -c ". $(TP_HOME)/bin/activate ; pip install psycopg2 flup 'Whoosh<2.5.0'" + $(inroot) bash -c ". $(TP_HOME)/bin/activate ; django-admin.py startproject project $(TP_HOME)" + chmod +x $(CHROOT)/$(TP_HOME)/manage.py + $(inroot) ln -sf ../manage.py $(TP_HOME)/bin/manage + cp urls.py $(CHROOT)/$(TP_HOME)/project/urls.py + $(M4C) settings_local.py >> $(CHROOT)/$(TP_HOME)/project/settings_local.py ifdef SCROBBLER_AUTH - cat $(SCROBBLER_AUTH) >> $(CHROOT)/etc/teamplayer/settings_local.py + cat $(SCROBBLER_AUTH) >> $(CHROOT)/$(TP_HOME)/project/settings_local.py endif mkdir -p $(CHROOT)$(TP_HOME)/bin $(M4C) start-teamplayer > $(CHROOT)$(TP_HOME)/bin/start-teamplayer @@ -51,9 +59,8 @@ endif chmod +x $(CHROOT)$(TP_HOME)/bin/stop-teamplayer $(inroot) $(INSTALL) -d -o $(TP_USER) -g $(TP_USER) $(TP_DB) $(inroot) $(INSTALL) -d -o $(TP_USER) -g $(TP_USER) $(TP_DB)/songs - $(inroot) rm -rf $(TP_HOME)/web/media/songs - $(inroot) ln -s $(TP_DB)/songs $(TP_HOME)/web/media/songs - $(inroot) chown -R $(TP_USER) $(TP_HOME) + $(inroot) mkdir -p $(TP_HOME)/library + $(inroot) chown -R $(TP_USER):$(TP_USER) $(TP_HOME) $(inroot) $(INSTALL) -d -o $(TP_USER) -g $(TP_USER) $(TP_DB)/mpd $(inroot) $(INSTALL) -d -o $(TP_USER) -g $(TP_USER) /var/log/teamplayer $(M4C) local.start > $(CHROOT)/etc/local.d/teamplayer.start @@ -64,10 +71,9 @@ endif $(M4C) lighttpd.conf > $(CHROOT)/etc/lighttpd/lighttpd.conf $(inroot) gpasswd -a lighttpd teamplayer - # Fix for Gentoo bug #359361. Remove when fixed - $(inroot) ln -sf /usr/lib/postgresql-$(PGVER)/lib64/libpq.so.5 /usr/lib/libpq.so.5 $(inroot) ln -sf /etc/init.d/lighttpd $(rcdefault)/lighttpd $(inroot) ln -sf /etc/init.d/ntpd $(rcdefault)/ntpd + $(inroot) $(EMERGE) --depclean --with-bdeps=n clean: diff --git a/teamplayer/bash_profile b/teamplayer/bash_profile index 90297af..06f9bc8 100644 --- a/teamplayer/bash_profile +++ b/teamplayer/bash_profile @@ -1 +1,3 @@ +export DJANGO_SETTINGS_MODULE='project.settings_local' PATH="$HOME/bin:$PATH" +. activate diff --git a/teamplayer/issue b/teamplayer/issue index 2bca640..21b8ac1 100644 --- a/teamplayer/issue +++ b/teamplayer/issue @@ -1,4 +1,4 @@ - ------------------------------------------------------------------------------ + ------------------------------------------------------------------------------ TEAMPLAYER CONSOLE ------------------------------------------------------------------------------ diff --git a/teamplayer/lighttpd.conf b/teamplayer/lighttpd.conf index d0cd2fa..44a57c3 100644 --- a/teamplayer/lighttpd.conf +++ b/teamplayer/lighttpd.conf @@ -71,10 +71,10 @@ fastcgi.server = ( ), ) alias.url = ( - "/m" => "TP_HOME/web/media/", + "/static" => "TP_HOME/static/", ) url.rewrite-once = ( - "^(/m.*)$" => "$1", + "^(/static.*)$" => "$1", "^(/.*)$" => "/teamplayer.fcgi$1", ) diff --git a/teamplayer/local.start b/teamplayer/local.start index b97c145..f633dcb 100755 --- a/teamplayer/local.start +++ b/teamplayer/local.start @@ -1,14 +1,16 @@ #!/bin/sh +LOGFILE="/var/log/teamplayer/teamplayer.log" + if [ ! -f /etc/firstboot ] ; then echo "Creating TeamPlayer database ..." createuser -U postgres -D -S -R teamplayer createdb -U postgres teamplayer - touch /var/log/teamplayer/teamplayer.log - chown TP_USER:TP_USER /var/log/teamplayer/teamplayer.log + touch "$LOGFILE" + chown TP_USER:TP_USER "$LOGFILE" fi su -c "TP_HOME/bin/start-teamplayer" TP_USER -tailf /var/log/teamplayer/teamplayer.log > /dev/tty7 & +#tailf "$LOGFILE" > /dev/console & touch /etc/firstboot diff --git a/teamplayer/local.stop b/teamplayer/local.stop old mode 100644 new mode 100755 diff --git a/teamplayer/make.conf b/teamplayer/make.conf index f5071b2..271b736 100644 --- a/teamplayer/make.conf +++ b/teamplayer/make.conf @@ -1,3 +1,5 @@ # Settings for TeamPlayer PYTHON_TARGETS="python2_7" +PYTHON_SINGLE_TARGET="python2_7" +USE_PYTHON="2.7" diff --git a/teamplayer/package.keywords b/teamplayer/package.keywords index 0b545d7..df9e5ca 100644 --- a/teamplayer/package.keywords +++ b/teamplayer/package.keywords @@ -1,4 +1,4 @@ -dev-db/postgresql-base ~amd64 -dev-db/postgresql-server ~amd64 -dev-python/django ~amd64 -dev-python/python-mpd ~amd64 +dev-db/postgresql-base ~amd64 ~x86 +dev-db/postgresql-server ~amd64 ~x86 +virtual/python-imaging ~amd64 ~x86 +dev-lang/python:2.7 ~amd64 ~x86 diff --git a/teamplayer/package.use b/teamplayer/package.use index b4e6f62..aef83e4 100644 --- a/teamplayer/package.use +++ b/teamplayer/package.use @@ -1,12 +1,13 @@ app-editors/nano ncurses dev-db/sqlite extensions dev-lang/python sqlite ssl threads xml -dev-python/django postgres media-libs/flac ogg -media-sound/mpd audiofile ffmpeg flac id3tag lame network ogg vorbis mad sqlite +media-sound/mpd aac audiofile ffmpeg flac inotify id3tag lame network ogg vorbis mad sqlite media-video/ffmpeg mmx mxext mp3 network x264 +sys-apps/kmod tools sys-devel/gcc cxx sys-kernel/gentoo-sources symlink sys-libs/ncurses minimal +virtual/python-imaging python_targets_python2_7 virtual/ffmpeg x264 mp3 www-servers/lighttpd fastcgi pcre diff --git a/teamplayer/settings_local.py b/teamplayer/settings_local.py index db83bc2..7642ca6 100644 --- a/teamplayer/settings_local.py +++ b/teamplayer/settings_local.py @@ -1,15 +1,131 @@ +from settings import * + +############################################################################# +# Local Settings +# +# New/Overriden settings from settings_local.py +############################################################################# + +import os + +DEBUG = False +TEMPLATE_DEBUG = DEBUG + +TIME_ZONE = 'America/New_York' + +# Language code for this installation. All choices can be found here: +# http://www.i18nguy.com/unicode/language-identifiers.html +LANGUAGE_CODE = 'en-us' + +# If you set this to False, Django will make some optimizations so as not +# to load the internationalization machinery. +USE_I18N = False + +# URL that handles the media served from MEDIA_ROOT. Make sure to use a +# trailing slash if there is a path component (optional in other cases). +# Examples: "http://media.lawrence.com", "http://example.com/media/" +MEDIA_URL = '' + +STATIC_ROOT = 'static' +STATIC_URL = '/static/' +STATICFILE_FINDERS = ( + 'django.contrib.staticfiles.finders.FileSystemFinder', + 'django.contrib.staticfiles.finders.AppDirectoriesFinder', +) + +# List of callables that know how to import templates from various sources. +TEMPLATE_LOADERS = ( + 'django.template.loaders.filesystem.Loader', + 'django.template.loaders.app_directories.Loader', +) + +MIDDLEWARE_CLASSES = ( + 'django.middleware.common.CommonMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', +) + +INSTALLED_APPS = ( + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'haystack', + 'rest_framework', + 'teamplayer', + 'tp_library', +) + +AUTH_PROFILE_MODULE = 'teamplayer.UserProfile' +LOGIN_REDIRECT_URL = '/' + +REST_FRAMEWORK = { + 'DEFAULT_PERMISSION_CLASSES': [ + 'rest_framework.permissions.IsAuthenticated', + ], +} + +LOGGING = { + 'version': 1, + 'disable_existing_loggers': False, + 'filters': { + 'require_debug_false': { + '()': 'django.utils.log.RequireDebugFalse' + } + }, + 'formatters': { + 'verbose': { + 'format': '%(levelname)s %(asctime)s %(message)s' + } + }, + 'handlers': { + 'mail_admins': { + 'level': 'ERROR', + 'filters': ['require_debug_false'], + 'class': 'django.utils.log.AdminEmailHandler' + }, + 'console': { + 'level': 'DEBUG', + 'class': 'logging.StreamHandler', + 'formatter': 'verbose' + } + }, + 'loggers': { + 'django.request': { + 'handlers': ['mail_admins'], + 'level': 'ERROR', + 'propagate': True, + }, + 'teamplayer': { + 'handlers': ['console'], + 'level': 'DEBUG', + 'propagate': False, + } + } +} + +ALLOWED_HOSTS = ['*'] TIME_ZONE = 'UTC' -DJANGO_STATIC_MEDIA = False FORCE_SCRIPT_NAME = '' +MEDIA_ROOT = 'TP_DB' TEMPLATE_DIRS = ( 'TP_HOME/web/teamplayer/templates', ) -TP_STREAM_URL = '/stream.mp3' + `TP_HOME' = 'TP_HOME' -DEBUG = False -TEMPLATE_DEBUG = DEBUG + +TEAMPLAYER = { + 'STREAM_URL': '/stream.mp3', + 'MPD_HOME': 'TP_DB/mpd', + 'MPD_LOG': '/dev/null', + 'UPLOADED_LIBRARY_DIR': 'TP_HOME/library', + 'CROSSFADE': 2, +} + DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', @@ -20,6 +136,13 @@ DATABASES = { } } -TP_MPD_HOME = 'TP_DB/mpd' -TP_REPO_URL = '/repo/' -TP_MPD_LOG = '/dev/null' + +# haystack +HAYSTACK_CONNECTIONS = { + 'default': { + 'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine', + 'PATH': os.path.join(`TP_HOME', 'library_index'), + }, +} + +HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor' diff --git a/teamplayer/start-teamplayer b/teamplayer/start-teamplayer index f6e1eb0..83a49f7 100755 --- a/teamplayer/start-teamplayer +++ b/teamplayer/start-teamplayer @@ -1,17 +1,15 @@ #!/bin/sh # this should be run as the TP_USER user -PYTHONPATH="/etc/teamplayer:$PYTHONPATH" -PYTHON=python2.7 -export PYTHONPATH +PYTHON=python +DJANGO_SETTINGS_MODULE="project.settings_local" ; export DJANGO_SETTINGS_MODULE cd ~ -hg serve -p 8000 --prefix /repo/ > /var/log/teamplayer/hgserve.log 2>&1 & - -cd ~/web +. bin/activate if [ ! -f "/etc/firstboot" ] ; then $PYTHON manage.py syncdb --noinput --verbosity=0 + $PYTHON manage.py collectstatic --noinput --verbosity=0 fi # start the fastcgi daemon @@ -19,6 +17,6 @@ $PYTHON manage.py runfcgi daemonize=true protocol=fcgi maxrequest=20 \ pidfile="TP_DB/fcgi.pid" socket=TP_DB/teamplayer.sock umask=002 \ > "/var/log/teamplayer/teamplayer.log" 2>&1 -# spin! -$PYTHON manage.py spin --verbosity=2 $@ > "/var/log/teamplayer/teamplayer.log" 2>&1 & +# Start the Spin Doctor +$PYTHON manage.py spindoctor --verbosity=2 $@ > "/var/log/teamplayer/teamplayer.log" 2>&1 & echo $! > "TP_DB/tps.pid" diff --git a/teamplayer/stop-teamplayer b/teamplayer/stop-teamplayer index 4199ca4..25bf488 100755 --- a/teamplayer/stop-teamplayer +++ b/teamplayer/stop-teamplayer @@ -1,12 +1,14 @@ #!/bin/sh # this should be run as the TP_USER user -cd ~/web -PYTHONPATH="/etc/teamplayer:$PYTHONPATH" -PYTHON=python2.7 +PYTHON=python +DJANGO_SETTINGS_MODULE="project.settings_local" ; export DJANGO_SETTINGS_MODULE -export PYTHONPATH +. ~/bin/activate -[ -f "TP_DB/tps.pid" ] && kill $(cat "TP_DB/tps.pid") +cd ~ + +#[ -f "TP_DB/tps.pid" ] && kill $(cat "TP_DB/tps.pid") [ -f "TP_DB/fcgi.pid" ] && kill $(cat "TP_DB/fcgi.pid") + $PYTHON manage.py stop_stream >> "/var/log/teamplayer/teamplayer.log" diff --git a/teamplayer/urls.py b/teamplayer/urls.py new file mode 100644 index 0000000..14d579a --- /dev/null +++ b/teamplayer/urls.py @@ -0,0 +1,8 @@ +from django.conf.urls import patterns, include, url + +urlpatterns = patterns( + '', + (r'^accounts/login/$', 'django.contrib.auth.views.login'), + url('^library/', include('tp_library.urls')), + url('', include('teamplayer.urls')), +) diff --git a/teamplayer/world b/teamplayer/world index ef4c7bc..156c174 100644 --- a/teamplayer/world +++ b/teamplayer/world @@ -1,7 +1,3 @@ -=dev-python/django-1.3* -dev-python/flup -dev-python/python-mpd -media-libs/mutagen media-sound/mpd net-misc/ntp www-servers/lighttpd