From 6c9c498860be3e96bd85834bea0c6c02907cad4a Mon Sep 17 00:00:00 2001 From: Hanoh Haim Date: Wed, 20 Apr 2016 16:16:06 +0300 Subject: add new TOC --- images/Thumbs.db | Bin 590336 -> 601088 bytes images/icons/selected_tab_bg.png | Bin 0 -> 124 bytes images/icons/toggle.png | Bin 0 -> 135 bytes trex_book.asciidoc | 1 + trex_rpc_server_spec-docinfo.html | 6 + trex_rpc_server_spec.asciidoc | 1 + trex_stateless.asciidoc | 2 + trex_toc.asciidoc | 221 +++++++++++++++++++++++++++++++++++++ trex_vm_manual-docinfo.html | 6 + trex_vm_manual.asciidoc | 19 +++- ws_main.py | 225 +++++++++++++++++++++++++++++++++++--- wscript | 3 + 12 files changed, 463 insertions(+), 21 deletions(-) create mode 100644 images/icons/selected_tab_bg.png create mode 100644 images/icons/toggle.png create mode 100644 trex_rpc_server_spec-docinfo.html create mode 100644 trex_toc.asciidoc create mode 100644 trex_vm_manual-docinfo.html diff --git a/images/Thumbs.db b/images/Thumbs.db index a7cb4a90..893347af 100755 Binary files a/images/Thumbs.db and b/images/Thumbs.db differ diff --git a/images/icons/selected_tab_bg.png b/images/icons/selected_tab_bg.png new file mode 100644 index 00000000..16bb5d61 Binary files /dev/null and b/images/icons/selected_tab_bg.png differ diff --git a/images/icons/toggle.png b/images/icons/toggle.png new file mode 100644 index 00000000..84380cd0 Binary files /dev/null and b/images/icons/toggle.png differ diff --git a/trex_book.asciidoc b/trex_book.asciidoc index 2326f3ec..f13c63ae 100755 --- a/trex_book.asciidoc +++ b/trex_book.asciidoc @@ -10,6 +10,7 @@ TRex :toclevels: 4 include::trex_ga.asciidoc[] +include::trex_toc.asciidoc[] == Introduction diff --git a/trex_rpc_server_spec-docinfo.html b/trex_rpc_server_spec-docinfo.html new file mode 100644 index 00000000..6fb66a5e --- /dev/null +++ b/trex_rpc_server_spec-docinfo.html @@ -0,0 +1,6 @@ + + + + + + diff --git a/trex_rpc_server_spec.asciidoc b/trex_rpc_server_spec.asciidoc index 7df63553..1663830b 100755 --- a/trex_rpc_server_spec.asciidoc +++ b/trex_rpc_server_spec.asciidoc @@ -10,6 +10,7 @@ The TRex RPC Server :toclevels: 4 include::trex_ga.asciidoc[] +include::trex_toc.asciidoc[] == Change log diff --git a/trex_stateless.asciidoc b/trex_stateless.asciidoc index 303de5c5..4aad01e6 100755 --- a/trex_stateless.asciidoc +++ b/trex_stateless.asciidoc @@ -22,6 +22,8 @@ ifdef::backend-xhtml11[] endif::backend-xhtml11[] include::trex_ga.asciidoc[] +include::trex_toc.asciidoc[] + == Audience diff --git a/trex_toc.asciidoc b/trex_toc.asciidoc new file mode 100644 index 00000000..664370b9 --- /dev/null +++ b/trex_toc.asciidoc @@ -0,0 +1,221 @@ + +ifdef::backend-xhtml11[] +++++ +
+ +
+
+ Table of Contents +
+ + +
+ + + + + + + + + + + + + + + + + + + + + +++++ +endif::backend-xhtml11[] + diff --git a/trex_vm_manual-docinfo.html b/trex_vm_manual-docinfo.html new file mode 100644 index 00000000..6fb66a5e --- /dev/null +++ b/trex_vm_manual-docinfo.html @@ -0,0 +1,6 @@ + + + + + + diff --git a/trex_vm_manual.asciidoc b/trex_vm_manual.asciidoc index 7e22d54a..ec4c39c5 100755 --- a/trex_vm_manual.asciidoc +++ b/trex_vm_manual.asciidoc @@ -8,6 +8,8 @@ TRex Virtual Machine setup and basic usage include::trex_ga.asciidoc[] +include::trex_toc.asciidoc[] + == Introduction @@ -276,12 +278,14 @@ Once we have TRex up and running, we can enjoy the benefit of having live monito This can be easily done by following these steps: - 0. Download the latest version of TrexViewer application and install it using http://trex-tgn.cisco.com/trex/client_gui/setup.exe[this link]. - 1. Start the application and fill in the following: + +1. Download the latest version of TrexViewer application and install it using http://trex-tgn.cisco.com/trex/client_gui/setup.exe[this link]. + + +2. Start the application and fill in the following: + - Trex ip: `127.0.0.1:4500` - 2. Click the play button. +3. Click the play button. ifdef::backend-docbook[] image::images/trex_motinor_config.png[title="TRex viewer start screen",align="center",width=400,link="images/trex_motinor_config.png"] @@ -291,9 +295,7 @@ ifdef::backend-xhtml11[] image::images/trex_motinor_config.png[title="TRex viewer start screen",align="center",width=900,link="images/trex_motinor_config.png"] endif::backend-xhtml11[] - - - 3. **That's it!** + +**That's it!** + Now the live data from TRex will be displayed on the screen. ifdef::backend-docbook[] @@ -328,3 +330,8 @@ The VM runs TRex with single client and single server port. The traffic generate TRex identifies only the packets which were dedicately sent by one of those traffic ports and receives them in the other port. Hence, packets generated by client port will be received by the server port and vice versa. Ontop, network adapter #4 used to [underline]#listen# to all traffic generated by both of TRex's ports, therefore it is very useful in providing live data of the generated flows over the network. + + + + + diff --git a/ws_main.py b/ws_main.py index 849e68fa..73b35c51 100644 --- a/ws_main.py +++ b/ws_main.py @@ -12,11 +12,155 @@ APPNAME='wafdocs' import os, re, shutil import shlex import subprocess +import json + top = '.' out = 'build' +from HTMLParser import HTMLParser + +class CTocNode: + def __init__ (self): + self.name="root" + self.level=1; # 1,2,3,4 + self.parent=None + self.childs=[]; # link to CTocNode + + def get_link (self): + name=self.name + l=name.split('.'); + l=l[-1].lower() + s=''; + for c in l: + if c.isalpha() or c.isspace(): + s+=c + + return '#_'+'_'.join(s.lower().split()); + + + def add_new_child (self,name,level): + n=CTocNode(); + n.name=name; + n.level=level; + n.parent=self; + self.childs.append(n); + return n + + def to_json_childs (self): + l=[] + for obj in self.childs: + l.append(obj.to_json()); + return (l); + + def to_open (self): + if self.level <3: + return True + else: + return False + + + def to_json (self): + d={"text" : self.name, + "link" : self.get_link(), + "state" : { + "opened" : self.to_open() + } + } + if len(self.childs)>0 : + d["children"]= self.to_json_childs() + return d + + + +class TocHTMLParser(HTMLParser): + + def __init__ (self): + HTMLParser.__init__(self); + self.state=0; + self.root=CTocNode() + self.root.parent=self.root + self.level=2; + self.d={}; + self.last_level=1 + self.set_level(1,self.root) + + + def set_level (self,level,node): + assert(node!=None); + assert(isinstance(node,CTocNode)==True); + self.d[str(level)]=node + + # in case we change from high to low level remove the higher level + if level1): + return (True); + + def handle_starttag(self, tag, attrs): + if self.is_header (tag): + self.state=True; + self.level=int(tag[1]); + + def handle_endtag(self, tag): + if self.is_header (tag): + self.state=False; + + + def handle_data(self, data): + if self.state: + level=self.level + + cnode=self.get_level(level-1) + + n=cnode.add_new_child(data,level); + assert(n!=None); + self.set_level(level,n) + self.last_level=level + + def dump_as_json (self): + return json.dumps(self.root.to_json_childs(), sort_keys=False, indent=4) + + + + +def create_toc_json (input_file,output_file): + f = open (input_file) + l=f.readlines() + f.close(); + html_input = ''.join(l) + parser = TocHTMLParser() + parser.feed(html_input); + f = open (output_file,'w') + f.write(parser.dump_as_json()); + f.close(); + + + + re_xi = re.compile('''^(include|image)::([^.]*.(asciidoc|\\{PIC\\}))\[''', re.M) def ascii_doc_scan(self): p = self.inputs[0].parent @@ -96,6 +240,47 @@ def convert_to_pdf(task): os.system('a2x --no-xmllint -v -f pdf -d article %s -D %s ' %(task.inputs[0].abspath(),out_dir ) ) return (0) + + +def toc_fixup_file (input_file, + out_file, + json_file_name + ): + + file = open(input_file) + contents = file.read() + replaced_contents = contents.replace('input_replace_me.json', json_file_name) + file = open(out_file,'w') + file.write(replaced_contents) + file.close(); + + + +def convert_to_html_toc_book(task): + + input_file = task.inputs[0].abspath() + + json_out_file = os.path.splitext(task.outputs[0].abspath())[0]+'.json' + tmp = os.path.splitext(task.outputs[0].abspath())[0]+'.tmp' + json_out_file_short = os.path.splitext(task.outputs[0].name)[0]+'.json' + + cmd='{0} -a stylesheet={1} -a icons=true -a docinfo -d book -a max-width=55em -o {2} {3}'.format( + task.env['ASCIIDOC'], + task.inputs[1].abspath(), + tmp, + task.inputs[0].abspath()); + + os.system( cmd ) + + create_toc_json(tmp,json_out_file) + + toc_fixup_file(tmp,task.outputs[0].abspath(),json_out_file_short); + + os.system('rm {0}'.format(tmp)); + + + + def convert_to_pdf_book(task): input_file = task.outputs[0].abspath() out_dir = task.outputs[0].parent.get_bld().abspath() @@ -209,6 +394,14 @@ def build_cp(bld,dir,root,callback): + + + + + + + + def build(bld): bld(rule=my_copy, target='symbols.lang') @@ -252,13 +445,6 @@ def build(bld): bld(rule='${ASCIIDOC} -a stylesheet=${SRC[1].abspath()} -a icons=true -a max-width=55em -o ${TGT} ${SRC[0].abspath()}', source='release_notes.asciidoc waf.css', target='release_notes.html', scan=ascii_doc_scan) - - bld(rule='${ASCIIDOC} -a docinfo -a stylesheet=${SRC[1].abspath()} -a icons=true -a toc2 -a max-width=55em -d book -o ${TGT} ${SRC[0].abspath()}', - source='trex_book.asciidoc waf.css', target='trex_manual.html', scan=ascii_doc_scan) - - bld(rule='${ASCIIDOC} -a docinfo -a stylesheet=${SRC[1].abspath()} -a icons=true -a toc2 -a max-width=55em -d book -o ${TGT} ${SRC[0].abspath()}', - source='trex_stateless.asciidoc waf.css', target='trex_stateless.html', scan=ascii_doc_scan) - bld(rule='${ASCIIDOC} -a docinfo -a stylesheet=${SRC[1].abspath()} -a icons=true -a toc2 -a max-width=55em -d book -o ${TGT} ${SRC[0].abspath()}', source='draft_trex_stateless.asciidoc waf.css', target='draft_trex_stateless.html', scan=ascii_doc_scan) @@ -277,17 +463,26 @@ def build(bld): bld(rule=convert_to_pdf_book, source='trex_control_plane_design_phase1.asciidoc waf.css', target='trex_control_plane_design_phase1.pdf', scan=ascii_doc_scan) - bld(rule='${ASCIIDOC} -a stylesheet=${SRC[1].abspath()} -a icons=true -a toc2 -a max-width=55em -o ${TGT} ${SRC[0].abspath()}', - source='trex_vm_manual.asciidoc waf.css', target='trex_vm_manual.html', scan=ascii_doc_scan) + # with nice TOC + bld(rule=convert_to_html_toc_book, + source='trex_vm_manual.asciidoc waf.css', target='trex_vm_manual.html',scan=ascii_doc_scan) + + bld(rule=convert_to_html_toc_book, + source='trex_stateless.asciidoc waf.css', target='trex_stateless.html',scan=ascii_doc_scan); + + bld(rule=convert_to_html_toc_book, + source='trex_book.asciidoc waf.css', target='trex_manual.html',scan=ascii_doc_scan); + + bld(rule=convert_to_html_toc_book, + source='trex_rpc_server_spec.asciidoc waf.css', target='trex_rpc_server_spec.html',scan=ascii_doc_scan); + + bld(rule='${ASCIIDOC} -a stylesheet=${SRC[1].abspath()} -a icons=true -a toc2 -a max-width=55em -o ${TGT} ${SRC[0].abspath()}', source='vm_doc.asciidoc waf.css', target='vm_doc.html', scan=ascii_doc_scan) bld(rule='${ASCIIDOC} -a stylesheet=${SRC[1].abspath()} -a icons=true -a toc2 -a max-width=55em -o ${TGT} ${SRC[0].abspath()}', source='packet_builder_yaml.asciidoc waf.css', target='packet_builder_yaml.html', scan=ascii_doc_scan) - - bld(rule='${ASCIIDOC} -a stylesheet=${SRC[1].abspath()} -a icons=true -a toc2 -a max-width=55em -o ${TGT} ${SRC[0].abspath()}', - source='trex_rpc_server_spec.asciidoc waf.css', target='trex_rpc_server_spec.html', scan=ascii_doc_scan) bld(rule='${ASCIIDOC} -a stylesheet=${SRC[1].abspath()} -a icons=true -a toc2 -a max-width=55em -o ${TGT} ${SRC[0].abspath()}', source='trex_control_plane_design_phase1.asciidoc waf.css', target='trex_control_plane_design_phase1.html', scan=ascii_doc_scan) @@ -367,18 +562,18 @@ def release(bld): def publish(bld): # copy all the files to our web server remote_dir = "%s:%s" % ( Env().get_local_web_server(), Env().get_remote_release_path ()+'../doc/') - os.system('rsync -av --rsh=ssh build/ %s' % (remote_dir)) + os.system('rsync -av --del --rsh=ssh build/ %s' % (remote_dir)) def publish_ext(bld): from_ = 'build/' - os.system('rsync -avz -e "ssh -i %s" --rsync-path=/usr/bin/rsync %s %s@%s:%s/doc/' % (Env().get_trex_ex_web_key(),from_, Env().get_trex_ex_web_user(),Env().get_trex_ex_web_srv(),Env().get_trex_ex_web_path() ) ) + os.system('rsync -avz --del -e "ssh -i %s" --rsync-path=/usr/bin/rsync %s %s@%s:%s/doc/' % (Env().get_trex_ex_web_key(),from_, Env().get_trex_ex_web_user(),Env().get_trex_ex_web_srv(),Env().get_trex_ex_web_path() ) ) def publish_test(bld): # copy all the files to our web server remote_dir = "%s:%s" % ( Env().get_local_web_server(), Env().get_remote_release_path ()+'../test/') - os.system('rsync -av --rsh=ssh build/ %s' % (remote_dir)) + os.system('rsync -av --del --rsh=ssh build/ %s' % (remote_dir)) diff --git a/wscript b/wscript index f935668f..187a5528 100755 --- a/wscript +++ b/wscript @@ -24,6 +24,9 @@ def configure(conf): ws_main.configure(conf) +def create_toc (bld): + ws_main.create_toc(bld) + def build(bld): ws_main.build(bld) -- cgit