SF.net SVN: fclient: [133] trunk/sandbox/fcp
Status: Pre-Alpha
Brought to you by:
jurner
|
From: <ju...@us...> - 2008-02-04 03:17:32
|
Revision: 133
http://fclient.svn.sourceforge.net/fclient/?rev=133&view=rev
Author: jurner
Date: 2008-02-03 19:17:38 -0800 (Sun, 03 Feb 2008)
Log Message:
-----------
added a few utility scripts
Added Paths:
-----------
trunk/sandbox/fcp/scripts/
trunk/sandbox/fcp/scripts/__init__.py
trunk/sandbox/fcp/scripts/fcpscripts_consts.py
trunk/sandbox/fcp/scripts/gen_docs.py
trunk/sandbox/fcp/scripts/gen_messagecheatsheet.py
Added: trunk/sandbox/fcp/scripts/__init__.py
===================================================================
--- trunk/sandbox/fcp/scripts/__init__.py (rev 0)
+++ trunk/sandbox/fcp/scripts/__init__.py 2008-02-04 03:17:38 UTC (rev 133)
@@ -0,0 +1 @@
+
Added: trunk/sandbox/fcp/scripts/fcpscripts_consts.py
===================================================================
--- trunk/sandbox/fcp/scripts/fcpscripts_consts.py (rev 0)
+++ trunk/sandbox/fcp/scripts/fcpscripts_consts.py 2008-02-04 03:17:38 UTC (rev 133)
@@ -0,0 +1,29 @@
+"""Some consts for scripts"""
+
+import os
+#**************************************************************************
+#
+#**************************************************************************
+FcpDir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+DocDir = os.path.join(FcpDir, 'doc')
+EpydocFolder = 'epydoc'
+EpydocDir = os.path.join(DocDir, EpydocFolder)
+
+FilenameMessageCheatSheet = 'MessageCheatSheet.html'
+
+WikiBaseUri = 'http://wiki.freenetproject.org/'
+WikiStartPage = WikiBaseUri + 'FreenetFCPSpec2Point0'
+WikiFcpPrefix = 'FCP2p0'
+
+#**************************************************************************
+# some helpers
+#**************************************************************************
+def saveCreateDir(directory):
+ if not os.path.isdir(directory):
+ os.mkdir(directory)
+
+def enshureDocDirExists():
+ saveCreateDir(DocDir)
+ saveCreateDir(EpydocDir)
+
+
\ No newline at end of file
Added: trunk/sandbox/fcp/scripts/gen_docs.py
===================================================================
--- trunk/sandbox/fcp/scripts/gen_docs.py (rev 0)
+++ trunk/sandbox/fcp/scripts/gen_docs.py 2008-02-04 03:17:38 UTC (rev 133)
@@ -0,0 +1,59 @@
+"""Generates epydoc documentation for the package
+
+gen_docs.py
+
+@note: the script assumes it is located in the scripts subdirectory of the fcp package
+@note: Use gen_docs.py -? or --help to print out this help text
+"""
+
+from __future__ import with_statement
+
+import sys, os
+from epydoc import cli
+import subprocess
+
+import fcpscripts_consts as consts
+import gen_messagecheatsheet
+#**************************************************************************************
+#
+#**************************************************************************************
+def main():
+ """"""
+
+ consts.enshureDocDirExists()
+ print 'calling epydoc'
+ sys.argv = [
+ __file__,
+ '-v',
+ '-o%s' % consts.EpydocDir,
+ '--src-code-tab-width', '4',
+ #'--debug',
+ consts.FcpDir,
+ ]
+ cli.cli()
+ print 'ok'
+
+ # create a redirect to 'epydoc/index.html'
+ print 'creating redirect'
+ with open(os.path.join(consts.DocDir, 'index.html'), 'w') as fp:
+ fp.write('''<html>
+ <head>
+ <meta http-equiv="Refresh" content="0; URL=%s">
+ </head>
+</html>
+''' % (consts.EpydocFolder + '/' + 'index.html') )
+
+ print 'done'
+
+#**************************************************************************************
+#
+#**************************************************************************************
+if __name__ == '__main__':
+ wantsHelp = len(sys.argv) > 1 and sys.argv[1] or None
+ if wantsHelp not in ('-?', '--help'):
+ sys.exit(main())
+
+ print __doc__
+
+
+
Added: trunk/sandbox/fcp/scripts/gen_messagecheatsheet.py
===================================================================
--- trunk/sandbox/fcp/scripts/gen_messagecheatsheet.py (rev 0)
+++ trunk/sandbox/fcp/scripts/gen_messagecheatsheet.py 2008-02-04 03:17:38 UTC (rev 133)
@@ -0,0 +1,203 @@
+"""Dumps a cheatsheet for all Fcp messages as taken from the freenet wiki to 'MessageCheatSheet.html'
+
+gen_cheatsheet.py [path-to-tidy-executable]
+
+@note: this script assumes it is located in the 'scripts' folder of the fcp package
+@note: tidy has to be installed
+@note: if tidy can not be run by typing 'tidy' into your shell, you have to pass
+the full path to the tidy executable
+@note: the script will dump documentations for Fcp messages from the freenet wiki [http://wiki.freenetproject.org/].
+If you don't like that, don't use this script.
+@note: the cheat sheet comes equipped with anchors to jump to a specified message (..MessageCheatSheet.html#NodeHello)
+@note: gen_cheatsheet.py -? or --help will print out this help text
+
+"""
+from __future__ import with_statement
+
+
+import os, sys
+
+import cStringIO
+import shutil
+import subprocess
+import urllib
+from xml.etree import cElementTree as ET
+
+import fcpscripts_consts as consts
+#*******************************************************************************
+#
+#*******************************************************************************
+Dir = os.path.dirname(os.path.abspath(__file__))
+
+
+#TODO: does shell=True work on windows?
+UseShell = True
+
+
+def tidyPage(data, commandline):
+ p = subprocess.Popen(
+ args=commandline,
+ shell=UseShell,
+ stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ )
+ stdin, stderr = p.communicate(input=data)
+ return stdin
+
+
+def readPage(url, tidy):
+ fp = urllib.urlopen(url)
+ try:
+ data = fp.read()
+ data = tidyPage(data, tidy)
+
+ # remove namespace decl tidy added
+ data = data.split('\n', 1)[1]
+ data = '<html>\n' + data
+
+ return ET.fromstring(data)
+ finally:
+ fp.close()
+
+
+def parentMap(tree):
+ m = {}
+ for parent in tree.getiterator():
+ for child in parent:
+ m[child] = parent
+ return m
+
+
+def createCheatSheet(tidy=None):
+
+ if tidy is None:
+ tidy = 'tidy'
+ TidyToXml = '%s --output-xml yes --doctype omit --numeric-entities yes --show-warnings no' % tidy
+ TidyToHtml = '%s --input-xml --output-html yes --indent yes --show-warnings no' % tidy
+
+ buf = cStringIO.StringIO()
+ tree = readPage(consts.WikiStartPage, TidyToXml)
+
+ tables = tree.findall('.//table')
+ if tables:
+
+ # assert refs to messages are located in table 0
+ table = tables[0]
+
+ # get all refs to messages
+ As = table.findall('.//a')
+ As.sort(cmp=lambda x,y: cmp(x.attrib.get('href', 0), y.attrib.get('href', 0)) )
+ for a in As:
+ hrefMessage = a.attrib.get('href', None)
+ if hrefMessage is not None:
+
+ uri = consts.WikiBaseUri + hrefMessage
+ tree = readPage(uri, TidyToXml)
+
+ # find <div class="page">
+ DIVs = tree.findall(".//div")
+ for div in DIVs:
+ clss = div.attrib.get('class', None)
+ if clss == 'page':
+
+ parentmap = parentMap(div)
+ #print parents
+
+ # remove all forms and scripts
+ if 'ondblclick' in div.attrib:
+ del div.attrib['ondblclick']
+
+ forms = div.findall('.//form')
+ for form in forms:
+ parent = parentmap[form]
+ parent.remove(form)
+
+ # disable all refs
+ As = div.findall('.//a')
+ for a in As:
+ href = a.attrib.get('href', None)
+ if href is not None:
+ if 'href' in a.attrib:
+ del a.attrib['href']
+
+ # place an anchor to message name and some deco
+ a = ET.Element('a', {'name': hrefMessage.replace(consts.WikiFcpPrefix, '')})
+ div.insert(0, a)
+ hr = ET.Element('hr')
+ div.append(hr)
+
+ tree = ET.ElementTree(div)
+ tree.write(buf)
+ #
+ fpathCheatSheet = os.path.join(Dir, consts.FilenameMessageCheatSheet)
+ with open(fpathCheatSheet, 'w') as fp:
+ fp.write(tidyPage(buf.getvalue(), TidyToHtml) )
+ return fpathCheatSheet
+
+
+def main(tidy=None):
+ print 'generating message cheat sheet from: %s' % consts.WikiStartPage
+ fpath = createCheatSheet(tidy)
+ print 'done'
+
+
+#*******************************************************************************
+#
+#*******************************************************************************
+if __name__ == '__main__':
+ if len(sys.argv) > 1:
+ param = sys.argv[1]
+ if param in ('-?', '--help'):
+ print __doc__
+ else:
+ main(param)
+ main()
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|