/app-text/chm2pdf/files/tempdir.patch

https://github.com/1000timesdead/portage · Patch · 71 lines · 60 code · 11 blank · 0 comment · 0 complexity · 9509d5c0a1da54dea0aaa29772fc9bf1 MD5 · raw file

  1. --- chm2pdf-0.9.1.orig/chm2pdf 2008-07-09 12:42:26.000000000 +0200
  2. +++ chm2pdf-0.9.1/chm2pdf 2009-02-25 20:58:53.000000000 +0100
  3. @@ -27,6 +27,8 @@
  4. import os, os.path
  5. import re, glob
  6. import getopt
  7. +import tempfile
  8. +import shutil
  9. # from BeautifulSoup import BeautifulSoup
  10. global version
  11. @@ -39,8 +41,8 @@
  12. global filename #the input filename
  13. version = '0.9.1'
  14. -CHM2PDF_TEMP_WORK_DIR='/tmp/chm2pdf/work'
  15. -CHM2PDF_TEMP_ORIG_DIR='/tmp/chm2pdf/orig'
  16. +CHM2PDF_TEMP_WORK_DIR=tempfile.mkdtemp()
  17. +CHM2PDF_TEMP_ORIG_DIR=tempfile.mkdtemp()
  18. @@ -299,16 +301,6 @@
  19. # ########################### File extraction and correction: START ############################
  20. #
  21. if options['dontextract'] == '':
  22. -
  23. - try:
  24. - os.mkdir(CHM2PDF_TEMP_WORK_DIR)
  25. - except OSError: # The directory already exists.
  26. - pass
  27. -
  28. - try:
  29. - os.mkdir(CHM2PDF_TEMP_ORIG_DIR)
  30. - except OSError: # The directory already exists.
  31. - pass
  32. try:
  33. os.mkdir(CHM2PDF_ORIG_DIR)
  34. @@ -620,7 +612,7 @@
  35. 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.'
  36. print '\t--cookies \'name="value with space"; name=value\'\n\t\t'
  37. print '\t--datadir directory\n\t\tSpecifies the location of the HTMLDOC data files, usually /usr/share/htmldoc or C:\Program Files\HTMLDOC '
  38. - 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.'
  39. +# 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.'
  40. print '\t--duplex\n\t\tSpecifies that the output should be formatted for double-sided printing.'
  41. print '\t--effectduration {0.1..10.0}\n\t\tSpecifies the duration in seconds of PDF page transition effects.'
  42. print '\t--embedfonts\n\t\tSpecifies that fonts should be embedded in PDF output.'
  43. @@ -1084,13 +1076,6 @@
  44. print 'CHM file "' + filename + '" not found!'
  45. return
  46. - #remove temporary files
  47. - if options['dontextract'] == '':
  48. - if options['verbose']=='--verbose' and options['verbositylevel']=='high':
  49. - print 'Removing any previous temporary files...'
  50. - os.system('rm -r '+CHM2PDF_ORIG_DIR+'/*')
  51. - os.system('rm -r '+CHM2PDF_WORK_DIR+'/*')
  52. -
  53. cfile = chm.CHMFile()
  54. cfile.LoadCHM(filename)
  55. @@ -1105,6 +1090,8 @@
  56. os.system('extract_chmLib ' + filename + ' ' + CHM2PDF_ORIG_DIR + '&> /dev/null')
  57. convert_to_pdf(cfile, filename, outputfilename, options)
  58. + shutil.rmtree(CHM2PDF_TEMP_WORK_DIR)
  59. + shutil.rmtree(CHM2PDF_TEMP_ORIG_DIR)
  60. if __name__ == '__main__':