Last active
April 4, 2016 03:27
-
-
Save Fedjmike/d901ba743ffbf31bbf79c8549058f733 to your computer and use it in GitHub Desktop.
merging releases
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def merge_into_release(self, dest_release, src_release): | |
"""Transfers all data from a release to another and removes the source. | |
Overwrites the destination where the release info differs. | |
There is never loss of user information.""" | |
#merge = replace in dest + remove in src | |
#move = insert in dest + remove in src | |
def move_actions(model, dest_id, src_id): | |
model.execute("update actions set object_id=? where object_id=?", src_id, dest_id) | |
def replace_attachments(model, dest_id, src_id): | |
model.execute("insert or replace into palettes (?, color1, color2, color3)" | |
" select color1, color2, color3 from palettes where id=?", dest_id, src_id) | |
model.execute("insert or replace into descriptions (?, description)" | |
" select description from descriptions where id=?", dest_id, src_id) | |
model.execute("insert or replace into links (?, type_id, target)" | |
" select type_id, target from links where id=?", dest_id, src_id) | |
def replace_tracks(model, dest_id, src_id): | |
(src_sides, dest_sides), _, _ = \ | |
zip(model.get_release_tracks(src_id) | |
model.get_release_tracks(dest_id)) | |
flatten = lambda lists: [item for list in lists for item in list] | |
track_pairs = zip(*map(flatten, [src_sides, dest_sides])) | |
if not all(src.runtime == dest.runtime for src, dest in track_pairs): | |
raise ValueError("Track list runtimes didn't match") | |
for track in dest_sides | |
with self.transaction() as model: | |
merge_tracks(self, dest_id, src_id) | |
move_actions(self, dest_id, src_id) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment