-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merging mopidy-local-sqlite and mopidy-local-images into mopidy-local #10
Conversation
❤️ |
Updated according to https://gist.github.com/jodal/6c011e327035cc4ad56dbc2e3c28f1eb (to my best knowledge) and tested basic functionality with Mopidy 3.0.0a6. |
uris_to_remove.add(track.uri) | ||
elif mtime > track.last_modified or args.force: | ||
uris_to_update.add(track.uri) | ||
uris_in_library.add(track.uri) | ||
|
||
logger.info('Removing %d missing tracks.', len(uris_to_remove)) | ||
logger.info("Removing %d missing tracks.", len(uris_to_remove)) | ||
for uri in uris_to_remove: | ||
library.remove(uri) | ||
|
||
for abspath in file_mtimes: | ||
relpath = os.path.relpath(abspath, media_dir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use Pathlib here and all through this next section:
relpath = abspath.relative_to(media_dir)
relpath = relpath.encode('utf-8') | ||
return 'local:track:%s' % urllib.quote(relpath) | ||
if isinstance(relpath, str): | ||
relpath = relpath.encode("utf-8") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "utf-8" argument is at least redundant.
If relpath
can contain "surrogateescape" encoded random bytes, which is the sane way to pass random bytes through Unicode text, this, and all other places where paths are encoded, should be changed to:
relpath = relpath.encode(errors="surrogateescape")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks really good! I'm comfortable merging this and doing any further improvement iteratively on the master branch, with some preleases inbetween the improvements 👍
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def check_dirs_and_files(config): | ||
if not os.path.isdir(config['local']['media_dir']): | ||
if not os.path.isdir(config["local"]["media_dir"]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from pathlib import Path
if not Path(config["local"]["media_dir"]).is_dir():
...
for root, dirs, files in os.walk(self._image_dir, topdown=False): | ||
for name in dirs: | ||
os.rmdir(os.path.join(root, name)) | ||
for name in files: | ||
os.remove(os.path.join(root, name)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be replaced with shutil.rmtree()
?
relpath = relpath.encode('utf-8') | ||
return 'local:track:%s' % urllib.quote(relpath) | ||
if isinstance(relpath, str): | ||
relpath = relpath.encode("utf-8") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "utf-8" argument is at least redundant.
If relpath
can contain "surrogateescape" encoded random bytes, which is the sane way to pass random bytes through Unicode text, this, and all other places where paths are encoded, should be changed to:
relpath = relpath.encode(errors="surrogateescape")
@jodal, @kingosticks: Thanks for reviewing! I don't know how much time I can spend on this short-term, so since this basically seems to work (at least for me), I'd also suggest just merging this and doing the rest iteratively... |
My initial attempt, don't judge too harshly ;-)
I split up the Local library into
LocalLibraryProvider
andLocalStorageProvider
, the latter being used bymopidy local scan
only. Otherwise, this is pretty straight-forward, no attempt at cleaning things up except for getting rid of some config settings that (probably) nobody used, anyway.I did some very basic testing, and it seems to basically work. One thing I noticed was that when scanning a large (~20,000 tracks) library,
mopidy local scan
uses several GB of memory. That's something we should investigate further.