Skip to content
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

compatibility of IPFS plugin with Python 3 #2554

Merged
merged 2 commits into from Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 8 additions & 6 deletions beetsplug/ipfs.py
Expand Up @@ -147,6 +147,8 @@ def ipfs_add(self, album):
def ipfs_get(self, lib, query):
query = query[0]
# Check if query is a hash
# TODO: generalize to other hashes; probably use a multihash
# implementation
if query.startswith("Qm") and len(query) == 46:
self.ipfs_get_from_hash(lib, query)
else:
Expand Down Expand Up @@ -190,15 +192,15 @@ def ipfs_import(self, lib, args):
else:
lib_name = _hash
lib_root = os.path.dirname(lib.path)
remote_libs = lib_root + "/remotes"
remote_libs = os.path.join(lib_root, b"remotes")
if not os.path.exists(remote_libs):
try:
os.makedirs(remote_libs)
except OSError as e:
msg = "Could not create {0}. Error: {1}".format(remote_libs, e)
self._log.error(msg)
return False
path = remote_libs + "/" + lib_name + ".db"
path = os.path.join(remote_libs, lib_name.encode() + b".db")
if not os.path.exists(path):
cmd = "ipfs get {0} -o".format(_hash).split()
cmd.append(path)
Expand All @@ -209,7 +211,7 @@ def ipfs_import(self, lib, args):
return False

# add all albums from remotes into a combined library
jpath = remote_libs + "/joined.db"
jpath = os.path.join(remote_libs, b"joined.db")
jlib = library.Library(jpath)
nlib = library.Library(path)
for album in nlib.albums():
Expand Down Expand Up @@ -237,7 +239,7 @@ def ipfs_list(self, lib, args):
return

for album in albums:
ui.print_(format(album, fmt), " : ", album.ipfs)
ui.print_(format(album, fmt), " : ", album.ipfs.decode())

def query(self, lib, args):
rlib = self.get_remote_lib(lib)
Expand All @@ -246,8 +248,8 @@ def query(self, lib, args):

def get_remote_lib(self, lib):
lib_root = os.path.dirname(lib.path)
remote_libs = lib_root + "/remotes"
path = remote_libs + "/joined.db"
remote_libs = os.path.join(lib_root, b"remotes")
path = os.path.join(remote_libs, b"joined.db")
if not os.path.isfile(path):
raise IOError
return library.Library(path)
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.rst
Expand Up @@ -102,6 +102,7 @@ Fixes:
error message. Thanks to :user:`Mary011196`. :bug:`1676` :bug:`2508`
* :doc:`/plugins/web`: Avoid a crash when sending binary data, such as
Chromaprint fingerprints, in music attributes. :bug:`2542` :bug:`2532`
* :doc:`/plugins/ipfs`: Fix Python 3 compatibility.

Two plugins had backends removed due to bitrot:

Expand Down