tags 161225 + patch pending thanks * Martin Michlmayr <[EMAIL PROTECTED]> [2002-09-17 21:18]: > When I specify the --edit-cddb option and imprive the CDDB entry, jack > should ask me if I want to submit the updated version back to freedb. > It could simply generate the md5sum before I edit the file and prompt > "Do you want to submit this updated information? Y/N" if the md5sum > doesn't match anymore. Also, it would have to update "Revision" > header in the CDDB info.
I've implemented this now. diff -urN jack-3.1.1~/jack_freedb.py jack-3.1.1/jack_freedb.py --- jack-3.1.1~/jack_freedb.py 2005-07-28 14:43:19.734153256 +0100 +++ jack-3.1.1/jack_freedb.py 2005-07-28 16:17:22.075387008 +0100 @@ -22,6 +22,9 @@ import os import locale import codecs +import tempfile +import shutil +import re import jack_playorder import jack_functions @@ -763,3 +766,43 @@ else: print "please set your e-mail address. aborting..." +def update_revision(file): + "Update the revision (and submitted-via) information in a FreeDB template" + + re_revision = re.compile(r"^#\s*Revision:\s*(\d+)") + re_agent = re.compile(r"^#\s*Submitted via:") + + tmp, tmpname = tempfile.mkstemp() + freedb_file = open(file, "r") + revision = 0 + comments = 1 + for line in freedb_file.readlines(): + rev = re_revision.match(line) + agent = re_agent.match(line) + if rev: + revision = int(rev.group(1)) + 1 + os.write(tmp, "# Revision: %d\n" % revision) + elif agent: + os.write(tmp, "# Submitted via: " + prog_name + " " + prog_version + "\n") + else: + if not line.startswith("#"): + # The 'Revisions' field is optional but should be set when you + # submit a new version. Therefore, after the comments check + # whether we've seen a revision and if not write one. + if comments: + if revision == 0: + revision += 1 + os.write(tmp, "# Revision: %d\n" % revision) + comments = 0 + os.write(tmp, line) + os.close(tmp) + freedb_file.close() + try: + shutil.copyfile(tmpname, file) + except IOError: + print "Cannot copy updated template over existing one." + try: + os.unlink(tmpname) + except IOError: + print "Cannot remove temporary file %s." % tmpname + diff -urN jack-3.1.1~/jack_prepare.py jack-3.1.1/jack_prepare.py --- jack-3.1.1~/jack_prepare.py 2005-07-28 14:43:19.736152952 +0100 +++ jack-3.1.1/jack_prepare.py 2005-07-28 16:17:20.542620024 +0100 @@ -20,6 +20,7 @@ import types import pprint import os, sys +import difflib, shutil import jack_playorder import jack_functions @@ -469,10 +470,10 @@ if err: error("invalid freedb file") else: - if cf['_freedb_submit']: - jack_freedb.do_freedb_submit(cf['_freedb_form_file'], cd_id) - elif cf['_freedb_mailsubmit']: + if cf['_freedb_mailsubmit']: jack_freedb.do_freedb_mailsubmit(cf['_freedb_form_file'], cd_id) + else: + jack_freedb.do_freedb_submit(cf['_freedb_form_file'], cd_id) ### (9) do query on start @@ -489,7 +490,33 @@ jack_display.exit() if cf['_edit_cddb']: + file = cf['_freedb_form_file'] + bakfile = file + ".bak" + if os.path.exists(file): + try: + shutil.copyfile(file, bakfile) + except IOError: + pass jack_utils.ex_edit(cf['_freedb_form_file']) + if os.path.exists(bakfile): + try: + f = open(file, "r") + b = open(bakfile, "r") + except IOError: + print "Could not open jack.freedb or jack.freedb.bak for comparison" + else: + pdiff = "".join(difflib.unified_diff(b.readlines(), f.readlines(), bakfile, file)) + f.close() + b.close() + if pdiff: + print + print "You made the following changes to the FreeDB file:" + print + print pdiff + x = raw_input("Would you like to submit these changes to the FreeDB server? (y/N) ") + if string.upper(x[0]) == "Y": + jack_freedb.update_revision(file) + freedb_submit() if cf['_query_on_start']: err, jack_tag.track_names, jack_tag.locale_names, freedb_rename, revision = jack_freedb.interpret_db_file(jack_ripstuff.all_tracks, todo, cf['_freedb_form_file'], verb = cf['_query_on_start'], dirs = 1) -- Martin Michlmayr http://www.cyrius.com/ -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]