From 3f14c56860ff67e2d2a689fe3f362ad7a25631d5 Mon Sep 17 00:00:00 2001 From: Michaƫl Ball Date: Sun, 20 Dec 2015 15:22:16 +0000 Subject: Syntax improvements --- Gruntfile.js | 18 +++++++++--------- app.db | Bin 4096 -> 4096 bytes common/utils.py | 4 ++-- db/db_manager.py | 17 +++++++---------- library.py | 13 +++++++++---- mach2.py | 8 ++++---- 6 files changed, 31 insertions(+), 29 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index a220434..d7ec914 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,28 +1,28 @@ module.exports = function(grunt) { - var path = require("path"); + var path = require('path'); grunt.initConfig({ - pkg: grunt.file.readJSON("package.json"), + pkg: grunt.file.readJSON('package.json'), bower: { install: { options: { - targetDir: "static/scripts/libs", + targetDir: 'static/scripts/libs', install: true, cleanup: true, - layout: "byComponent" + layout: 'byComponent' } } }, run: { mach2: { - cmd: "python", - args: ["mach2.py"] + cmd: 'python', + args: ['mach2.py'] } } }); - grunt.loadNpmTasks("grunt-bower-task"); - grunt.loadNpmTasks("grunt-run"); + grunt.loadNpmTasks('grunt-bower-task'); + grunt.loadNpmTasks('grunt-run'); - grunt.task.registerTask("default", ["bower:install", "run:mach2"]); + grunt.task.registerTask('default', ['bower:install', 'run:mach2']); }; diff --git a/app.db b/app.db index 264137d..7493558 100644 Binary files a/app.db and b/app.db differ diff --git a/common/utils.py b/common/utils.py index 38ad5ed..a7489f9 100644 --- a/common/utils.py +++ b/common/utils.py @@ -13,7 +13,7 @@ def make_where_clause(params, join_operator="AND"): try: for (column, operator) in params.items(): condition_subphrase = "" - + if operator == "BETWEEN": condition_subphrase = " ".join(("%s", operator, ":%s1 AND :%s2")) @@ -22,7 +22,7 @@ def make_where_clause(params, join_operator="AND"): column)) else: condition_subphrase = " ".join(("%s", operator, ":%s")) - + where_items.append(condition_subphrase % (column, column)) where_statement = None diff --git a/db/db_manager.py b/db/db_manager.py index c55ac39..f9b10c3 100644 --- a/db/db_manager.py +++ b/db/db_manager.py @@ -1,7 +1,6 @@ import configparser import os import sqlite3 -import tempfile class DbManager: @@ -32,18 +31,16 @@ class DbManager: yield("{0};".format(sql)) table_name_ident = table_name.replace("\"", "\"\"") - res = cu.execute( - "PRAGMA table_info(\"{0}\")".format(table_name_ident)) + res = cu.execute("PRAGMA table_info(\"{0}\")".format( + table_name_ident)) column_names = [ str(table_info[1]) for table_info in res.fetchall()] q = """ SELECT 'INSERT INTO "{0}" VALUES({1})' FROM "{0}"; - """.format( - table_name_ident, - ",".join( - """'||quote("{0}")||'""".format( - col.replace( - "\"", "\"\"")) for col in column_names)) + """.format(table_name_ident, ",".join( + """'||quote("{0}")||'""".format( + col.replace( + "\"", "\"\"")) for col in column_names)) query_res = cu.execute(q) for row in query_res: yield("{0};".format(row[0])) @@ -82,7 +79,7 @@ class DbManager: self.conn.row_factory = sqlite3.Row - def __del__(self): + def export(self): if not os.path.isfile(self.config["DEFAULT"]["database"]): script = "" diff --git a/library.py b/library.py index 6cdb732..531a148 100755 --- a/library.py +++ b/library.py @@ -1,11 +1,12 @@ #!/usr/bin/env python import configparser import gevent -from gevent import queue +from gevent import monkey, queue import logging import mutagen import os +from db.db_manager import DbManager from models.track import Track @@ -24,6 +25,7 @@ def store_track_task(): def run(path=None): + db = DbManager() if path is not None: if os.path.isdir(path): store_dir(path) @@ -31,13 +33,15 @@ def run(path=None): store_file(path) else: store_dir("/media/Music") + db.export() def store_file(path): + logger = logging.getLogger("store_file") m = mutagen.File(path, easy=True) if m: if not Track.store(path, m): - print("Problem saving %s" % (path,)) + logger.error("Problem saving %s" % (path,)) def store_dir(path): @@ -50,10 +54,10 @@ def store_dir(path): file_path = "".join([root, "/", name]) file, ext = os.path.splitext(file_path) - if ext in allowed_extensions: + if ext.lower() in allowed_extensions: file_store.put(file_path) - logger.info("Storing tracks") + logger.info("Storing tracks") gevent.joinall([gevent.spawn(store_track_task)] * 6) logger.info("Done") @@ -88,6 +92,7 @@ def update_track_filename(oldpath, newpath): track.save() if __name__ == "__main__": + monkey.patch_all() config = configparser.ConfigParser() config.read("mach2.ini") diff --git a/mach2.py b/mach2.py index fdd86c2..8261019 100644 --- a/mach2.py +++ b/mach2.py @@ -1,17 +1,17 @@ +import base64 import configparser import json import mimetypes import os import sqlite3 -import subprocess import tempfile -import threading -from flask import Flask, Response, current_app, g, redirect, render_template +from flask import Flask, Response, g, redirect, render_template from flask import request, url_for from flask.ext.compress import Compress from flask.ext.login import LoginManager, current_user, login_required from flask.ext.login import login_user, logout_user +from gevent import subprocess from models.album import Album from models.artist import Artist @@ -66,7 +66,7 @@ def query_db(query, args=(), one=False): @login_manager.request_loader -def load_user(request): +def load_user_from_request(request): # first, try to login using the api_key url arg api_key = request.args.get('api_key', None) -- cgit v1.2.3