diff -r d8fccb2cd802 -r 468f4c8d3d5b mpdot/mpdot.py --- a/mpdot/mpdot.py Fri Apr 23 20:47:58 2010 +0100 +++ b/mpdot/mpdot.py Wed Aug 11 14:49:30 2010 +0100 @@ -45,7 +45,7 @@ #import xml from cStringIO import StringIO -__version__ = '0.1.3' +__version__ = '0.1.4' """ Nokia XHTML conversion: @@ -62,10 +62,10 @@ CMD_PREFIX_NERVOUS = "echo" #CMD_PREFIX_XSL = "/xsl:plugins/cxxapiref/xsl/dita2xhtml.nokia.xsl " -DIR_DOT_COMPONENT = 'dot_comp' -DIR_DOT_SOURCE = 'dot_src' -DIR_TOC_TMP = 'dot_toc_tmp' -DIR_DOT_TOC = 'dot_toc' +BUILD_DIR = 'build' +DIR_DOT_COMPONENT = os.path.join(BUILD_DIR, 'dot_comp') +DIR_TOC_TMP = os.path.join(BUILD_DIR, 'dot_toc_tmp') +DIR_DOT_TOC = os.path.join(BUILD_DIR, 'dot_toc') def invokeDot(theDitaMapPath, theDirOut, argList, isNervous): @@ -143,7 +143,7 @@ def execute(inToc, outDir, argList, numJobs=0, nervous=False): inDir = os.path.dirname(inToc) - outDirCmpDot = os.path.join(outDir, DIR_DOT_COMPONENT) + outDirCmpDot = os.path.join(os.path.dirname(outDir), DIR_DOT_COMPONENT) if not os.path.exists(outDirCmpDot): os.makedirs(outDirCmpDot) if numJobs >= 1: @@ -161,7 +161,7 @@ for t in genCompMapNames(inToc) ] myResults = [r.get() for r in [myPool.apply_async(invokeDot, t) for t in myTaskS]] - copyDirs(myResults, os.path.join(outDir, DIR_DOT_SOURCE)) + copyDirs(myResults, outDir) return myResults class DitamapLinkConverterError(Exception): @@ -208,7 +208,7 @@ if root is not None: with open(filepath, 'w') as f: f.write(""""""+'\n') - f.write(""""""+'\n') + f.write(""""""+'\n') f.write(etree.tostring(root)) f.close() @@ -231,19 +231,33 @@ def publish_toc(toc_path, out_dir, argList, nervous): toc_name = os.path.basename(toc_path) - tmp_out = os.path.join(out_dir, DIR_TOC_TMP) + tmp_out = os.path.join(os.path.dirname(out_dir), DIR_TOC_TMP) dlc = DitamapLinkConverter(toc_path, tmp_out) dlc.convert() toc_to_publish = os.path.join(tmp_out, toc_name) - out = os.path.join(out_dir, DIR_DOT_TOC) + out = os.path.join(os.path.dirname(out_dir), DIR_DOT_TOC) invokeDot(toc_to_publish, out, argList, nervous) - final_destination = os.path.join(out_dir, DIR_DOT_SOURCE) + final_destination = out_dir if not os.path.exists(final_destination): os.makedirs(final_destination) - try: - shutil.copy(os.path.join(out, 'index.html'), final_destination) - except IOError, err: - logging.error('publish_toc(): %s' % str(err)) + for item in os.listdir(out): + item_path = os.path.join(out, item) + try: + if os.path.isdir(item_path): + if os.path.exists(os.path.join(final_destination, item)): # The published toc's META-INF files etc. + shutil.rmtree(os.path.join(final_destination, item)) # will be the final ones in the publication, + shutil.copytree(item_path, os.path.join(final_destination, item)) # any existing ones will be overwritten + else: + shutil.copy(item_path, final_destination) + logging.info("Copied %s to %s" % (item_path, final_destination)) + except IOError, err: + logging.error("Couldn't copy %s to %s, error was '%s'" % (item_path, final_destination, str(err))) + +def clean(out_dir): + if os.path.exists(out_dir): + shutil.rmtree(out_dir) + if os.path.exists(os.path.join(os.path.dirname(out_dir), BUILD_DIR)): + shutil.rmtree(os.path.join(os.path.dirname(out_dir), BUILD_DIR)) def main(): usage = "usage: %prog [options] -Doptions without the -D" @@ -277,6 +291,7 @@ # Dump out timestamp print 'Start time: %s' % time.ctime() execTime = time.clock() + clean(args[1]) myResults = execute(args[0], args[1], args[2:], options.jobs, options.nervous) publish_toc(args[0], args[1], args[2:], options.nervous) print 'Number of DITA maps processed: %d' % len(myResults) @@ -354,7 +369,7 @@ self.assertRaises(DitamapLinkConverterError, dlc.convert) cmap = """ - + @@ -363,7 +378,7 @@ """ # converted_cmap = """ - +