Defer set commit

This commit is contained in:
Ehmry - 2019-02-18 23:39:57 +01:00
parent be57e23685
commit 2c977bdc1e
1 changed files with 43 additions and 29 deletions

View File

@ -52,44 +52,57 @@ register_options_page(BlobsetsOptionsPage)
class IngestFile(BaseAction):
NAME = 'Ingest file to blob set'
def _ingest(self, track, file):
rootHex = tagger.config.setting[ROOT_HASH_KEY]
print("rootHex is ", rootHex)
mbid = track.metadata["musicbrainz_recordingid"]
path = file.filename
self.tagger.window.set_statusbar_message(
N_('Ingesting %(path)s...'), {'path': path})
_, ext = os.path.splitext(path)
p = Popen(["blobset", "repl"], stdin=PIPE, stdout=PIPE)
cmd = '(hex (commit (insert (load {}) (blob (path "{}")) "{}{}")))'.format(rootHex, path, mbid, ext)
def __init__(self):
super(IngestFile, self).__init__()
register_track_action(self)
self.root_sym = 0
self.blobset_process = Popen(["blobset", "repl"], stdin=PIPE, stdout=PIPE)
root_hex = tagger.config.setting[ROOT_HASH_KEY]
cmd = '(define root_{} (load {}))\n'.format(self.root_sym, root_hex)
print(cmd)
(stdout_data, stderr_data) = p.communicate(cmd.encode(encoding='UTF-8'))
new_root = stdout_data.decode().strip().strip('"')
print(new_root)
self.blobset_process.stdin.write(cmd.encode(encoding='UTF-8'))
self.blobset_process.stdin.flush()
print(self.blobset_process.stdout.readline().decode())
def _ingest_tracks(self, objs):
for track in objs:
if isinstance(track, Track):
for file in track.linked_files:
mbid = track.metadata["musicbrainz_recordingid"]
path = file.filename
self.tagger.window.set_statusbar_message(
N_('Ingesting %(path)s...'), {'path': path})
_, ext = os.path.splitext(path)
cmd = '(define root_{} (insert root_{} (blob (path "{}")) "{}{}"))\n'.format(self.root_sym+1, self.root_sym, path, mbid, ext)
print(cmd)
self.blobset_process.stdin.write(cmd.encode(encoding='UTF-8'))
self.blobset_process.stdin.flush()
self.tagger.window.set_statusbar_message(self.blobset_process.stdout.readline().decode())
self.root_sym = self.root_sym+1
break
cmd = '(hex (commit root_{}))\n'.format(self.root_sym)
print(cmd)
self.blobset_process.stdin.write(cmd.encode(encoding='UTF-8'))
self.blobset_process.stdin.flush()
output = self.blobset_process.stdout.readline()
new_root = output.decode().strip().strip('"')
print("new root is", new_root)
tagger.config.setting[ROOT_HASH_KEY] = new_root
self.tagger.window.set_statusbar_message(
N_('Root hash updated to %(hash)s.'),
{'hash': tagger.config.setting[ROOT_HASH_KEY]}
)
def _ingest_callback(self, track, result=None, error=None):
def _ingest_callback(self, result=None, error=None):
if error:
self.tagger.window.set_statusbar_message(
N_('%(mbid)s ingestion failed.'),
{'mbid': track.metadata["musicbrainz_recordingid"]}
)
self.tagger.window.set_statusbar_message('ingestion failed.')
def callback(self, objs):
rootHex = tagger.config.setting[ROOT_HASH_KEY]
print("current hash ", rootHex)
for obj in objs:
if isinstance(obj, Track):
for file in obj.linked_files:
thread.run_task(
partial(self._ingest, obj, file),
partial(self._ingest_callback, obj),
priority=2, thread_pool=file.tagger.save_thread_pool)
break
# communicate with the REPL on the save thread
thread.run_task(
partial(self._ingest_tracks, objs),
partial(self._ingest_callback),
priority=2, thread_pool=self.tagger.save_thread_pool)
class CopyIdToClipboard(BaseAction):
NAME = "Copy id Clipboard..."
@ -110,6 +123,7 @@ class CopyIdToClipboard(BaseAction):
clipboard = QtWidgets.QApplication.clipboard()
clipboard.setText('musicbrainz/release/{}'.format(mbid))
register_track_action(IngestFile())
IngestFile()
register_track_action(CopyIdToClipboard())
register_album_action(CopyIdToClipboard())