Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
devsnd committed Oct 9, 2017
2 parents 79487b7 + 494a066 commit 04cf89b
Show file tree
Hide file tree
Showing 21 changed files with 28,253 additions and 11,997 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ matrix:

# command to install dependencies
install:
- "pip install --upgrade setuptools"
- "pip install cherrypy${CHERRYPY_VERSION} --no-use-wheel"
- "pip install coveralls pyyaml"
- "if [[ $TRAVIS_PYTHON_VERSION = 2.6 ]]; then pip install unittest2; fi"
Expand Down
7 changes: 7 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
---------

0.41.0 (2017-10-09)
- FIXED: Installing CherryMusic via pip (thanks to rjsberry)
- IMPROVEMENT: updated jPlayer to 2.9.2, improved mobile compatibility (thansk to Max Leiter)
- IMPROVEMENT: Increased List Directory Item Size (thansk to Max Leiter)
- IMPROVEMENT: Made usernames case-insensitive (thanks to Max Leiter)
- IMPROVEMENT: Changed download zip archive name (thanks to Max Leiter)

0.40.0 (2017-04-08)
- FEATURE: Added option to select Album Art Source for manual searches
- FIXED: Server refused to start when not able to detect cherrypy version
Expand Down
2 changes: 1 addition & 1 deletion cherrymusicserver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#python 2.6+ backward compability
from __future__ import unicode_literals

