Just FYI, this would be five lines of code if you were making a plugin for the calibre editor (not counting the boilerplate for the plugin)
Code:
from calibre.ebooks.oeb.polish.replace import rename_files
book = self.current_container
fmap = {f:f.replace(' ', '_') for f in book.manifest_id_map.itervalues() if ' ' in f}
if fmap:
rename_files(book, fmap)
Just replace the call to self.magnify_fonts() with the above code in the demo plugin
http://manual.calibre-ebook.com/crea...t-book-plugins
and you are done.