author | Michel Szarindar <Michel.Szarindar@Nokia.com> |
Fri, 23 Apr 2010 20:47:58 +0100 | |
changeset 3 | d8fccb2cd802 |
parent 2 | 932c358ece3e |
child 4 | 468f4c8d3d5b |
permissions | -rw-r--r-- |
2
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
1 |
""" |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
2 |
Created on Feb 25, 2010 |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
3 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
4 |
@author: p2ross |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
5 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
6 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
7 |
Take as inmput the toc. Read for |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
8 |
<topicref format="ditamap" href="GUID-F59DFBA0-B60B-334A-9B18-4B4E1E756DFA.ditamap" navtitle="camera" /> |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
9 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
10 |
Create in output dir |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
11 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
12 |
out/dot_comp/camera_GUID-F59DFBA0-B60B-334A-9B18-4B4E1E756DFA/ |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
13 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
14 |
As the DOT target. |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
15 |
Run DOT as a sub-process. |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
16 |
Then copy all of the contents except the index.html into: |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
17 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
18 |
out/dot_src/ |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
19 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
20 |
Els stuff with ditamaps to dot_src/... |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
21 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
22 |
Then run DOT on input: |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
23 |
out/dot_src/<toc>.ditamap |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
24 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
25 |
Output: |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
26 |
out/dot_tgt/ |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
27 |
""" |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
28 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
29 |
import os |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
30 |
import sys |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
31 |
from optparse import OptionParser, check_choice |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
32 |
import subprocess |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
33 |
import multiprocessing |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
34 |
try: |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
35 |
from xml.etree import cElementTree as etree |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
36 |
except ImportError: |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
37 |
from xml.etree import ElementTree as etree |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
38 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
39 |
import logging |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
40 |
#import pprint |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
41 |
import random |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
42 |
import time |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
43 |
import shutil |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
44 |
import unittest |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
45 |
#import xml |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
46 |
from cStringIO import StringIO |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
47 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
48 |
__version__ = '0.1.3' |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
49 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
50 |
""" |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
51 |
Nokia XHTML conversion: |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
52 |
$> ant ... -Dtranstype=xhtml.nokia -Dargs.input=INPUT_DITAMAP |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
53 |
Nokia Eclipse Help conversion: |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
54 |
$> ant ... -Dtranstype=eclipsehelp.nokia -Dargs.eclipse.version=VERSION -Dargs.eclipse.provider="Nokia Corporation" -Dargs.input=INPUT_DITAMAP |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
55 |
""" |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
56 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
57 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
58 |
CMD_BASE = "ant -logger org.dita.dost.log.DITAOTBuildLogger -Doutercontrol=quiet" |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
59 |
CMD_PREFIX_INPUT = "-Dargs.input=" |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
60 |
CMD_PREFIX_OUTPUT = "-Doutput.dir=" |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
61 |
CMD_PREFIX_TEMP = "-Ddita.temp.dir=" |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
62 |
CMD_PREFIX_NERVOUS = "echo" |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
63 |
#CMD_PREFIX_XSL = "/xsl:plugins/cxxapiref/xsl/dita2xhtml.nokia.xsl " |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
64 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
65 |
DIR_DOT_COMPONENT = 'dot_comp' |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
66 |
DIR_DOT_SOURCE = 'dot_src' |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
67 |
DIR_TOC_TMP = 'dot_toc_tmp' |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
68 |
DIR_DOT_TOC = 'dot_toc' |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
69 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
70 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
71 |
def invokeDot(theDitaMapPath, theDirOut, argList, isNervous): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
72 |
myCmdList = [] |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
73 |
if isNervous: |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
74 |
myCmdList.append(CMD_PREFIX_NERVOUS) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
75 |
time.sleep(0.25 * random.random()) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
76 |
# Randomise the start time so that DOT does not create |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
77 |
# duplicate temp directories (0.001 sec name resolution). |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
78 |
time.sleep(1.0 * random.random()) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
79 |
myCmdList.append(CMD_BASE) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
80 |
myCmdList.append('%s"%s"' % (CMD_PREFIX_INPUT, theDitaMapPath)) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
81 |
myCmdList.append('%s"%s"' % (CMD_PREFIX_OUTPUT, theDirOut)) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
82 |
myCmdList.append('%s"%s"' % (CMD_PREFIX_TEMP, 'temp/%s' % os.path.basename(theDirOut))) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
83 |
myCmdList.extend(['-D%s' % a for a in argList]) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
84 |
myCmd = ' '.join(myCmdList).replace('\\', '/') |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
85 |
if not os.path.exists(theDirOut): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
86 |
os.makedirs(theDirOut) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
87 |
print 'invokeDot: "%s"' % myCmd |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
88 |
p = subprocess.Popen( |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
89 |
myCmd, |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
90 |
shell=True, |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
91 |
bufsize=-1, |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
92 |
# Direct stdout/stderr to a PIPE then forget them |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
93 |
stdout=subprocess.PIPE, |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
94 |
stderr=subprocess.PIPE, |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
95 |
#close_fds=True, |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
96 |
) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
97 |
(stdOut, stdErr) = p.communicate() |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
98 |
if len(stdErr) > 0: |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
99 |
print 'stdErr for: %s -> %s' % (theDitaMapPath, theDirOut) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
100 |
print stdErr |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
101 |
return p.returncode, theDirOut |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
102 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
103 |
def genCompMapNames(theToc): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
104 |
for ev, el in etree.iterparse(theToc): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
105 |
if el.tag == 'topicref': |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
106 |
myRef = el.get('href', None) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
107 |
if myRef is not None and myRef.endswith('.ditamap'): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
108 |
logging.debug('genCompMapNames(): %s -> %s' % (myRef, el.get('navtitle'))) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
109 |
yield myRef, el.get('navtitle') |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
110 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
111 |
def _copyDir(s, d, depth=0): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
112 |
"""Recursive copy of all but the top level index.html.""" |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
113 |
assert(os.path.isdir(s)) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
114 |
assert(os.path.isdir(d)) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
115 |
for n in os.listdir(s): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
116 |
pS = os.path.join(s, n) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
117 |
pD = os.path.join(d, n) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
118 |
if os.path.isfile(pS) \ |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
119 |
and (depth > 1 or n.lower() != 'index.html'): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
120 |
try: |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
121 |
shutil.copy(pS, pD) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
122 |
except (WindowsError, IOError), err: |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
123 |
logging.error('_copyDirs(): %s' % err) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
124 |
elif os.path.isdir(pS): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
125 |
if not os.path.exists(pD): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
126 |
os.makedirs(pD) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
127 |
_copyDir(pS, pD, depth=depth+1) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
128 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
129 |
def copyDirs(theResults, theOutDir): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
130 |
if not os.path.exists(theOutDir): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
131 |
os.makedirs(theOutDir) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
132 |
for c, d in theResults: |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
133 |
if c == 0: |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
134 |
print 'copyDirs(): "%s" to "%s"' % (os.path.basename(d), theOutDir) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
135 |
if not os.path.isdir(d): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
136 |
logging.error('copyDirs(): not a directory: %s' % d) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
137 |
elif not os.path.isdir(theOutDir): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
138 |
logging.error('copyDirs(): not a directory: %s' % theOutDir) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
139 |
else: |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
140 |
_copyDir(d, theOutDir) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
141 |
else: |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
142 |
logging.error('Not copying. Results code %d directory: %s' % (c, d)) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
143 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
144 |
def execute(inToc, outDir, argList, numJobs=0, nervous=False): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
145 |
inDir = os.path.dirname(inToc) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
146 |
outDirCmpDot = os.path.join(outDir, DIR_DOT_COMPONENT) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
147 |
if not os.path.exists(outDirCmpDot): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
148 |
os.makedirs(outDirCmpDot) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
149 |
if numJobs >= 1: |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
150 |
myPool = multiprocessing.Pool(processes=numJobs) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
151 |
else: |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
152 |
logging.info('Setting jobs to %d' % multiprocessing.cpu_count()) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
153 |
myPool = multiprocessing.Pool(processes=multiprocessing.cpu_count()) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
154 |
myTaskS = [ |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
155 |
( |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
156 |
os.path.join(inDir, t[0]), |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
157 |
os.path.join(outDirCmpDot, '%s_%s' % (t[1], t[0])), |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
158 |
argList, |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
159 |
nervous, |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
160 |
) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
161 |
for t in genCompMapNames(inToc) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
162 |
] |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
163 |
myResults = [r.get() for r in [myPool.apply_async(invokeDot, t) for t in myTaskS]] |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
164 |
copyDirs(myResults, os.path.join(outDir, DIR_DOT_SOURCE)) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
165 |
return myResults |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
166 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
167 |
class DitamapLinkConverterError(Exception): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
168 |
""" Raised if an invalid toc is input """ |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
169 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
170 |
class DitamapLinkConverter(): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
171 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
172 |
def __init__(self, toc_path, out_dir): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
173 |
self.out_dir = os.path.abspath(out_dir) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
174 |
self.toc_path = os.path.abspath(toc_path) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
175 |
self.toc_dir = os.path.dirname(self.toc_path) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
176 |
if not os.path.exists(self.out_dir): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
177 |
os.makedirs(self.out_dir) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
178 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
179 |
def _convert_link_to_html(self, link): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
180 |
if link.attrib["href"].endswith(".xml"): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
181 |
link.attrib["href"] = link.attrib["href"].replace(".xml", ".html") |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
182 |
link.attrib["scope"] = "peer" |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
183 |
link.attrib["format"] = "html" |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
184 |
return link |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
185 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
186 |
def _convert_links(self, tree): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
187 |
for element in tree.getiterator(): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
188 |
if element.attrib.get("href") != None: |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
189 |
element = self._convert_link_to_html(element) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
190 |
return tree |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
191 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
192 |
def _handle_map(self, ditamap): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
193 |
try: |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
194 |
root = etree.parse(ditamap).getroot() |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
195 |
except IOError, e: |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
196 |
logging.error("Component map \"%s\" does not exist" % ditamap) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
197 |
return |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
198 |
except Exception, e: |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
199 |
logging.error("%s could not be parsed: %s\n" % (ditamap, str(e))) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
200 |
return |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
201 |
root = self._convert_links(root) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
202 |
self._write_file(root, os.path.basename(ditamap)) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
203 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
204 |
def _write_file(self, root, file_name): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
205 |
filepath = self.out_dir+os.sep+file_name |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
206 |
logging.debug('Writing file \"%s\"' % filepath) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
207 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
208 |
if root is not None: |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
209 |
with open(filepath, 'w') as f: |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
210 |
f.write("""<?xml version="1.0" encoding="UTF-8"?>"""+'\n') |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
211 |
f.write("""<!DOCTYPE cxxAPIMap PUBLIC "-//NOKIA//DTD DITA C++ API Map Reference Type v0.5.0//EN" "dtd/cxxAPIMap.dtd" >"""+'\n') |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
212 |
f.write(etree.tostring(root)) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
213 |
f.close() |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
214 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
215 |
def _get_component_map_paths(self, tree): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
216 |
all_hrefs = [] |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
217 |
for element in tree.getiterator(): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
218 |
if element.tag == "topicref": |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
219 |
all_hrefs.append(self.toc_dir+os.sep+element.attrib["href"]) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
220 |
return all_hrefs |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
221 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
222 |
def convert(self): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
223 |
try: |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
224 |
tree = etree.parse(self.toc_path).getroot() |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
225 |
except Exception, e: |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
226 |
raise DitamapLinkConverterError("%s could not be parsed: %s\n" % (self.toc_path, str(e))) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
227 |
component_maps = self._get_component_map_paths(tree) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
228 |
for component_map in component_maps: |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
229 |
self._handle_map(component_map) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
230 |
shutil.copyfile(self.toc_path, self.out_dir+os.sep+os.path.basename(self.toc_path)) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
231 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
232 |
def publish_toc(toc_path, out_dir, argList, nervous): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
233 |
toc_name = os.path.basename(toc_path) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
234 |
tmp_out = os.path.join(out_dir, DIR_TOC_TMP) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
235 |
dlc = DitamapLinkConverter(toc_path, tmp_out) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
236 |
dlc.convert() |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
237 |
toc_to_publish = os.path.join(tmp_out, toc_name) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
238 |
out = os.path.join(out_dir, DIR_DOT_TOC) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
239 |
invokeDot(toc_to_publish, out, argList, nervous) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
240 |
final_destination = os.path.join(out_dir, DIR_DOT_SOURCE) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
241 |
if not os.path.exists(final_destination): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
242 |
os.makedirs(final_destination) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
243 |
try: |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
244 |
shutil.copy(os.path.join(out, 'index.html'), final_destination) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
245 |
except IOError, err: |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
246 |
logging.error('publish_toc(): %s' % str(err)) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
247 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
248 |
def main(): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
249 |
usage = "usage: %prog [options] <DITA map> <output directory> -Doptions without the -D" |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
250 |
parser = OptionParser(usage, version='%prog ' + __version__) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
251 |
parser.add_option( |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
252 |
"-l", "--loglevel", |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
253 |
type="int", |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
254 |
dest="loglevel", |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
255 |
default=30, |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
256 |
help="Log Level (debug=10, info=20, warning=30, [error=40], critical=50) [default: %default]" |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
257 |
) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
258 |
parser.add_option( |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
259 |
"-j", "--jobs", |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
260 |
type="int", |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
261 |
dest="jobs", |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
262 |
default=0, |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
263 |
help="Max processes when multiprocessing. Zero uses number of native CPUs [default: %default]" |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
264 |
) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
265 |
parser.add_option("-n", action="store_true", dest="nervous", default=False, |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
266 |
help="Nervous mode (do no harm). [default: %default]") |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
267 |
(options, args) = parser.parse_args() |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
268 |
logging.basicConfig(level=options.loglevel, stream=sys.stdout) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
269 |
if len(args) < 1 or not os.path.isfile(args[0]): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
270 |
parser.print_help() |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
271 |
parser.error("I can't do much without a path to the XML TOC.") |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
272 |
return 1 |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
273 |
if len(args) < 2: |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
274 |
parser.print_help() |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
275 |
parser.error("I need an output path.") |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
276 |
return 1 |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
277 |
# Dump out timestamp |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
278 |
print 'Start time: %s' % time.ctime() |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
279 |
execTime = time.clock() |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
280 |
myResults = execute(args[0], args[1], args[2:], options.jobs, options.nervous) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
281 |
publish_toc(args[0], args[1], args[2:], options.nervous) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
282 |
print 'Number of DITA maps processed: %d' % len(myResults) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
283 |
print 'End time: %s' % time.ctime() |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
284 |
print 'Elapsed time: %8.3f (s)' % (time.clock()-execTime) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
285 |
print 'Bye, bye...' |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
286 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
287 |
if __name__ == '__main__': |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
288 |
multiprocessing.freeze_support() |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
289 |
sys.exit(main()) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
290 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
291 |
class TestDitamapLinkConverter(unittest.TestCase): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
292 |
def setUp(self): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
293 |
self._create_test_dir() |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
294 |
self.dlc = DitamapLinkConverter('', self.out_dir) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
295 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
296 |
def tearDown(self): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
297 |
self._clean_test_dir() |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
298 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
299 |
def _create_test_dir(self): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
300 |
self.test_dir = "ditamap_link_converter_test_dir" |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
301 |
self.out_dir = self.test_dir+os.sep+"out" |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
302 |
self.cmap_path = self.test_dir+os.sep+"cmap.xml" |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
303 |
os.mkdir(self.test_dir) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
304 |
f = open(self.cmap_path, "w") |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
305 |
f.write(cmap) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
306 |
f.close() |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
307 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
308 |
def _clean_test_dir(self): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
309 |
shutil.rmtree(self.test_dir) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
310 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
311 |
def _write_string_to_file(self, string, filepath): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
312 |
f = open(filepath, "w") |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
313 |
f.write(string) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
314 |
f.close() |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
315 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
316 |
def test_i_can_change_a_link_to_an_xml_file_to_link_to_an_html_file(self): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
317 |
link = etree.Element("cxxStructRef", href="GUID-AE25CF37-B862-306B-B7B3-4A1226B83DA2.xml", navtitle="_SChannels") |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
318 |
link = self.dlc._convert_link_to_html(link) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
319 |
self.assertEquals(link.attrib["href"], "GUID-AE25CF37-B862-306B-B7B3-4A1226B83DA2.html") |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
320 |
self.assertTrue(link.get("scope", None) and link.attrib["scope"] == "peer") |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
321 |
self.assertTrue(link.get("format", None) and link.attrib["format"] == "html") |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
322 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
323 |
def test_i_can_find_all_link_elements_in_a_tree(self): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
324 |
tree = etree.parse(StringIO(cmap)) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
325 |
tree = self.dlc._convert_links(tree) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
326 |
self.assertTrue(tree.find("cxxStructRef").attrib["href"].endswith(".html")) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
327 |
self.assertTrue(tree.find("cxxFileRef").attrib["href"].endswith(".html")) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
328 |
self.assertTrue(tree.find("cxxClassRef").attrib["href"].endswith(".html")) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
329 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
330 |
def test_i_can_write_a_converted_map_to_an_output_directory(self): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
331 |
self.dlc._handle_map(self.cmap_path) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
332 |
self.assertTrue(os.path.exists(self.out_dir+os.sep+"cmap.xml")) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
333 |
self.assertEquals(open(self.out_dir+os.sep+"cmap.xml").read(), converted_cmap) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
334 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
335 |
def test_i_gracefully_handle_a_link_to_component_map_that_doesnt_exist(self): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
336 |
try: |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
337 |
self.dlc._handle_map("non_existsant_ditamap.ditamap") |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
338 |
except: |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
339 |
self.fail("Didn't handle a component ditamap that doesn't exist") |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
340 |
else: |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
341 |
pass # Expected (silently handled non existant map) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
342 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
343 |
def test_i_parse_all_hrefs_in_a_toc(self): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
344 |
converter = DitamapLinkConverter(os.getcwd()+os.sep+'toc.ditamap', self.out_dir) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
345 |
tree = etree.parse(StringIO(toc)) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
346 |
paths = converter._get_component_map_paths(tree) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
347 |
expected = [os.getcwd()+os.sep+"GUID-F59DFBA0-B60B-334A-9B18-4B4E1E756DFA.ditamap"] |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
348 |
self.assertEquals(paths, expected) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
349 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
350 |
def test_i_raise_an_exception_if_i_am_given_an_invalid_toc(self): |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
351 |
invalid_toc_path = self.test_dir+os.sep+"invalid_toc.xml" |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
352 |
self._write_string_to_file(invalid_toc, invalid_toc_path) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
353 |
dlc = DitamapLinkConverter(invalid_toc_path, self.out_dir) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
354 |
self.assertRaises(DitamapLinkConverterError, dlc.convert) |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
355 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
356 |
cmap = """<?xml version="1.0" encoding="UTF-8"?> |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
357 |
<!DOCTYPE cxxAPIMap PUBLIC "-//NOKIA//DTD DITA C++ API Map Reference Type v0.5.0//EN" "dtd/cxxAPIMap.dtd" > |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
358 |
<cxxAPIMap id="GUID-0D9E5D45-5A07-302C-BEB3-2D0252214F2E" title="wlmplatform"> |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
359 |
<cxxStructRef href="GUID-AE25CF37-B862-306B-B7B3-4A1226B83DA2.xml" navtitle="_SChannels" /> |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
360 |
<cxxFileRef href="GUID-E1984316-685F-394E-B71A-9816E1495C1F.xml" navtitle="wlanerrorcodes.h" /> |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
361 |
<cxxClassRef href="GUID-F795E994-BCB6-3040-872A-90F8ADFC75E7.xml" navtitle="MWlanMgmtNotifications" /> |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
362 |
</cxxAPIMap> |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
363 |
""" |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
364 |
# |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
365 |
converted_cmap = """<?xml version="1.0" encoding="UTF-8"?> |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
366 |
<!DOCTYPE cxxAPIMap PUBLIC "-//NOKIA//DTD DITA C++ API Map Reference Type v0.5.0//EN" "dtd/cxxAPIMap.dtd" > |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
367 |
<cxxAPIMap id="GUID-0D9E5D45-5A07-302C-BEB3-2D0252214F2E" title="wlmplatform"> |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
368 |
<cxxStructRef format="html" href="GUID-AE25CF37-B862-306B-B7B3-4A1226B83DA2.html" navtitle="_SChannels" scope="peer" /> |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
369 |
<cxxFileRef format="html" href="GUID-E1984316-685F-394E-B71A-9816E1495C1F.html" navtitle="wlanerrorcodes.h" scope="peer" /> |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
370 |
<cxxClassRef format="html" href="GUID-F795E994-BCB6-3040-872A-90F8ADFC75E7.html" navtitle="MWlanMgmtNotifications" scope="peer" /> |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
371 |
</cxxAPIMap>""" |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
372 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
373 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
374 |
toc = """<?xml version="1.0" encoding="UTF-8"?> |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
375 |
<!DOCTYPE map PUBLIC "-//OASIS//DTD DITA Map//EN" "map.dtd"> |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
376 |
<map id="GUID-445218BA-A6BF-334B-9337-5DCBD993AEB3" title="Symbian^3"> |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
377 |
<topichead id="GUID-6B11027F-F9AF-3FA0-8A9D-8EA68E3D0F8D" navtitle="Applications"> |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
378 |
<topichead id="GUID-4766FA96-56F3-3E37-9B2C-6F280673BBA1" navtitle="Camera Apps"> |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
379 |
<topichead id="GUID-34AB7AC3-E64C-39E0-B6B1-53FEF84566F2" navtitle="s60"> |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
380 |
<topichead id="GUID-4766FA96-56F3-3E37-9B2C-6F280673BBA1" navtitle="camera"> |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
381 |
<topicref format="ditamap" href="GUID-F59DFBA0-B60B-334A-9B18-4B4E1E756DFA.ditamap" navtitle="camera" /> |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
382 |
</topichead> |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
383 |
<topichead id="GUID-A0EFE059-67DA-372B-AB98-9DB79584972E" navtitle="camera_help" /> |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
384 |
</topichead> |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
385 |
</topichead> |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
386 |
</topichead> |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
387 |
</map> |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
388 |
""" |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
389 |
|
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
390 |
invalid_toc = """<?xml version="1.0" encoding="UTF-8"? |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
391 |
<!DOCTYPE map PUBLIC "-//OASIS//DTD DITA Map//EN" "map.dtd"> |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
392 |
<map id="GUID-445218BA-A6BF-334B-9337-5DCBD993AEB3" title="Symbian^3"> |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
393 |
<topichead id="GUID-6B11027F-F9AF-3FA0-8A9D-8EA68E3D0F8D" navtitle="Applications"> |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
394 |
<topichead id="GUID-4766FA96-56F3-3E37-9B2C-6F280673BBA1" navtitle="Camera Apps"> |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
395 |
<topichead id="GUID-34AB7AC3-E64C-39E0-B6B1-53FEF84566F2" navtitle="s60"> |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
396 |
<topichead id="GUID-4766FA96-56F3-3E37-9B2C-6F280673BBA1" navtitle="camera"> |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
397 |
<topicref format="ditamap" href="GUID-F59DFBA0-B60B-334A-9B18-4B4E1E756DFA.ditamap" navtitle="camera" /> |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
398 |
</topichead> |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
399 |
<topichead id="GUID-A0EFE059-67DA-372B-AB98-9DB79584972E" navtitle="camera_help" /> |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
400 |
</topichead> |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
401 |
</topichead> |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
402 |
</topichead> |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
403 |
</map> |
932c358ece3e
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff
changeset
|
404 |
""" |