Tizen 2.1 base
[platform/upstream/hplip.git] / fax / filters / pstotiff
1 #!/usr/bin/env python
2
3 import os
4 import os.path
5 import time 
6 import sys
7 import tempfile
8
9 READ_SIZE = 8192
10
11 total_bytes_read = 0
12 temp_in_file = "-"
13
14 if (len(sys.argv) > 6):
15    temp_in_file = sys.argv[6] 
16
17 temp_out_handle, temp_out_fname = tempfile.mkstemp()
18
19 font = "-I/usr/share/cups/fonts"
20 device = "-sDEVICE=tiffg4 -dMaxStripSize=0 -r204x196 -dNOPAUSE -dBATCH -dSAFER -dPARANOIDSAFER -dSHORTERRORS -dWRITESYSTEMDICT -dGHOSTSCRIPT -sstdout=%stderr -sOutputFile=" + temp_out_fname + " " + temp_in_file
21
22 gs_command = "/usr/bin/gs" + " " + font + " " + device
23
24 exit_code = os.system(gs_command)
25
26 file_len = os.stat(temp_out_fname).st_size
27 if (file_len < READ_SIZE):
28     READ_SIZE = file_len
29
30 os.close(temp_out_handle)
31
32 out_handle = open(temp_out_fname, mode='rb')
33 while (total_bytes_read < file_len):
34       data = out_handle.read(READ_SIZE)
35       sys.stdout.write(data)
36       total_bytes_read += READ_SIZE
37 out_handle.close()
38
39 os.remove(temp_out_fname)
40 sys.exit(0)