View Single Post
Old 09-04-2008, 10:37 AM   #115
ashkulz
Addict
ashkulz will become famous soon enoughashkulz will become famous soon enoughashkulz will become famous soon enoughashkulz will become famous soon enoughashkulz will become famous soon enoughashkulz will become famous soon enoughashkulz will become famous soon enough
 
ashkulz's Avatar
 
Posts: 350
Karma: 705
Join Date: Dec 2006
Location: Mumbai, India
Device: Kindle 1/REB 1200
Post

Quote:
Originally Posted by Nate the great View Post
I have a suggestion. At some point are you going to add file conversion to impserve? Given that it is running on a computer, we do have the processing cycles to spare.

My suggestion is that you prepare for the new feature by having impserve download incompatible files (like ZIP and PRC) to the content folder.
I'm open to suggestions on how this feature should work, and what exactly is it that is wanted. To be honest, I'd prefer that most of features like this should be done as plugins, which is why I added a plugin framework for impserve. If how to do such a plugin is not clear, I'm attaching a plugin which uses a 'hypothetical' command prc2imp to do the job.

Code:
# WARNING: this is untested code that I cooked up in 5 minutes. Take it only as an example!
import impserve
import os, subprocess

class PrcConverter(impserve.ProxyResponse):
    def get_response(self, url, headers, data):
        if not 'application/x-palm-prc' in headers['Content-Type']:
            return headers, data

        open('input.prc', 'w').write(data)

        # assuming a command prc2imp exists
	if not subprocess.call(['prc2imp', 'input.prc', '-o', 'output.imp']) or not os.path.isfile('output.imp'):
            return headers, data
 
        headers['Content-Type'] = 'application/x-softbook'
        data = open('output.imp').read()
        os.remove('input.prc')
        os.remove('output.imp')
        return headers, data
The only important parts are the 'Content-Type' part, which is what the server is returning as Content-Type. If you expect the server to get it wrong, add a file called mime.types in the impserve directory and add the following to it:
Code:
application/x-palm-prc   prc pdb
The other important part is where you do your conversion: here it is done via an external process (as mentioned earlier). Obviously, you'd have more code here (metadata extraction, error handling, etc) but requests like these should be handled as plugins, as some people may want them and some don't.

Last edited by ashkulz; 09-04-2008 at 10:43 AM.
ashkulz is offline   Reply With Quote