Permalink
Browse files

Added basic header/footer system with imports for JavaScript librarie…

…s. Added validator for import utility and appropriate styling.
  • Loading branch information...
jbillo committed Sep 30, 2012
1 parent 71941d4 commit 43d8ff13efc1d4e3c8caa356e952da441ada59ab
View
@@ -37,7 +37,12 @@ def run(self):
while self.running:
# find the first unprocessed import task
- task = self.sa_session.query(ImportTask).filter(ImportTask.started == None).order_by(ImportTask.created).first()
+ try:
+ task = self.sa_session.query(ImportTask).filter(ImportTask.started == None).order_by(ImportTask.created).first()
+ except ex as OperationalError:
+ # Ran into this when my SQLite database was locked.
+ self.log.error(u'Operational error accessing database. Ensure it is not open by another process.')
+ break
if task != None:
# start processing it
task.started = datetime.utcnow()
@@ -113,11 +118,13 @@ def importFile(self, uri):
self.log.info(u'ImportFile called with uri %s', uri)
mtype = mimetypes.guess_type(uri)[0]
- if mtype == u'audio/mpeg':
- pass
- else:
+ if mtype != u'audio/mpeg':
self.log.info(u'Unsupported mime type %s. Ignoring file.', mtype)
+ # Try to read the metadata appropriately.
+ metadata = self.readMp3MetaData(uri)
+ print metadata
+
def readMp3MetaData(self, uri):
# TODO: check that the uri doesn't already exist
@@ -152,6 +159,8 @@ def readMp3MetaData(self, uri):
track.album = self.findAlbum(metadata['album'], metadata['albumsort'], metadata['musicbrainz_albumid'], metadata)
if track.album != None:
disc = self.findDisc(track.album, metadata['discnumber'], metadata['discsubtitle'], metadata['musicbrainz_discid'])
+
+ return track
def findArtist(name=None, name_sort=None, musicbrainz_id=None):
@@ -375,4 +384,4 @@ def findDisc(album=None, discnumber=None, discsubtitle=None, musicbrainz_id=None
def stop(self):
"""Cleans up the thread"""
self.log.info(u'%s.stop has been called', self.getName())
- self.running = False
+ self.running = False
View
@@ -18,7 +18,7 @@
# A plugin to help SQLAlchemy bind correctly to CherryPy threads
- # See http://www.defuze.org/archives/222-integrating-sqlalchemy-into-a-cherrypy-application.html
+# See http://www.defuze.org/archives/222-integrating-sqlalchemy-into-a-cherrypy-application.html
class SAEnginePlugin(plugins.SimplePlugin):
def __init__(self, bus):
plugins.SimplePlugin.__init__(self, bus)
@@ -65,14 +65,45 @@ def commit_transaction(self):
# defines the web application that is the default client
class Musik:
api = api.API()
+
+ def _header(self, **kwargs):
+ return templates.get_template('header.html').render(**kwargs)
+
+ def _footer(self, **kwargs):
+ return templates.get_template('footer.html').render(**kwargs)
+
+ def _render(self, template_name, **kwargs):
+ return templates.get_template(template_name).render(**kwargs)
+
+ # Render an entire page with the passed variables
+ def _render_page(self, template_names, **kwargs):
+ result = []
+
+ if type(template_names) != list:
+ # Create one-element list
+ template_names = [template_names]
+
+ result.append(self._header(**kwargs))
+
+ for template in template_names:
+ result.append(self._render(template, **kwargs))
+
+ result.append(self._footer(**kwargs))
+ return result
+
@cherrypy.expose
def index(self):
- return templates.get_template('index.html').render()
+ return self._render_page("index.html", **{
+ "title": "Home"
+ })
@cherrypy.expose
def importmedia(self):
- return templates.get_template('importmedia.html').render()
+ return self._render_page("importmedia.html", **{
+ "title": "Import Media",
+ "js_appends": ['importmedia/validator.js'],
+ })
# starts the web app. this call will block until the server goes down
@@ -0,0 +1,18 @@
+$(document).ready(function() {
+ $('.validate-error').hide();
+});
+
+$('#importmedia-form').submit(function() {
+ $('.validate-error').html('');
+ $('.validate-error').hide();
+
+ // Validate path
+ if ($('#path').val() == '') {
+ $('#validate-error-top').html("Please provide a valid path to continue.");
+ $('.validate-error').show();
+ $('#path').focus();
+ return false;
+ }
+
+ return true;
+});
Oops, something went wrong.

0 comments on commit 43d8ff1

Please sign in to comment.