2 |
import mimetypes |
import mimetypes |
3 |
import os |
import os |
4 |
import os.path |
import os.path |
|
import rfc822 |
|
5 |
|
|
6 |
class GenImages: |
class GenImages: |
7 |
"""This class does XXX, brutally.""" # XXX |
"""This class does XXX, brutally.""" # XXX |
16 |
"""Constructor. files is a list of mediaserver block filenames.""" |
"""Constructor. files is a list of mediaserver block filenames.""" |
17 |
self.files = files |
self.files = files |
18 |
|
|
|
def readHeaders(self, file): |
|
|
"""Reads headers from a mediaserver block (file object).""" |
|
|
headers = {} |
|
|
for k in rfc822.Message(file).headers: |
|
|
key, value = k.split(': ') |
|
|
headers[key] = value.strip() |
|
|
return headers |
|
|
|
|
|
|
|
|
def stripBlock(self, inFilename, outFilename): |
|
|
"""Strips headers from a mediaserver block and writes rest of it to a tempfile.""" |
|
|
inFile = open(inFilename, 'rb') |
|
|
outFile = open(outFilename, 'wb') |
|
|
self.readHeaders(inFile) |
|
|
for a in inFile.readlines(): # 'for in inFile' (python 2.2) |
|
|
outFile.write(a) |
|
|
inFile.close() |
|
|
outFile.close() |
|
|
|
|
19 |
def pdfToPnm(self, file, resolution): |
def pdfToPnm(self, file, resolution): |
20 |
"""Pipes rest of the file to GS, returns list of image filenames.""" |
"""Pipes rest of the file to GS, returns list of image filenames.""" |
21 |
blockId = file.name[2:] # b_foo becomes foo |
blockId = file.name[2:] # b_foo becomes foo |