Cleanup calls to sub tools

This commit is contained in:
Kovid Goyal 2007-08-17 15:58:32 +00:00
parent 40f7709ec0
commit 05291739db
2 changed files with 10 additions and 6 deletions

View File

@ -12,13 +12,14 @@
## You should have received a copy of the GNU General Public License along ## You should have received a copy of the GNU General Public License along
## with this program; if not, write to the Free Software Foundation, Inc., ## with this program; if not, write to the Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import os, sys, shutil, glob, logging import os, sys, shutil, glob, logging
from tempfile import mkdtemp from tempfile import mkdtemp
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
from libprs500.ebooks.lrf import option_parser as lrf_option_parser from libprs500.ebooks.lrf import option_parser as lrf_option_parser
from libprs500.ebooks import ConversionError from libprs500.ebooks import ConversionError
from libprs500.ebooks.lrf.html.convert_from import process_file as html_process_file from libprs500.ebooks.lrf.html.convert_from import process_file as html_process_file
from libprs500 import isosx, __appname__, setup_cli_handlers from libprs500 import isosx, __appname__, setup_cli_handlers, iswindows
CLIT = 'clit' CLIT = 'clit'
if isosx and hasattr(sys, 'frameworks_dir'): if isosx and hasattr(sys, 'frameworks_dir'):
CLIT = os.path.join(sys.frameworks_dir, CLIT) CLIT = os.path.join(sys.frameworks_dir, CLIT)
@ -33,10 +34,13 @@ def generate_html(pathtolit, logger):
if not os.access(pathtolit, os.R_OK): if not os.access(pathtolit, os.R_OK):
raise ConversionError, 'Cannot read from ' + pathtolit raise ConversionError, 'Cannot read from ' + pathtolit
tdir = mkdtemp(prefix=__appname__+'_') tdir = mkdtemp(prefix=__appname__+'_')
cmd = ' '.join([CLIT, '"'+pathtolit+'"', tdir]) os.rmdir(tdir)
sep = r'\\' if iswindows else os.path.sep
cmd = ' '.join([CLIT, '"'+pathtolit+'"', '"%s"'%(tdir+sep,)])
logger.debug(cmd)
p = Popen(cmd, shell=True, stderr=PIPE, stdout=PIPE) p = Popen(cmd, shell=True, stderr=PIPE, stdout=PIPE)
ret = p.wait()
logger.info(p.stdout.read()) logger.info(p.stdout.read())
ret = p.wait()
if ret != 0: if ret != 0:
shutil.rmtree(tdir) shutil.rmtree(tdir)
err = p.stderr.read() err = p.stderr.read()

View File

@ -18,7 +18,7 @@ from libprs500.ebooks.lrf import option_parser as lrf_option_parser
from libprs500.ebooks.metadata.meta import get_metadata from libprs500.ebooks.metadata.meta import get_metadata
from libprs500.ebooks.lrf.html.convert_from import process_file as html_process_file from libprs500.ebooks.lrf.html.convert_from import process_file as html_process_file
from libprs500.ebooks import ConversionError from libprs500.ebooks import ConversionError
from libprs500 import isosx, setup_cli_handlers from libprs500 import isosx, setup_cli_handlers, __appname__
UNRTF = 'unrtf' UNRTF = 'unrtf'
if isosx and hasattr(sys, 'frameworks_dir'): if isosx and hasattr(sys, 'frameworks_dir'):
@ -31,7 +31,7 @@ def option_parser():
) )
def generate_html(rtfpath, logger): def generate_html(rtfpath, logger):
tdir = tempfile.mkdtemp(prefix='rtf2lrf_') tdir = tempfile.mkdtemp(prefix=__appname__+'_')
cwd = os.path.abspath(os.getcwd()) cwd = os.path.abspath(os.getcwd())
os.chdir(tdir) os.chdir(tdir)
try: try: