Lines 27-32
Link Here
|
27 |
import os, os.path |
27 |
import os, os.path |
28 |
import re, glob |
28 |
import re, glob |
29 |
import getopt |
29 |
import getopt |
|
|
30 |
import tempfile |
31 |
import shutil |
30 |
# from BeautifulSoup import BeautifulSoup |
32 |
# from BeautifulSoup import BeautifulSoup |
31 |
|
33 |
|
32 |
global version |
34 |
global version |
Lines 39-46
Link Here
|
39 |
global filename #the input filename |
41 |
global filename #the input filename |
40 |
|
42 |
|
41 |
version = '0.9.1' |
43 |
version = '0.9.1' |
42 |
CHM2PDF_TEMP_WORK_DIR='/tmp/chm2pdf/work' |
44 |
CHM2PDF_TEMP_WORK_DIR=tempfile.mkdtemp() |
43 |
CHM2PDF_TEMP_ORIG_DIR='/tmp/chm2pdf/orig' |
45 |
CHM2PDF_TEMP_ORIG_DIR=tempfile.mkdtemp() |
44 |
|
46 |
|
45 |
|
47 |
|
46 |
|
48 |
|
Lines 299-314
Link Here
|
299 |
# ########################### File extraction and correction: START ############################ |
301 |
# ########################### File extraction and correction: START ############################ |
300 |
# |
302 |
# |
301 |
if options['dontextract'] == '': |
303 |
if options['dontextract'] == '': |
302 |
|
|
|
303 |
try: |
304 |
os.mkdir(CHM2PDF_TEMP_WORK_DIR) |
305 |
except OSError: # The directory already exists. |
306 |
pass |
307 |
|
308 |
try: |
309 |
os.mkdir(CHM2PDF_TEMP_ORIG_DIR) |
310 |
except OSError: # The directory already exists. |
311 |
pass |
312 |
|
304 |
|
313 |
try: |
305 |
try: |
314 |
os.mkdir(CHM2PDF_ORIG_DIR) |
306 |
os.mkdir(CHM2PDF_ORIG_DIR) |
Lines 620-626
Link Here
|
620 |
print '\t--continuous\n\t\tSpecifies that the HTML sources are unstructured (plain web pages).\n\t\tNo page breaks are inserted between each file or URL in the output.' |
612 |
print '\t--continuous\n\t\tSpecifies that the HTML sources are unstructured (plain web pages).\n\t\tNo page breaks are inserted between each file or URL in the output.' |
621 |
print '\t--cookies \'name="value with space"; name=value\'\n\t\t' |
613 |
print '\t--cookies \'name="value with space"; name=value\'\n\t\t' |
622 |
print '\t--datadir directory\n\t\tSpecifies the location of the HTMLDOC data files, usually /usr/share/htmldoc or C:\Program Files\HTMLDOC ' |
614 |
print '\t--datadir directory\n\t\tSpecifies the location of the HTMLDOC data files, usually /usr/share/htmldoc or C:\Program Files\HTMLDOC ' |
623 |
print "\t--dontextract \n\t\tIf given, %s will not extract the HTML files from the given CHM file, but will use previously extracted copies from the temporary directory " %name + '(i.e. ' + CHM2PDF_TEMP_ORIG_DIR + ' and ' + CHM2PDF_TEMP_WORK_DIR + '). Usually you will use this option after you have used the \'--extract-only\' option to extract the files in order to correct them manually (in ' + CHM2PDF_TEMP_WORK_DIR + '). After the correction, a call with \'--dontextract\' will not overwrite your changes, but will use the corrected files instead.' |
615 |
# print "\t--dontextract \n\t\tIf given, %s will not extract the HTML files from the given CHM file, but will use previously extracted copies from the temporary directory " %name + '(i.e. ' + CHM2PDF_TEMP_ORIG_DIR + ' and ' + CHM2PDF_TEMP_WORK_DIR + '). Usually you will use this option after you have used the \'--extract-only\' option to extract the files in order to correct them manually (in ' + CHM2PDF_TEMP_WORK_DIR + '). After the correction, a call with \'--dontextract\' will not overwrite your changes, but will use the corrected files instead.' |
624 |
print '\t--duplex\n\t\tSpecifies that the output should be formatted for double-sided printing.' |
616 |
print '\t--duplex\n\t\tSpecifies that the output should be formatted for double-sided printing.' |
625 |
print '\t--effectduration {0.1..10.0}\n\t\tSpecifies the duration in seconds of PDF page transition effects.' |
617 |
print '\t--effectduration {0.1..10.0}\n\t\tSpecifies the duration in seconds of PDF page transition effects.' |
626 |
print '\t--embedfonts\n\t\tSpecifies that fonts should be embedded in PDF output.' |
618 |
print '\t--embedfonts\n\t\tSpecifies that fonts should be embedded in PDF output.' |
Lines 1084-1096
Link Here
|
1084 |
print 'CHM file "' + filename + '" not found!' |
1076 |
print 'CHM file "' + filename + '" not found!' |
1085 |
return |
1077 |
return |
1086 |
|
1078 |
|
1087 |
#remove temporary files |
|
|
1088 |
if options['dontextract'] == '': |
1089 |
if options['verbose']=='--verbose' and options['verbositylevel']=='high': |
1090 |
print 'Removing any previous temporary files...' |
1091 |
os.system('rm -r '+CHM2PDF_ORIG_DIR+'/*') |
1092 |
os.system('rm -r '+CHM2PDF_WORK_DIR+'/*') |
1093 |
|
1094 |
cfile = chm.CHMFile() |
1079 |
cfile = chm.CHMFile() |
1095 |
cfile.LoadCHM(filename) |
1080 |
cfile.LoadCHM(filename) |
1096 |
|
1081 |
|
Lines 1105-1110
Link Here
|
1105 |
os.system('extract_chmLib ' + filename + ' ' + CHM2PDF_ORIG_DIR + '&> /dev/null') |
1090 |
os.system('extract_chmLib ' + filename + ' ' + CHM2PDF_ORIG_DIR + '&> /dev/null') |
1106 |
|
1091 |
|
1107 |
convert_to_pdf(cfile, filename, outputfilename, options) |
1092 |
convert_to_pdf(cfile, filename, outputfilename, options) |
|
|
1093 |
shutil.rmtree(CHM2PDF_TEMP_WORK_DIR) |
1094 |
shutil.rmtree(CHM2PDF_TEMP_ORIG_DIR) |
1108 |
|
1095 |
|
1109 |
|
1096 |
|
1110 |
if __name__ == '__main__': |
1097 |
if __name__ == '__main__': |