VERSION = "0.40.0"
VERSION = "0.41.0"
__version__ = VERSION
DESCRIPTION = "an mp3 server for your browser"
LONG_DESCRIPTION = """CherryMusic is a music streaming
Expand Down
2 changes: 1 addition & 1 deletion cherrymusicserver/httphandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def download(self, value):
_save_and_release_session()
zipmime = 'application/x-zip-compressed'
cherrypy.response.headers["Content-Type"] = zipmime
zipname = 'attachment; filename="music.zip"'
zipname = 'attachment; filename="CherryMusic-archive.zip"'
cherrypy.response.headers['Content-Disposition'] = zipname
basedir = cherry.config['media.basedir']
fullpath_filelist = [os.path.join(basedir, f) for f in filelist]
Expand Down
57 changes: 34 additions & 23 deletions cherrymusicserver/sqlitecache.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import traceback

from backport.collections import deque, Counter
from contextlib import closing
from operator import itemgetter

import cherrymusicserver as cherry
Expand Down Expand Up @@ -92,8 +93,10 @@ def __init__(self, connector=None):
self.db = self.conn.cursor()

#I don't care about journaling!
self.conn.execute('PRAGMA synchronous = OFF')
self.conn.execute('PRAGMA journal_mode = MEMORY')
with closing(self.conn.execute('PRAGMA synchronous = OFF')):
pass
with closing(self.conn.execute('PRAGMA journal_mode = MEMORY')):
pass
self.load_db_to_memory()

def file_db_in_memory(self):
Expand Down Expand Up @@ -310,27 +313,31 @@ def register_file_with_db(self, fileobj):


def add_to_file_table(self, fileobj):
cursor = self.conn.execute('INSERT INTO files (parent, filename, filetype, isdir) VALUES (?,?,?,?)', (fileobj.parent.uid if fileobj.parent else -1, fileobj.name, fileobj.ext, 1 if fileobj.isdir else 0))
rowid = cursor.lastrowid
with closing(self.conn.execute('INSERT INTO files (parent, filename, filetype, isdir) VALUES (?,?,?,?)', (fileobj.parent.uid if fileobj.parent else -1, fileobj.name, fileobj.ext, 1 if fileobj.isdir else 0))) as cursor:
rowid = cursor.lastrowid
fileobj.uid = rowid
return fileobj


def add_to_dictionary_table(self, filename):
word_ids = []
for word in set(SQLiteCache.searchterms(filename)):
wordrowid = self.conn.execute('''SELECT rowid FROM dictionary WHERE word = ? LIMIT 0,1''', (word,)).fetchone()
with closing(self.conn.execute('''SELECT rowid FROM dictionary WHERE word = ? LIMIT 0,1''', (word,))) as cursor:
wordrowid = cursor.fetchone()
if wordrowid is None:
wordrowid = self.conn.execute('''INSERT INTO dictionary (word) VALUES (?)''', (word,)).lastrowid
with closing(self.conn.execute('''INSERT INTO dictionary (word) VALUES (?)''', (word,))) as cursor:
wordrowid = cursor.lastrowid
else:
wordrowid = wordrowid[0]
word_ids.append(wordrowid)
return word_ids


def add_to_search_table(self, file_id, word_id_seq):
self.conn.executemany('INSERT INTO search (drowid, frowid) VALUES (?,?)',
((wid, file_id) for wid in word_id_seq))
with closing(
self.conn.executemany('INSERT INTO search (drowid, frowid) VALUES (?,?)',
((wid, file_id) for wid in word_id_seq))):
pass


def remove_recursive(self, fileobj, progress=None):
Expand Down Expand Up @@ -385,18 +392,19 @@ def remove_from_search(self, fileid):
'''remove all references to the given fileid from the search table.
returns a list of all wordids which had their last search references
deleted during this operation.'''
foundlist = self.conn.execute(
with closing(self.conn.execute(
'SELECT drowid FROM search' \
' WHERE frowid=?', (fileid,)) \
.fetchall()
' WHERE frowid=?', (fileid,))) as cursor:
foundlist = cursor.fetchall()
wordset = set([t[0] for t in foundlist])

self.conn.execute('DELETE FROM search WHERE frowid=?', (fileid,))
with closing(self.conn.execute('DELETE FROM search WHERE frowid=?', (fileid,))):
pass

for wid in set(wordset):
count = self.conn.execute('SELECT count(*) FROM search'
' WHERE drowid=?', (wid,)) \
.fetchone()[0]
with closing(self.conn.execute('SELECT count(*) FROM search'
' WHERE drowid=?', (wid,))) as cursor:
count = cursor.fetchone()[0]
if count:
wordset.remove(wid)
return wordset
Expand All @@ -407,12 +415,14 @@ def remove_all_from_dictionary(self, wordids):
if not wordids:
return
args = list(zip(wordids))
self.conn.executemany('DELETE FROM dictionary WHERE rowid=(?)', args)
with closing(self.conn.executemany('DELETE FROM dictionary WHERE rowid=(?)', args)):
pass


def remove_from_files(self, fileid):
'''deletes the given file id from the files table'''
self.conn.execute('DELETE FROM files WHERE rowid=?', (fileid,))
with closing(self.conn.execute('DELETE FROM files WHERE rowid=?', (fileid,))):
pass


def db_recursive_filelister(self, fileobj, factory=None):
Expand All @@ -437,10 +447,10 @@ def db_recursive_filelister(self, fileobj, factory=None):
def fetch_child_files(self, fileobj, sort=True, reverse=False):
'''fetches from files table a list of all File objects that have the
argument fileobj as their parent.'''
id_tuples = self.conn.execute(
'SELECT rowid, filename, filetype, isdir' \
' FROM files where parent=?', (fileobj.uid,)) \
.fetchall()
with closing(self.conn.execute(
'SELECT rowid, filename, filetype, isdir' \
' FROM files where parent=?', (fileobj.uid,))) as cursor:
id_tuples = cursor.fetchall()
if sort:
id_tuples = sorted(id_tuples, key=lambda t: t[1], reverse=reverse)
return (File(name + ext,
Expand Down Expand Up @@ -556,9 +566,10 @@ def factory(fs, db, parent):

def update_word_occurrences(self):
log.i(_('updating word occurrences...'))
self.conn.execute('''UPDATE dictionary SET occurrences = (
with closing(self.conn.execute('''UPDATE dictionary SET occurrences = (
select count(*) from search WHERE search.drowid = dictionary.rowid
)''')
)''')):
pass

def enumerate_fs_with_db(self, startpath, itemfactory=None):
'''
Expand Down
22 changes: 14 additions & 8 deletions cherrymusicserver/userdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,17 @@ def addUser(self, username, password, admin):
return False
user = User.create(username, password, admin)
try:
self.conn.execute('''
INSERT INTO users
(username, admin, password, salt)
VALUES (?,?,?,?)''',
(user.name, 1 if user.isadmin else 0, user.password, user.salt))
exists = self.conn.execute('SELECT username'
' FROM users WHERE lower(username) = lower(?)',
(username,)).fetchone()
if (not exists):
self.conn.execute('''
INSERT INTO users
(username, admin, password, salt)
VALUES (?,?,?,?)''',
(user.name, 1 if user.isadmin else 0, user.password, user.salt))
else:
raise sqlite3.IntegrityError;
except sqlite3.IntegrityError:
log.e('cannot create user "%s", already exists!' % user.name)
return False
Expand All @@ -82,7 +88,7 @@ def changePassword(self, username, newpassword):

newuser = User.create(username, newpassword, False) #dummy user for salt
self.conn.execute('''
UPDATE users SET password = ?, salt = ? WHERE username = ?
UPDATE users SET password = ?, salt = ? WHERE lower(username) = lower(?)
''', (newuser.password, newuser.salt, newuser.name) )
self.conn.commit()
return "success"
Expand All @@ -103,7 +109,7 @@ def auth(self, username, password):
return User.nobody()

rows = self.conn.execute('SELECT rowid, username, admin, password, salt'
' FROM users WHERE username = ?', (username,))\
' FROM users WHERE lower(username) = lower(?)', (username,))\
.fetchall()
assert len(rows) <= 1
if rows:
Expand Down Expand Up @@ -131,7 +137,7 @@ def getNameById(self, userid):
return username[0] if username else 'nobody'

def getIdByName(self, username):
res = self.conn.execute('''SELECT rowid FROM users WHERE username = ?''',(username,))
res = self.conn.execute('''SELECT rowid FROM users WHERE lower(username) = lower(?)''',(username,))
userid = res.fetchone()
if userid:
return userid[0]
Expand Down
2 changes: 1 addition & 1 deletion cmbootstrap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def bootstrap():
download it for you and put it in the folder in which currently
CherryMusic resides.
''')
if input("Download cherrypy now? (y/n)") == 'y':
if input("Download cherrypy now? (y/N)\n") in ('y', 'yes'):
inst = DependencyInstaller()
inst.install_cherrypy()
print('Successfully installed cherrymusic dependencies! You can now start cherrymusic.')
Expand Down
2 changes: 1 addition & 1 deletion devscripts/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@ def remove_whitespace(html):
html = remove_whitespace(html)

with open(MAIN_OUTPUT_HTML, 'w') as mainhtml:
mainhtml.write(html)
mainhtml.write(html)
2 changes: 1 addition & 1 deletion res/devel.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<!--REMOVE-END-->

<!--COMPRESS-JS-BEGIN out=res/dist/cherrymusic.dist.js-->
<script type="text/javascript" src="res/js/ext/jquery-1.10.2.js"></script>
<script type="text/javascript" src="res/js/ext/jquery-3.2.1.js"></script>
<script type="text/javascript" src="res/js/ext/json2.min.js"></script>
<script type="text/javascript" src="res/js/ext/jquery.jplayer.js"></script>
<script type="text/javascript" src="res/js/ext/jplayer.playlist.js"></script>
Expand Down
Loading

0 comments on commit 04cf89b

Please sign in to comment.