[xiph-commits] r3935 - in arkaiv/trunk: arkaiv/controllers arkaiv/templates arkaiv/tests/functional data/templates
dcrowdy at svn.annodex.net
dcrowdy at svn.annodex.net
Wed May 27 20:37:53 PDT 2009
Author: dcrowdy
Date: 2009-05-27 20:37:52 -0700 (Wed, 27 May 2009)
New Revision: 3935
Added:
arkaiv/trunk/arkaiv/controllers/addmedia.py
arkaiv/trunk/arkaiv/controllers/playlist.py
arkaiv/trunk/arkaiv/tests/functional/test_addmedia.py
arkaiv/trunk/arkaiv/tests/functional/test_playlist.py
Modified:
arkaiv/trunk/arkaiv/controllers/page.py
arkaiv/trunk/arkaiv/controllers/page.pyc
arkaiv/trunk/arkaiv/templates/autohandler
arkaiv/trunk/data/templates/autohandler.py
arkaiv/trunk/data/templates/autohandler.pyc
Log:
Separated playlists and adding media into separate controllers
Added: arkaiv/trunk/arkaiv/controllers/addmedia.py
===================================================================
--- arkaiv/trunk/arkaiv/controllers/addmedia.py (rev 0)
+++ arkaiv/trunk/arkaiv/controllers/addmedia.py 2009-05-28 03:37:52 UTC (rev 3935)
@@ -0,0 +1,169 @@
+import logging
+import os
+import os.path
+import shutil
+import subprocess
+import sys
+
+from pylons import request, response, session, tmpl_context as c
+from pylons.controllers.util import abort, redirect_to
+from pylons import config
+
+from arkaiv.lib.base import BaseController, render, model
+from arkaiv.model.cmmlparser import cmmlParser
+from arkaiv.model.oggzinfo import OggzInfo
+from arkaiv.model.framer import Frame
+
+log = logging.getLogger(__name__)
+
+archive_loc = config['archive_loc']
+
+class AddmediaController(BaseController):
+
+ def index(self):
+ # Return a rendered template
+ #return render('/addmedia.mako')
+ # or, return a response
+ collectionlist = model.getcollections()
+ c.collectioninfo = ""
+ for collection in collectionlist:
+ c.collectioninfo = c.collectioninfo + "<option>" + collection['name'] + "</option>"
+
+ return render('/addannodexform.mak')
+
+ def addannodexmedia(self):
+ cmmlsource = request.POST['cmmlfile']
+ oggsource = request.POST['oggfile']
+
+ # If there is no ogg file, then return an error
+ if (oggsource == ""):
+ return render ('/nosourcefileerror.mak')
+
+ if (self.__addmediatoarchive(cmmlsource, oggsource) == "file exists"):
+ return render ('/fileexistsmessage.mak')
+ else:
+ redirect_to(controller='page', action='mainpage')
+
+ def __addmediatoarchive(self, cmmlsource, oggsource):
+ # Deal with the cmml file
+ # if no cmml file has been entered, then create one
+ if cmmlsource=="":
+ print "creating source file"
+ basecmmlname = os.path.splitext(oggsource.filename)[0].replace(' ',"") + ".cmml"
+ newcmmlname = os.path.join(archive_loc, basecmmlname)
+ parser = cmmlParser()
+ #parser.setcmmlfilename(newcmmlname)
+ fulloggpath = os.path.join(archive_loc, oggsource.filename)
+ if os.path.isfile(newcmmlname):
+ print "File exists - bail time"
+ return "file exists"
+ parser.createnewfile(newcmmlname, fulloggpath)
+
+ else:
+ newcmmlname = os.path.join(archive_loc, cmmlsource.filename.replace(' ',""))
+ permanent_file = open(newcmmlname, 'w')
+ shutil.copyfileobj(cmmlsource.file, permanent_file)
+ cmmlsource.file.close()
+ permanent_file.close()
+
+ # Now the ogg file...
+ # FIXME whitespace is dealt with in a very clumsy manner
+ newoggname = os.path.join(archive_loc, oggsource.filename.replace(' ', ""))
+ permanent_file = open(newoggname, 'w')
+ shutil.copyfileobj(oggsource.file, permanent_file)
+ oggsource.file.close()
+ permanent_file.close()
+
+ basename = os.path.splitext(newoggname)[0]
+ imagedirname = basename + "_clipimages"
+ # Create a directory for clip images
+ if not os.path.isdir(imagedirname):
+ os.makedirs(imagedirname, mode=0755)
+
+ # Get the title for the item (head title)
+ parser = cmmlParser()
+ parser.setcmmlfilename(newcmmlname)
+ title = parser.gettitle()
+ # adding an item here, even though we don't actually have the source
+ # anx file in place yet...
+ newanxname = basename + ".anx"
+ newitemid = model.addsource(title, newoggname, newcmmlname)
+
+ # Need to update the source tag in the cmml file
+ parser.updatesourcetag(newoggname)
+ parser.addmetaid(newitemid)
+
+ headinfo = {}
+ headinfo['itemid']= newitemid
+ headinfo['id'] = ""
+ headinfo['title'] = title
+ headid = model.addhead(headinfo)
+
+ # Now extract any clip information and add it to the database
+ # get a list of dictionary objects
+
+ o = OggzInfo(newoggname)
+ cliplist = parser.getclipsfromcmml()
+ for clipdict in cliplist:
+ clipdict['itemid'] = newitemid
+ if o.has_video():
+ # get a still image for the correct frame
+ print "getting a clip image"
+ try:
+ # this fails very badly - stopping the web server even, so
+ # has been disabled for the moment.
+ print "multiple clip image import disabled for now"
+# clipdict['img_src'] = self.__createimageforclip(newcmmlname, clipdict)
+ except:
+ print "problem with clip image for id " + str(clipdict['itemid'])
+ clipdict['img_src'] = ""
+ else:
+ clipdict['img_src'] = ""
+ model.addclip(clipdict)
+
+ # Check whether the ogg file has any existing vorbis comments/tags
+ # and import them as meta tags
+
+ parser = cmmlParser()
+ parser.setcmmlfilename(newcmmlname)
+ metalist = parser.getheadinfofromcmml()
+
+ cmd = "vorbiscomment -l " + newoggname
+ runit = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE , stderr=subprocess.PIPE)
+ out, err = runit.communicate()
+
+ for line in out.splitlines():
+ metadict={}
+ print line
+ tag = line.split("=")
+ metadict['name'] = tag[0]
+ metadict['content'] = tag[1]
+ metadict['id'] = tag[0]
+ metadict['scheme'] = ""
+ metalist.append(metadict)
+
+ # Extract meta info from the head and add to database
+
+ for metadict in metalist:
+ metadict['headindex'] = headid
+ metadict['itemid'] = newitemid
+ model.addmeta(metadict)
+
+ # Now we read the meta tags back from the database, and write them into
+ # the cmml file, syncing the id tags - useful (essential) for editing
+ # these later.
+ metalist = model.getmetasforhead(headid)
+ # sync cmml id attribute of head metas with the database primary key
+ for meta in metalist:
+ model.syncmetaid(meta.ixm)
+
+ # and sync with the cmml file
+ # Probably best to do it in one go at this stage
+ parser.setcmmlfilename(newcmmlname)
+ parser.syncheadmetas(metalist)
+
+ collection = request.params['collection']
+ model.additemtocollection(headinfo['itemid'], collection)
+
+ return
+
Modified: arkaiv/trunk/arkaiv/controllers/page.py
===================================================================
--- arkaiv/trunk/arkaiv/controllers/page.py 2009-05-28 02:37:53 UTC (rev 3934)
+++ arkaiv/trunk/arkaiv/controllers/page.py 2009-05-28 03:37:52 UTC (rev 3935)
@@ -58,29 +58,7 @@
return render('/addform.mak')
- def addannodexform(self):
- collectionlist = model.getcollections()
- c.collectioninfo = ""
- for collection in collectionlist:
- c.collectioninfo = c.collectioninfo + "<option>" + collection['name'] + "</option>"
- return render('/addannodexform.mak')
-
- def playlistpage(self):
- """ controller for the main playlist listing page
-
- """
- c.playlists=model.getplaylists()
- return render('/playlists.mak')
-
- def addplaylist(self):
- """ Controller to add a new playlist
-
- """
- model.addnewplaylist(request.params['newplaylist'])
- c.playlists = model.getplaylists()
- return render('/playlists.mak')
-
def additemstoplaylist(self):
nmetas = int(request.params['nummetas'])
playlist = request.params['playlist']
@@ -91,7 +69,7 @@
except:
pass
- redirect_to(action='playlistpage')
+ redirect_to(controller='playlist', action='playlistpage')
def addclipstoplaylist(self):
@@ -104,69 +82,9 @@
except:
pass
- redirect_to(action='playlistpage')
+ redirect_to(controller='playlist', action='playlistpage')
- def deleteplaylist(self):
- name = request.params['playlistname']
- model.deleteplaylist(name)
- redirect_to(action='playlistpage')
-
- def displayplaylist(self):
- # Need to extract appropriate info for the playlist selected
- playlistid = int(request.params['id'])
-# print "playlist id is \n\n"
- c.name = request.params['name']
- clips = model.getclipsfromplaylist(playlistid)
- items = model.getitemsfromplaylist(playlistid)
- # send a list of dictionaries to the template
- for clip in clips:
- if (clip != None):
- item = model.getitemforclip(clip['index'])
- clip['name'] = item.name #name of the item the clip belongs to
- sourceid = model.getsourcesforitem(item.ixi)
- oggsource = model.getsourcepath(sourceid)
- cmmlfile = model.getitemcmmlfile(item.ixi)
- urlpath = split(cmmlfile, path_base)
- # Now split off the extension
- urlpath = os.path.splitext(urlpath[1])[0]
- #clip['url'] = media_url_base + urlpath + ".anx" + "?id=" + clip['id']
- o = OggzInfo(oggsource)
- if (o.has_video()):
- clip['has_video'] = "Yes"
- else:
- clip['has_video'] = "No"
-
- if (o.has_audio()):
- clip['has_audio'] = "Yes"
- else:
- clip['has_audio'] = "No"
-
- if clip['end'] == 0:
- clip['url'] = media_url_base + urlpath + ".ogg" + "?t=" + str(clip['start'])
- else:
- clip['url'] = media_url_base + urlpath + ".ogg" + "?t=" + str(clip['start']) + "/" + str(clip['end'])
-
- for item in items:
- sourceid = model.getsourcesforitem(item['index'])
- oggsource = model.getsourcepath(sourceid)
- urlpath = split(item['cmmlfile'], path_base)
- # Now split off the extension
- urlpath = os.path.splitext(urlpath[1])[0]
- #clipimageurl = media_url_base + os.path.dirname(urlpath) + "/"
- item['id'] = "" # a dummy to match clip info
- #item['url'] = media_url_base + urlpath + ".anx" + "?id=0"
- item['url'] = media_url_base + urlpath + ".ogg"
- clips.append(item)
-
- c.clips = clips
- print c.clips
- if (not c.clips):
- print "Nothing in clips"
- return render ('/emptyplaylistmessage.mak')
- else:
- return render('/playlistview.mak')
-
def addannodexindirform(self):
# Currently unused - useful if importing a load of material locally
collectionlist = model.getcollections()
@@ -351,142 +269,7 @@
redirect_to(action='mainpage')
- def addannodexmedia(self):
- cmmlsource = request.POST['cmmlfile']
- oggsource = request.POST['oggfile']
- # If there is no ogg file, then return an error
- if (oggsource == ""):
- return render ('/nosourcefileerror.mak')
-
- if (self.__addmediatoarchive(cmmlsource, oggsource) == "file exists"):
- return render ('/fileexistsmessage.mak')
- else:
- redirect_to(action='mainpage')
-
- def __addmediatoarchive(self, cmmlsource, oggsource):
- # Deal with the cmml file
- # if no cmml file has been entered, then create one
- if cmmlsource=="":
- print "creating source file"
- basecmmlname = os.path.splitext(oggsource.filename)[0].replace(' ',"") + ".cmml"
- newcmmlname = os.path.join(archive_loc, basecmmlname)
- parser = cmmlParser()
- #parser.setcmmlfilename(newcmmlname)
- fulloggpath = os.path.join(archive_loc, oggsource.filename)
- if os.path.isfile(newcmmlname):
- print "File exists - bail time"
- return "file exists"
- parser.createnewfile(newcmmlname, fulloggpath)
-
- else:
- newcmmlname = os.path.join(archive_loc, cmmlsource.filename.replace(' ',""))
- permanent_file = open(newcmmlname, 'w')
- shutil.copyfileobj(cmmlsource.file, permanent_file)
- cmmlsource.file.close()
- permanent_file.close()
-
- # Now the ogg file...
- # FIXME whitespace is dealt with in a very clumsy manner
- newoggname = os.path.join(archive_loc, oggsource.filename.replace(' ', ""))
- permanent_file = open(newoggname, 'w')
- shutil.copyfileobj(oggsource.file, permanent_file)
- oggsource.file.close()
- permanent_file.close()
-
- basename = os.path.splitext(newoggname)[0]
- imagedirname = basename + "_clipimages"
- # Create a directory for clip images
- if not os.path.isdir(imagedirname):
- os.makedirs(imagedirname, mode=0755)
-
- # Get the title for the item (head title)
- parser = cmmlParser()
- parser.setcmmlfilename(newcmmlname)
- title = parser.gettitle()
- # adding an item here, even though we don't actually have the source
- # anx file in place yet...
- newanxname = basename + ".anx"
- newitemid = model.addsource(title, newoggname, newcmmlname)
-
- # Need to update the source tag in the cmml file
- parser.updatesourcetag(newoggname)
- parser.addmetaid(newitemid)
-
- headinfo = {}
- headinfo['itemid']= newitemid
- headinfo['id'] = ""
- headinfo['title'] = title
- headid = model.addhead(headinfo)
-
- # Now extract any clip information and add it to the database
- # get a list of dictionary objects
-
- o = OggzInfo(newoggname)
- cliplist = parser.getclipsfromcmml()
- for clipdict in cliplist:
- clipdict['itemid'] = newitemid
- if o.has_video():
- # get a still image for the correct frame
- print "getting a clip image"
- try:
- # this fails very badly - stopping the web server even, so
- # has been disabled for the moment.
- print "multiple clip image import disabled for now"
-# clipdict['img_src'] = self.__createimageforclip(newcmmlname, clipdict)
- except:
- print "problem with clip image for id " + str(clipdict['itemid'])
- clipdict['img_src'] = ""
- else:
- clipdict['img_src'] = ""
- model.addclip(clipdict)
-
- # Check whether the ogg file has any existing vorbis comments/tags
- # and import them as meta tags
-
- parser = cmmlParser()
- parser.setcmmlfilename(newcmmlname)
- metalist = parser.getheadinfofromcmml()
-
- cmd = "vorbiscomment -l " + newoggname
- runit = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE , stderr=subprocess.PIPE)
- out, err = runit.communicate()
-
- for line in out.splitlines():
- metadict={}
- print line
- tag = line.split("=")
- metadict['name'] = tag[0]
- metadict['content'] = tag[1]
- metadict['id'] = tag[0]
- metadict['scheme'] = ""
- metalist.append(metadict)
-
- # Extract meta info from the head and add to database
-
- for metadict in metalist:
- metadict['headindex'] = headid
- metadict['itemid'] = newitemid
- model.addmeta(metadict)
-
- # Now we read the meta tags back from the database, and write them into
- # the cmml file, syncing the id tags - useful (essential) for editing
- # these later.
- metalist = model.getmetasforhead(headid)
- # sync cmml id attribute of head metas with the database primary key
- for meta in metalist:
- model.syncmetaid(meta.ixm)
-
- # and sync with the cmml file
- # Probably best to do it in one go at this stage
- parser.setcmmlfilename(newcmmlname)
- parser.syncheadmetas(metalist)
-
- collection = request.params['collection']
- model.additemtocollection(headinfo['itemid'], collection)
-
- return
-
def search(self):
searchterms = request.params['searchterms']
Modified: arkaiv/trunk/arkaiv/controllers/page.pyc
===================================================================
(Binary files differ)
Added: arkaiv/trunk/arkaiv/controllers/playlist.py
===================================================================
--- arkaiv/trunk/arkaiv/controllers/playlist.py (rev 0)
+++ arkaiv/trunk/arkaiv/controllers/playlist.py 2009-05-28 03:37:52 UTC (rev 3935)
@@ -0,0 +1,102 @@
+import logging
+import os
+import os.path
+
+from string import split
+from pylons import request, response, session, tmpl_context as c
+from pylons.controllers.util import abort, redirect_to
+from pylons import config
+
+from arkaiv.model.oggzinfo import OggzInfo
+from arkaiv.lib.base import BaseController, render, model
+
+log = logging.getLogger(__name__)
+
+path_base = config['media_path_base']
+media_url_base = config['media_url_base']
+
+class PlaylistController(BaseController):
+
+ def index(self):
+ # Return a rendered template
+ #return render('/playlist.mako')
+ # or, return a response
+ return 'Hello World'
+
+ def playlistpage(self):
+ """ controller for the main playlist listing page
+
+ """
+ c.playlists=model.getplaylists()
+ return render('/playlists.mak')
+
+ def addplaylist(self):
+ """ Controller to add a new playlist
+
+ """
+ model.addnewplaylist(request.params['newplaylist'])
+ c.playlists = model.getplaylists()
+ return render('/playlists.mak')
+
+ def deleteplaylist(self):
+ name = request.params['playlistname']
+ model.deleteplaylist(name)
+
+ redirect_to(action='playlistpage')
+
+ def displayplaylist(self):
+ # Need to extract appropriate info for the playlist selected
+ playlistid = int(request.params['id'])
+# print "playlist id is \n\n"
+ c.name = request.params['name']
+ clips = model.getclipsfromplaylist(playlistid)
+ items = model.getitemsfromplaylist(playlistid)
+ # send a list of dictionaries to the template
+ for clip in clips:
+ if (clip != None):
+ item = model.getitemforclip(clip['index'])
+ clip['name'] = item.name #name of the item the clip belongs to
+ sourceid = model.getsourcesforitem(item.ixi)
+ oggsource = model.getsourcepath(sourceid)
+ cmmlfile = model.getitemcmmlfile(item.ixi)
+ urlpath = split(cmmlfile, path_base)
+ # Now split off the extension
+ urlpath = os.path.splitext(urlpath[1])[0]
+ #clip['url'] = media_url_base + urlpath + ".anx" + "?id=" + clip['id']
+ o = OggzInfo(oggsource)
+ if (o.has_video()):
+ clip['has_video'] = "Yes"
+ else:
+ clip['has_video'] = "No"
+
+ if (o.has_audio()):
+ clip['has_audio'] = "Yes"
+ else:
+ clip['has_audio'] = "No"
+
+ if clip['end'] == 0:
+ clip['url'] = media_url_base + urlpath + ".ogg" + "?t=" + str(clip['start'])
+ else:
+ clip['url'] = media_url_base + urlpath + ".ogg" + "?t=" + str(clip['start']) + "/" + str(clip['end'])
+
+ for item in items:
+ sourceid = model.getsourcesforitem(item['index'])
+ oggsource = model.getsourcepath(sourceid)
+ urlpath = split(item['cmmlfile'], path_base)
+ # Now split off the extension
+ urlpath = os.path.splitext(urlpath[1])[0]
+ #clipimageurl = media_url_base + os.path.dirname(urlpath) + "/"
+ item['id'] = "" # a dummy to match clip info
+ #item['url'] = media_url_base + urlpath + ".anx" + "?id=0"
+ item['url'] = media_url_base + urlpath + ".ogg"
+ clips.append(item)
+
+ c.clips = clips
+ print c.clips
+ if (not c.clips):
+ print "Nothing in clips"
+ return render ('/emptyplaylistmessage.mak')
+ else:
+ return render('/playlistview.mak')
+
+
Modified: arkaiv/trunk/arkaiv/templates/autohandler
===================================================================
--- arkaiv/trunk/arkaiv/templates/autohandler 2009-05-28 02:37:53 UTC (rev 3934)
+++ arkaiv/trunk/arkaiv/templates/autohandler 2009-05-28 03:37:52 UTC (rev 3935)
@@ -12,11 +12,11 @@
<ul id="navlist">
<li>${ h.link_to("All Items", h.url_for(controller='page', action="mainpage")) }</li>
<li>${ h.link_to("Collections", h.url_for(controller='collection', action='list')) }</li>
- <li>${ h.link_to("Add media", h.url_for(controller='page', action="addannodexform")) }</li>
- <li>${ h.link_to("Playlists", h.url_for(controller='page', action="playlistpage")) }</li>
+ <li>${ h.link_to("Add media", h.url_for(controller='addmedia', action='index')) }</li>
+ <li>${ h.link_to("Playlists", h.url_for(controller='playlist', action="playlistpage")) }</li>
<li>${ h.link_to("Help", h.url_for(controller='help', action='index')) }</li>
<li><span class="searchpadding">
-${ h.form(h.url_for(action='search'), multipart=True) }
+${ h.form(h.url_for(controller='page', action='search'), multipart=True) }
${ h.text_field('searchterms', value="Search") }
${ h.end_form() }
</span>
Added: arkaiv/trunk/arkaiv/tests/functional/test_addmedia.py
===================================================================
--- arkaiv/trunk/arkaiv/tests/functional/test_addmedia.py (rev 0)
+++ arkaiv/trunk/arkaiv/tests/functional/test_addmedia.py 2009-05-28 03:37:52 UTC (rev 3935)
@@ -0,0 +1,7 @@
+from arkaiv.tests import *
+
+class TestAddmediaController(TestController):
+
+ def test_index(self):
+ response = self.app.get(url(controller='addmedia', action='index'))
+ # Test response...
Added: arkaiv/trunk/arkaiv/tests/functional/test_playlist.py
===================================================================
--- arkaiv/trunk/arkaiv/tests/functional/test_playlist.py (rev 0)
+++ arkaiv/trunk/arkaiv/tests/functional/test_playlist.py 2009-05-28 03:37:52 UTC (rev 3935)
@@ -0,0 +1,7 @@
+from arkaiv.tests import *
+
+class TestPlaylistController(TestController):
+
+ def test_index(self):
+ response = self.app.get(url(controller='playlist', action='index'))
+ # Test response...
Modified: arkaiv/trunk/data/templates/autohandler.py
===================================================================
--- arkaiv/trunk/data/templates/autohandler.py 2009-05-28 02:37:53 UTC (rev 3934)
+++ arkaiv/trunk/data/templates/autohandler.py 2009-05-28 03:37:52 UTC (rev 3935)
@@ -3,7 +3,7 @@
__M_dict_builtin = dict
__M_locals_builtin = locals
_magic_number = 5
-_modified_time = 1243477198.1538479
+_modified_time = 1243480755.038595
_template_filename=u'/home/dcrowdy/src/arkaiv/working/trunk/arkaiv/templates/autohandler'
_template_uri=u'/autohandler'
_template_cache=cache.Cache(__name__, _modified_time)
@@ -30,16 +30,16 @@
__M_writer(unicode( h.link_to("Collections", h.url_for(controller='collection', action='list')) ))
__M_writer(u'</li>\n <li>')
# SOURCE LINE 15
- __M_writer(unicode( h.link_to("Add media", h.url_for(controller='page', action="addannodexform")) ))
+ __M_writer(unicode( h.link_to("Add media", h.url_for(controller='addmedia', action='index')) ))
__M_writer(u'</li>\n <li>')
# SOURCE LINE 16
- __M_writer(unicode( h.link_to("Playlists", h.url_for(controller='page', action="playlistpage")) ))
+ __M_writer(unicode( h.link_to("Playlists", h.url_for(controller='playlist', action="playlistpage")) ))
__M_writer(u'</li>\n <li>')
# SOURCE LINE 17
__M_writer(unicode( h.link_to("Help", h.url_for(controller='help', action='index')) ))
__M_writer(u'</li>\n <li><span class="searchpadding">\n')
# SOURCE LINE 19
- __M_writer(unicode( h.form(h.url_for(action='search'), multipart=True) ))
+ __M_writer(unicode( h.form(h.url_for(controller='page', action='search'), multipart=True) ))
__M_writer(u'\n')
# SOURCE LINE 20
__M_writer(unicode( h.text_field('searchterms', value="Search") ))
Modified: arkaiv/trunk/data/templates/autohandler.pyc
===================================================================
(Binary files differ)
More information about the commits
mailing list