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