Fix regression that was causing PDf conversion on windows to fail. Also update windows installer.

This commit is contained in:
Kovid Goyal 2008-05-22 12:55:05 -07:00
parent 0d4d03e3e0
commit 4fd3a1a191
2 changed files with 175 additions and 10 deletions

View File

@ -3,6 +3,7 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
''''''
import sys, os, subprocess, logging
from functools import partial
from calibre import isosx, setup_cli_handlers, filename_to_utf8, iswindows
from calibre.ebooks import ConversionError
from calibre.ptempfile import PersistentTemporaryDirectory
@ -10,10 +11,13 @@ from calibre.ebooks.lrf import option_parser as lrf_option_parser
from calibre.ebooks.lrf.html.convert_from import process_file as html_process_file
PDFTOHTML = 'pdftohtml'
popen = subprocess.Popen
if isosx and hasattr(sys, 'frameworks_dir'):
PDFTOHTML = os.path.join(getattr(sys, 'frameworks_dir'), PDFTOHTML)
if iswindows and hasattr(sys, 'frozen'):
PDFTOHTML = os.path.join(os.path.dirname(sys.executable), 'pdftohtml.exe')
popen = partial(subprocess.Popen, creationflags=0x08) # CREATE_NO_WINDOW=0x08 so that no ugly console is popped up
def generate_html(pathtopdf, logger):
'''
@ -25,13 +29,12 @@ def generate_html(pathtopdf, logger):
tdir = PersistentTemporaryDirectory('pdftohtml')
index = os.path.join(tdir, 'index.html')
# This is neccessary as pdftohtml doesn't always (linux) respect absolute paths
cmd = PDFTOHTML + ' -enc UTF-8 -noframes -p -nomerge "%s" "%s"'%(pathtopdf, os.path.basename(index))
cmd = (PDFTOHTML, '-enc', 'UTF-8', '-noframes', '-p', '-nomerge', pathtopdf, os.path.basename(index))
cwd = os.getcwd()
try:
os.chdir(tdir)
p = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE,
stdout=subprocess.PIPE)
p = popen(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
logger.info(p.stdout.read())
ret = p.wait()
if ret != 0:

View File

@ -27,9 +27,8 @@ ShowUnInstDetails show
;------------------------------------------------------------------------------------------------------
;Include Modern UI
!include "AddToPath.nsh"
!include "XPUI.nsh"
!define XPUI_SKIN "Windows XP"
!include "MUI2.nsh"
!include "WinMessages.nsh"
;------------------------------------------------------------------------------------------------------
;Variables
@ -37,7 +36,7 @@ Var STARTMENU_FOLDER
Var MUI_TEMP
!define PRODUCT_NAME "%(name)s"
!define XPUI_BRANDINGTEXT "${PRODUCT_NAME} created by Kovid Goyal"
BrandingText "${PRODUCT_NAME} created by Kovid Goyal"
!define PRODUCT_VERSION "%(version)s"
!define WEBSITE "https://calibre.kovidgoyal.net"
!define DEVCON "C:\devcon\i386\devcon.exe"
@ -48,6 +47,168 @@ Var MUI_TEMP
!define PDFTOHTML "C:\pdftohtml\pdftohtml.exe"
!define IMAGEMAGICK "C:\ImageMagick"
; ---------------PATH manipulation -----------------------------------------------------------------
; Registry key for changing the environment variables for all users on both XP and Vista
!define WriteEnvStr_RegKey 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
Function Trim ; Added by Pelaca
Exch $R1
Push $R2
Loop:
StrCpy $R2 "$R1" 1 -1
StrCmp "$R2" " " RTrim
StrCmp "$R2" "$\n" RTrim
StrCmp "$R2" "$\r" RTrim
StrCmp "$R2" ";" RTrim
GoTo Done
RTrim:
StrCpy $R1 "$R1" -1
Goto Loop
Done:
Pop $R2
Exch $R1
FunctionEnd
; input, top of stack = string to search for
; top of stack-1 = string to search in
; output, top of stack (replaces with the portion of the string remaining)
; modifies no other variables.
;
; Usage:
; Push "this is a long ass string"
; Push "ass"
; Call StrStr
; Pop $R0
; ($R0 at this point is "ass string")
!macro StrStr un
Function ${un}StrStr
Exch $R1 ; st=haystack,old$R1, $R1=needle
Exch ; st=old$R1,haystack
Exch $R2 ; st=old$R1,old$R2, $R2=haystack
Push $R3
Push $R4
Push $R5
StrLen $R3 $R1
StrCpy $R4 0
; $R1=needle
; $R2=haystack
; $R3=len(needle)
; $R4=cnt
; $R5=tmp
loop:
StrCpy $R5 $R2 $R3 $R4
StrCmp $R5 $R1 done
StrCmp $R5 "" done
IntOp $R4 $R4 + 1
Goto loop
done:
StrCpy $R1 $R2 "" $R4
Pop $R5
Pop $R4
Pop $R3
Pop $R2
Exch $R1
FunctionEnd
!macroend
!insertmacro StrStr ""
!insertmacro StrStr "un."
Function AddToPath
Exch $0
Push $1
Push $2
Push $3
; don't add if the path doesn't exist
IfFileExists "$0\*.*" "" AddToPath_done
ReadEnvStr $1 PATH
Push "$1;"
Push "$0;"
Call StrStr
Pop $2
StrCmp $2 "" "" AddToPath_done
Push "$1;"
Push "$0\;"
Call StrStr
Pop $2
StrCmp $2 "" "" AddToPath_done
GetFullPathName /SHORT $3 $0
Push "$1;"
Push "$3;"
Call StrStr
Pop $2
StrCmp $2 "" "" AddToPath_done
Push "$1;"
Push "$3\;"
Call StrStr
Pop $2
StrCmp $2 "" "" AddToPath_done
ReadRegStr $1 ${WriteEnvStr_RegKey} "PATH"
StrCmp $1 "" AddToPath_NTdoIt
Push $1
Call Trim
Pop $1
StrCpy $0 "$1;$0"
AddToPath_NTdoIt:
WriteRegExpandStr ${WriteEnvStr_RegKey} "PATH" $0
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
AddToPath_done:
Pop $3
Pop $2
Pop $1
Pop $0
FunctionEnd
Function un.RemoveFromPath
Exch $0
Push $1
Push $2
Push $3
Push $4
Push $5
Push $6
IntFmt $6 "%%c" 26 # DOS EOF
ReadRegStr $1 ${WriteEnvStr_RegKey} "PATH"
StrCpy $5 $1 1 -1 # copy last char
StrCmp $5 ";" +2 # if last char != ;
StrCpy $1 "$1;" # append ;
Push $1
Push "$0;"
Call un.StrStr ; Find `$0;` in $1
Pop $2 ; pos of our dir
StrCmp $2 "" unRemoveFromPath_done
; else, it is in path
# $0 - path to add
# $1 - path var
StrLen $3 "$0;"
StrLen $4 $2
StrCpy $5 $1 -$4 # $5 is now the part before the path to remove
StrCpy $6 $2 "" $3 # $6 is now the part after the path to remove
StrCpy $3 $5$6
StrCpy $5 $3 1 -1 # copy last char
StrCmp $5 ";" 0 +2 # if last char == ;
StrCpy $3 $3 -1 # remove last char
WriteRegExpandStr ${WriteEnvStr_RegKey} "PATH" $3
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
unRemoveFromPath_done:
Pop $6
Pop $5
Pop $4
Pop $3
Pop $2
Pop $1
Pop $0
FunctionEnd
;------------------------------------------------------------------------------------------------------
;General
@ -64,9 +225,6 @@ Var MUI_TEMP
;Vista redirects $SMPROGRAMS to all users without this
RequestExecutionLevel admin
; Manipulate the PATH variable for all users, not just the installing user.
!define ALL_USERS
;------------------------------------------------------------------------------------------------------
;Interface Settings
@ -383,6 +541,10 @@ class BuildEXE(build_exe):
cwd = os.getcwd()
try:
os.chdir(os.path.join('src', 'calibre', 'gui2', 'pictureflow'))
if os.path.exists('release'):
shutil.rmtree('release')
if os.path.exists('debug'):
shutil.rmtree('debug')
subprocess.check_call(['qmake', 'pictureflow-lib.pro'])
subprocess.check_call(['mingw32-make', '-f', 'Makefile.Release'])
os.chdir('PyQt')