1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-12-22 08:56:17 +00:00

Some housekeeping

Trying to make flake8 happy
This commit is contained in:
Alban Féron 2020-11-29 17:24:28 +01:00
parent 36cea89b26
commit f8018b2751
No known key found for this signature in database
GPG Key ID: 8CE0313646D16165
46 changed files with 81 additions and 91 deletions

View File

@ -15,9 +15,10 @@ from flask import Blueprint
from pony.orm import ObjectNotFound
from pony.orm import commit
from ..db import ClientPrefs, Folder
from ..managers.user import UserManager
from .exceptions import Unauthorized
from .exceptions import GenericError, Unauthorized
from .formatters import JSONFormatter, JSONPFormatter, XMLFormatter
api = Blueprint("api", __name__)

View File

@ -11,10 +11,8 @@ from pony.orm import select, desc, avg, max, min, count, between
from ..db import (
Folder,
Artist,
Album,
Track,
RatingFolder,
StarredFolder,
StarredArtist,
StarredAlbum,

View File

@ -5,15 +5,13 @@
#
# Distributed under terms of the GNU AGPLv3 license.
import sys
import time
import uuid
from flask import current_app, request
from pony.orm import delete
from pony.orm import ObjectNotFound
from ..db import Track, Album, Artist, Folder, User
from ..db import Track, Album, Artist, Folder
from ..db import StarredTrack, StarredAlbum, StarredArtist, StarredFolder
from ..db import RatingTrack, RatingFolder
from ..lastfm import LastFm
@ -22,10 +20,11 @@ from . import api, get_entity, get_entity_id
from .exceptions import AggregateException, GenericError, MissingParameter, NotFound
def star_single(cls, eid):
def star_single(cls, starcls, eid):
"""Stars an entity
:param cls: entity class, Folder, Artist, Album or Track
:param starcls: matching starred class, StarredFolder, StarredArtist, StarredAlbum or StarredTrack
:param eid: id of the entity to star
"""
@ -34,27 +33,24 @@ def star_single(cls, eid):
except ObjectNotFound:
raise NotFound("{} {}".format(cls.__name__, eid))
starred_cls = getattr(sys.modules[__name__], "Starred" + cls.__name__)
try:
starred_cls[request.user, eid]
starcls[request.user, eid]
raise GenericError("{} {} already starred".format(cls.__name__, eid))
except ObjectNotFound:
pass
starred_cls(user=request.user, starred=e)
starcls(user=request.user, starred=e)
def unstar_single(cls, eid):
def unstar_single(cls, starcls, eid):
"""Unstars an entity
:param cls: entity class, Folder, Artist, Album or Track
:param starcls: matching starred class, StarredFolder, StarredArtist, StarredAlbum or StarredTrack
:param eid: id of the entity to unstar
"""
starred_cls = getattr(sys.modules[__name__], "Starred" + cls.__name__)
delete(
s for s in starred_cls if s.user.id == request.user.id and s.starred.id == eid
)
delete(s for s in starcls if s.user.id == request.user.id and s.starred.id == eid)
return None
@ -81,12 +77,12 @@ def handle_star_request(func):
if tid is not None:
try:
func(Track, tid)
func(Track, StarredTrack, tid)
except Exception as e:
err = e
else:
try:
func(Folder, fid)
func(Folder, StarredFolder, fid)
except Exception as e:
err = e
@ -96,14 +92,14 @@ def handle_star_request(func):
for alId in albumId:
alb_id = get_entity_id(Album, alId)
try:
func(Album, alb_id)
func(Album, StarredAlbum, alb_id)
except Exception as e:
errors.append(e)
for arId in artistId:
art_id = get_entity_id(Artist, arId)
try:
func(Artist, art_id)
func(Artist, StarredArtist, art_id)
except Exception as e:
errors.append(e)

View File

@ -7,7 +7,6 @@
import re
import string
import uuid
from flask import current_app, request
from pony.orm import ObjectNotFound, select, count

View File

@ -7,7 +7,7 @@
from flask import request
from ..db import ChatMessage, User
from ..db import ChatMessage
from . import api

View File

@ -5,7 +5,6 @@
#
# Distributed under terms of the GNU AGPLv3 license.
from flask import current_app
from pony.orm import rollback
from pony.orm import ObjectNotFound
from werkzeug.exceptions import BadRequestKeyError
@ -27,7 +26,7 @@ def key_error(e):
@api.errorhandler(ObjectNotFound)
def not_found(e):
def object_not_found(e):
rollback()
return NotFound(e.entity.__name__)

View File

@ -7,7 +7,6 @@
# Distributed under terms of the GNU AGPLv3 license.
import hashlib
import io
import json
import logging
import mediafile
@ -16,7 +15,6 @@ import os.path
import requests
import shlex
import subprocess
import uuid
import zlib
from flask import request, Response, send_file
@ -27,14 +25,12 @@ from xml.etree import ElementTree
from zipfile import ZIP_DEFLATED
from zipstream import ZipFile
from .. import scanner
from ..cache import CacheMiss
from ..db import Track, Album, Artist, Folder, User, ClientPrefs, now
from ..db import Track, Album, Folder, now
from . import api, get_entity, get_entity_id
from .exceptions import (
GenericError,
MissingParameter,
NotFound,
ServerError,
UnsupportedParameter,
@ -168,7 +164,7 @@ def stream_media():
yield data
def kill_processes():
if dec_proc != None:
if dec_proc is not None:
dec_proc.kill()
proc.kill()
@ -194,7 +190,7 @@ def stream_media():
kill_processes()
raise
finally:
if dec_proc != None:
if dec_proc is not None:
dec_proc.stdout.close()
dec_proc.wait()
proc.stdout.close()

View File

@ -10,7 +10,7 @@ from flask import request
from ..db import RadioStation
from . import api, get_entity
from .exceptions import Forbidden, MissingParameter, NotFound
from .exceptions import Forbidden, MissingParameter
@api.route("/getInternetRadioStations.view", methods=["GET", "POST"])

View File

@ -12,7 +12,7 @@ from ..db import User
from ..managers.user import UserManager
from . import api, decode_password
from .exceptions import Forbidden, GenericError, NotFound
from .exceptions import Forbidden, NotFound
def admin_only(f):

View File

@ -16,7 +16,7 @@ from hashlib import sha1
from pony.orm import Database, Required, Optional, Set, PrimaryKey, LongStr
from pony.orm import ObjectNotFound, DatabaseError
from pony.orm import buffer
from pony.orm import min, max, avg, sum, count, exists
from pony.orm import min, avg, sum, count, exists
from pony.orm import db_session
from urllib.parse import urlparse, parse_qsl
from uuid import UUID, uuid4

View File

@ -6,7 +6,15 @@
#
# Distributed under terms of the GNU AGPLv3 license.
from flask import current_app, redirect, request, session, url_for
from flask import (
current_app,
flash,
redirect,
request,
render_template,
session,
url_for,
)
from flask import Blueprint
from functools import wraps
from pony.orm import ObjectNotFound

View File

@ -12,7 +12,7 @@ from flask import current_app
from functools import wraps
from pony.orm import ObjectNotFound
from ..db import User, ClientPrefs
from ..db import User
from ..lastfm import LastFm
from ..managers.user import UserManager

View File

@ -6,7 +6,6 @@
# Distributed under terms of the GNU AGPLv3 license.
import os.path
import uuid
from pony.orm import select
from pony.orm import ObjectNotFound

View File

@ -6,7 +6,8 @@
# Distributed under terms of the GNU AGPLv3 license.
import logging
import os, os.path
import os
import os.path
import mediafile
import time
@ -16,9 +17,7 @@ from queue import Queue, Empty as QueueEmpty
from threading import Thread, Event
from .covers import find_cover_in_folder, CoverFile
from .db import Folder, Artist, Album, Track, User
from .db import StarredFolder, StarredArtist, StarredAlbum, StarredTrack
from .db import RatingFolder, RatingTrack
from .db import Folder, Artist, Album, Track
logger = logging.getLogger(__name__)
@ -212,7 +211,6 @@ class Scanner(Thread):
return
mtime = int(stat.st_mtime)
size = stat.st_size
tr = Track.get(path=path)
if tr is not None:

View File

@ -32,7 +32,7 @@ def process_table(connection, table, fields, nullable_fields=()):
c.execute("SELECT {1} FROM {0}".format(table, ",".join(fields + nullable_fields)))
for row in c:
for field, value in zip(fields + nullable_fields, row):
if value is None or not isinstance(value, basestring):
if value is None or not isinstance(value, str):
continue
to_update[field].add(value)

View File

@ -1,7 +1,6 @@
import argparse
import hashlib
import psycopg2
import uuid
try:
bytes = buffer

View File

@ -23,13 +23,13 @@ def process_table(connection, table, fields):
c = connection.cursor()
for row in c.execute("SELECT {1} FROM {0}".format(table, ",".join(fields))):
for field, value in zip(fields, row):
if value is None or not isinstance(value, basestring):
if value is None or not isinstance(value, str):
continue
to_update[field].add(value)
for field, values in to_update.iteritems():
sql = "UPDATE {0} SET {1}=? WHERE {1}=?".format(table, field)
c.executemany(sql, map(lambda v: (buffer(UUID(v).bytes), v), values))
c.executemany(sql, map(lambda v: (UUID(v).bytes, v), values))
connection.commit()

View File

@ -1,7 +1,6 @@
import argparse
import hashlib
import sqlite3
import uuid
try:
bytes = buffer

View File

@ -7,7 +7,6 @@
#
# Distributed under terms of the GNU AGPLv3 license.
import io
import logging
import mimetypes

View File

@ -8,7 +8,6 @@
import re
from lxml import etree
from supysonic.managers.user import UserManager
from ..testbase import TestBase

View File

@ -5,7 +5,7 @@
#
# Distributed under terms of the GNU AGPLv3 license.
import uuid
import unittest
from pony.orm import db_session

View File

@ -5,6 +5,7 @@
#
# Distributed under terms of the GNU AGPLv3 license.
import unittest
import uuid
from pony.orm import db_session

View File

@ -8,6 +8,7 @@
import base64
import flask.json
import unittest
from xml.etree import ElementTree

View File

@ -6,9 +6,9 @@
# Distributed under terms of the GNU AGPLv3 license.
import time
import unittest
import uuid
from lxml import etree
from pony.orm import db_session
from supysonic.db import Folder, Artist, Album, Track
@ -43,7 +43,7 @@ class BrowseTestCase(ApiTestBase):
album = Album(name=letter + lether + "lbum", artist=artist)
for num, song in enumerate(["One", "Two", "Three"]):
track = Track(
Track(
disc=1,
number=num,
title=song,

View File

@ -8,6 +8,7 @@
import flask.json
import os.path
import requests
import unittest
from pony.orm import db_session
@ -32,7 +33,7 @@ class LyricsTestCase(ApiTestBase):
artist = Artist(name="Artist")
album = Album(artist=artist, name="Album")
track = Track(
Track(
title="23bytes",
number=1,
disc=1,

View File

@ -6,6 +6,7 @@
# Distributed under terms of the GNU AGPLv3 license.
import os.path
import unittest
import uuid
from contextlib import closing

View File

@ -5,6 +5,7 @@
#
# Distributed under terms of the GNU AGPLv3 license.
import unittest
import uuid
from pony.orm import db_session

View File

@ -87,18 +87,18 @@ class ResponseHelperJsonTestCase(TestBase, UnwrapperMixin.create_from(JSONFormat
self.assertIn("dict", resp)
self.assertIn("list", resp)
d = resp["dict"]
l = resp["list"]
dct = resp["dict"]
lst = resp["list"]
self.assertIn("value", d)
self.assertIn("list", d)
self.assertNotIn("emptyList", d)
self.assertIn("subdict", d)
self.assertIsInstance(d["value"], str)
self.assertIsInstance(d["list"], list)
self.assertIsInstance(d["subdict"], dict)
self.assertIn("value", dct)
self.assertIn("list", dct)
self.assertNotIn("emptyList", dct)
self.assertIn("subdict", dct)
self.assertIsInstance(dct["value"], str)
self.assertIsInstance(dct["list"], list)
self.assertIsInstance(dct["subdict"], dict)
self.assertEqual(l, [{"b": "B"}, {"c": "C"}, [4, 5, 6], "final string"])
self.assertEqual(lst, [{"b": "B"}, {"c": "C"}, [4, 5, 6], "final string"])
class ResponseHelperJsonpTestCase(TestBase, UnwrapperMixin.create_from(JSONPFormatter)):

View File

@ -40,7 +40,7 @@ class SearchTestCase(ApiTestBase):
album = Album(name=letter + lether + "lbum", artist=artist)
for num, song in enumerate(["One", "Two", "Three"]):
track = Track(
Track(
disc=1,
number=num,
title=song,

View File

@ -6,6 +6,8 @@
#
# Distributed under terms of the GNU AGPLv3 license.
import unittest
from .apitestbase import ApiTestBase

View File

@ -11,7 +11,7 @@ import sys
from flask import current_app
from pony.orm import db_session
from supysonic.db import Folder, Track
from supysonic.db import Track
from supysonic.managers.folder import FolderManager
from supysonic.scanner import Scanner
@ -23,7 +23,7 @@ class TranscodingTestCase(ApiTestBase):
super().setUp()
with db_session:
folder = FolderManager.add("Folder", "tests/assets/folder")
FolderManager.add("Folder", "tests/assets/folder")
scanner = Scanner()
scanner.queue_folder("Folder")
scanner.run()

View File

@ -6,6 +6,8 @@
#
# Distributed under terms of the GNU AGPLv3 license.
import unittest
from ..utils import hexlify
from .apitestbase import ApiTestBase

View File

@ -32,7 +32,7 @@ class DbTestCase(unittest.TestCase):
def create_some_folders(self):
root_folder = db.Folder(root=True, name="Root folder", path="tests")
child_folder = db.Folder(
db.Folder(
root=False,
name="Child folder",
path="tests/assets",
@ -40,7 +40,7 @@ class DbTestCase(unittest.TestCase):
parent=root_folder,
)
child_2 = db.Folder(
db.Folder(
root=False,
name="Child folder (No Art)",
path="tests/formats",
@ -158,10 +158,10 @@ class DbTestCase(unittest.TestCase):
root_folder, child_folder, _ = self.create_some_folders()
user = self.create_user()
star = db.StarredFolder(user=user, starred=root_folder)
rating_user = db.RatingFolder(user=user, rated=root_folder, rating=2)
db.StarredFolder(user=user, starred=root_folder)
db.RatingFolder(user=user, rated=root_folder, rating=2)
other = self.create_user("Other")
rating_other = db.RatingFolder(user=other, rated=root_folder, rating=5)
db.RatingFolder(user=other, rated=root_folder, rating=5)
root = root_folder.as_subsonic_child(user)
self.assertIn("starred", root)
@ -180,7 +180,7 @@ class DbTestCase(unittest.TestCase):
artist = db.Artist(name="Test Artist")
user = self.create_user()
star = db.StarredArtist(user=user, starred=artist)
db.StarredArtist(user=user, starred=artist)
artist_dict = artist.as_subsonic_artist(user)
self.assertIsInstance(artist_dict, dict)
@ -204,7 +204,7 @@ class DbTestCase(unittest.TestCase):
album = db.Album(artist=artist, name="Test Album")
user = self.create_user()
star = db.StarredAlbum(user=user, starred=album)
db.StarredAlbum(user=user, starred=album)
# No tracks, shouldn't be stored under normal circumstances
self.assertRaises(ValueError, album.as_subsonic_album, user)

View File

@ -5,7 +5,6 @@
#
# Distributed under terms of the GNU AGPLv3 license.
import io
import mutagen
import os
import os.path
@ -131,8 +130,6 @@ class ScannerTestCase(unittest.TestCase):
@db_session
def test_rescan_corrupt_file(self):
track = db.Track.select().first()
with self.__temporary_track_copy() as tf:
self.__scan()
self.assertEqual(db.Track.select().count(), 2)
@ -147,8 +144,6 @@ class ScannerTestCase(unittest.TestCase):
@db_session
def test_rescan_removed_file(self):
track = db.Track.select().first()
with self.__temporary_track_copy():
self.__scan()
self.assertEqual(db.Track.select().count(), 2)
@ -158,8 +153,6 @@ class ScannerTestCase(unittest.TestCase):
@db_session
def test_scan_tag_change(self):
folder = db.Folder[self.folderid]
with self.__temporary_track_copy() as tf:
self.__scan()
copy = db.Track.get(path=tf)

View File

@ -277,7 +277,7 @@ class CoverWatcherTestCase(WatcherTestCase):
self.assertIsNone(Folder.select().first().cover_art)
def test_naming_add_good(self):
bad = os.path.basename(self._addcover())
self._addcover()
self._sleep()
good = os.path.basename(self._addcover("cover"))
self._sleep()
@ -288,7 +288,7 @@ class CoverWatcherTestCase(WatcherTestCase):
def test_naming_add_bad(self):
good = os.path.basename(self._addcover("cover"))
self._sleep()
bad = os.path.basename(self._addcover())
self._addcover()
self._sleep()
with db_session:

View File

@ -5,7 +5,7 @@
#
# Distributed under terms of the GNU AGPLv3 license.
import uuid
import unittest
from pony.orm import db_session

View File

@ -6,6 +6,7 @@
#
# Distributed under terms of the GNU AGPLv3 license.
import unittest
import uuid
from pony.orm import db_session

View File

@ -5,6 +5,7 @@
#
# Distributed under terms of the GNU AGPLv3 license.
import unittest
import uuid
from pony.orm import db_session

View File

@ -5,6 +5,7 @@
#
# Distributed under terms of the GNU AGPLv3 license.
import unittest
import uuid
from flask import escape

View File

@ -13,7 +13,6 @@ import unittest
from pony.orm import db_session
from supysonic.db import init_database, release_database
from supysonic.db import Folder
from supysonic.managers.folder import FolderManager
from supysonic.scanner import Scanner

View File

@ -22,7 +22,7 @@ class Issue129TestCase(TestBase):
super().setUp()
with db_session:
folder = FolderManager.add("folder", os.path.abspath("tests/assets/folder"))
FolderManager.add("folder", os.path.abspath("tests/assets/folder"))
scanner = Scanner()
scanner.queue_folder("folder")
scanner.run()

View File

@ -12,7 +12,7 @@ import unittest
from pony.orm import db_session
from supysonic.db import init_database, release_database
from supysonic.db import Folder, Track
from supysonic.db import Track
from supysonic.managers.folder import FolderManager
from supysonic.scanner import Scanner

View File

@ -12,7 +12,6 @@ import unittest
from pony.orm import db_session
from supysonic.db import init_database, release_database
from supysonic.db import Folder, Track
from supysonic.managers.folder import FolderManager
from supysonic.scanner import Scanner

View File

@ -14,7 +14,6 @@ import unittest
from pony.orm import db_session
from supysonic.db import init_database, release_database
from supysonic.db import Folder
from supysonic.managers.folder import FolderManager
from supysonic.scanner import Scanner

View File

@ -13,7 +13,6 @@ import os
import shutil
import tempfile
import unittest
import uuid
from pony.orm import db_session, ObjectNotFound
@ -37,7 +36,7 @@ class FolderManagerTestCase(unittest.TestCase):
self.assertIsNotNone(FolderManager.add("media", self.media_dir))
self.assertIsNotNone(FolderManager.add("music", self.music_dir))
folder = db.Folder(
db.Folder(
root=False, name="non-root", path=os.path.join(self.music_dir, "subfolder")
)
@ -45,7 +44,7 @@ class FolderManagerTestCase(unittest.TestCase):
album = db.Album(name="Album", artist=artist)
root = db.Folder.get(name="media")
track = db.Track(
db.Track(
title="Track",
artist=artist,
album=album,

View File

@ -9,7 +9,6 @@
from supysonic import db
from supysonic.managers.user import UserManager
import io
import unittest
import uuid