2 # vim: filencoding=utf-8 foldmethod=indent
6 locale
.setlocale( locale
.LC_ALL
)
7 gettext
.bindtextdomain( 'text2utf', '/usr/share/locale/' )
8 gettext
.textdomain( 'text2utf' )
17 def write2zenity(msg
, msg_type
='info'):
19 os
.system('zenity --%s --text="%s" --title "text2utf"' % (msg_type
, msg
))
22 'zenity "file-input" dialog'
23 return commands
.getoutput('zenity --file-selection --multiple --separator="|" --title "text2utf"')
25 def write2stdout(msg
, msg_type
='info'):
27 print '%s: %s' % (msg_type
, msg
)
30 os
.system('dos2unix -U \'%s\'' % file)
31 kodowanie
=commands
.getoutput('/usr/bin/file \'%s\'' % file)
32 kodowanie
=kodowanie
[len(file)+2:]
33 iconv_cmd
= '/usr/bin/iconv --from-code=%s --to-code=utf-8 --output=\'%s\' \'%s\''
35 if ('UTF-8 Unicode' in kodowanie
):
37 elif ('ISO-8859 text' in kodowanie
):
38 from_enc
= 'iso-8859-2'
40 from_enc
= 'Windows-1250'
41 if not from_enc
is None:
42 os
.system(iconv_cmd
% (from_enc
, '%s.tmp' % file , file))
43 shutil
.move('%s.tmp' % file, file)
51 def printnow(self
, msg
, msg_type
="info"):
53 write2stdout(msg
, msg_type
)
55 write2zenity(msg
, msg_type
)
56 def pr(self
, msg
, msg_type
="info"):
58 self
.printnow(msg
, msg_type
)
60 if (msg_type
=="info"):
61 self
.storemsginfo
.append(msg
)
62 elif (msg_type
=="error"):
63 self
.storemsgerror
.append(msg
)
64 def printstored(self
):
66 if (len(self
.storemsginfo
)>0):
67 self
.printnow('\n'.join(self
.storemsginfo
), "info")
68 if (len(self
.storemsgerror
)>0):
69 self
.printnow('\n'.join(self
.storemsgerror
), "error")
73 def printout (msg
, msg_type
='info'):
76 if 'zenity' in sys
.argv
[1:]:
79 mname
, filenames
= '', [s
for s
in sys
.argv
[1:] if s
!= 'zenity']
82 filenames
= get_file(_('Chose text file to convert.')).split("|")
86 printout(_('Chose text file to convert.'), 'error')
88 if (len(filenames
)>1):
90 for i
in range(len(filenames
)):
91 mname
= filenames
.pop(0)
92 if not os
.path
.isfile(mname
):
93 printout( _('File:')+" %s " % (mname
)+_('not exist!'), 'error')
96 filesize
= os
.path
.getsize(mname
)
98 printout(_('Chosed file is too big!')+" %sMB" % (filesize
/(1024*1024) ) )
101 subconvert('%s' % mname
)
102 printout(_('Convertet file:')+" %s." % (os
.path
.basename(mname
)) )