From e56ea14ab8531ee3cec375460577d1b89bf62e26 Mon Sep 17 00:00:00 2001 From: Liong Sauw Ming Date: Thu, 16 Jan 2014 05:30:46 +0000 Subject: Closed #1723: Merging pjsua2 branch into trunk git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@4704 74dad513-b988-da41-8d7b-12977e46ad98 --- doc/pjsip-book/fetch_trac.py | 85 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 doc/pjsip-book/fetch_trac.py (limited to 'doc/pjsip-book/fetch_trac.py') diff --git a/doc/pjsip-book/fetch_trac.py b/doc/pjsip-book/fetch_trac.py new file mode 100644 index 00000000..3c754624 --- /dev/null +++ b/doc/pjsip-book/fetch_trac.py @@ -0,0 +1,85 @@ +import urllib2 +import sys + +def fetch_rst(url): + print 'Fetching %s..' % url + req = urllib2.Request(url) + + fd = urllib2.urlopen(req, timeout=30) + body = fd.read() + + pos = body.find("{{{") + if pos >= 0: + body = body[pos+4:] + + pos = body.find("}}}") + if pos >= 0: + body = body[:pos] + + pos = body.find("#!rst") + if pos >= 0: + body = body[pos+6:] + + pos = url.rfind("/") + if pos >= 0: + filename = url[pos+1:] + else: + filename = url + + pos = filename.find('?') + if pos >= 0: + filename = filename[:pos] + + filename += ".rst" + f = open(filename, 'w') + f.write(body) + f.close() + + +def process_index(index): + pages = [] + + f = open(index + '.rst', 'r') + line = f.readline() + while line: + if line.find('toctree::') >= 0: + break + line = f.readline() + + if line.find('toctree::') < 0: + return [] + # Skip directive (or whatever it's called + line = f.readline().strip() + while line and line[0] == ':': + line = f.readline().strip() + # Skip empty lines + line = f.readline().strip() + while not line: + line = f.readline().strip() + # Parse names + while line: + pages.append(line) + line = f.readline().strip() + + f.close() + + return pages + + +if __name__ == '__main__': + print "** Warning: This will overwrite ALL RST files in current directory. Continue? [n] ", + if sys.stdin.readline().strip() != 'y': + sys.exit(0) + + url_format = 'http://trac.pjsip.org/repos/wiki/pjsip-doc/%s?format=txt' + + index = url_format % ('index') + fetch_rst(index) + + pages = process_index('index') + for page in pages: + url = url_format % (page) + fetch_rst(url) + + print 'Done.' + \ No newline at end of file -- cgit v1.2.3