1
from gourmet.plugin import ImporterPlugin
2
from gourmet.importers.importer import Tester
3
from gourmet.threadManager import get_thread_manager
4
from gourmet.importers.interactive_importer import InteractiveImporter
5
from gourmet import check_encodings
8
MAX_PLAINTEXT_LENGTH = 100000
10
class PlainTextImporter (InteractiveImporter):
12
name = 'Plain Text Importer'
14
def __init__ (self, filename):
15
self.filename = filename
16
InteractiveImporter.__init__(self)
19
if os.path.getsize(self.filename) > MAX_PLAINTEXT_LENGTH*16:
22
import gourmet.gtk_extras.dialog_extras as de
23
de.show_message(title=_('Big File'),
24
label=_('File %s is too big to import'%self.filename),
25
sublabel=_('Your file exceeds the maximum length of %s characters. You probably didn\'t mean to import it anyway. If you really do want to import this file, use a text editor to split it into smaller files and try importing again.')%MAX_PLAINTEXT_LENGTH,
26
message_type=gtk.MESSAGE_ERROR)
28
ifi = file(self.filename,'r')
29
data = '\n'.join(check_encodings.get_file(ifi))
32
return InteractiveImporter.do_run(self)
34
class PlainTextImporterPlugin (ImporterPlugin):
36
name = _('Plain Text file')
37
patterns = ['*.txt','[^.]*','*']
38
mimetypes = ['text/plain']
40
def test_file (self, filename):
41
'''Given a filename, test whether the file is of this type.'''
42
return -1 # we are a fallback option
44
def get_importer (self, filename):
45
return PlainTextImporter(filename=filename)