~ubuntu-branches/ubuntu/wily/sflphone/wily

« back to all changes in this revision

Viewing changes to daemon/libs/pjproject-2.2.1/doc/pjsip-book/fetch_trac.py

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2015-01-07 14:51:16 UTC
  • mfrom: (4.3.5 sid)
  • Revision ID: package-import@ubuntu.com-20150107145116-yxnafinf4lrdvrmx
Tags: 1.4.1-0.1ubuntu1
* Merge with Debian, remaining changes:
 - Drop soprano, nepomuk build-dep
* Drop ubuntu patches, now upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import urllib2
 
2
import sys
 
3
import unicodedata
 
4
 
 
5
def fetch_rst(url):
 
6
        print 'Fetching %s..' % url
 
7
        req = urllib2.Request(url)
 
8
                
 
9
        fd = urllib2.urlopen(req, timeout=30)
 
10
        body = fd.read()
 
11
        body = body.replace("\r\n", "\n")
 
12
 
 
13
        body = body.decode('utf8', 'ignore').encode('ascii', 'ignore')
 
14
 
 
15
        pos = body.find("{{{")
 
16
        if pos >= 0:
 
17
                body = body[pos+4:]
 
18
        
 
19
        pos = body.find("}}}")
 
20
        if pos >= 0:
 
21
                body = body[:pos]
 
22
 
 
23
        pos = body.find("#!rst")
 
24
        if pos >= 0:
 
25
                body = body[pos+6:]
 
26
 
 
27
        pos = url.rfind("/")
 
28
        if pos >= 0:
 
29
                filename = url[pos+1:]
 
30
        else:
 
31
                filename = url
 
32
        
 
33
        pos = filename.find('?')
 
34
        if pos >= 0:
 
35
                filename = filename[:pos]
 
36
                
 
37
        filename += ".rst"
 
38
        f = open(filename, 'w')
 
39
        f.write(body)
 
40
        f.close()
 
41
 
 
42
 
 
43
def process_index(index):
 
44
        pages = []
 
45
        
 
46
        f = open(index + '.rst', 'r')
 
47
        line = f.readline()
 
48
        while line:
 
49
                if line.find('toctree::') >= 0:
 
50
                        break
 
51
                line = f.readline()
 
52
                
 
53
        if line.find('toctree::') < 0:
 
54
                return []
 
55
        # Skip directive (or whatever it's called
 
56
        line = f.readline().strip()
 
57
        while line and line[0] == ':':
 
58
                line = f.readline().strip()
 
59
        # Skip empty lines
 
60
        line = f.readline().strip()
 
61
        while not line:
 
62
                line = f.readline().strip()
 
63
        # Parse names
 
64
        while line:
 
65
                pages.append(line)
 
66
                line = f.readline().strip()
 
67
                
 
68
        f.close()
 
69
        
 
70
        return pages
 
71
 
 
72
 
 
73
if __name__ == '__main__':
 
74
        print "** Warning: This will overwrite ALL RST files in current directory. Continue? [n] ",
 
75
        if sys.stdin.readline().strip() != 'y':
 
76
                sys.exit(0)
 
77
                
 
78
        url_format = 'http://trac.pjsip.org/repos/wiki/pjsip-doc/%s?format=txt'
 
79
        
 
80
        index = url_format % ('index')
 
81
        fetch_rst(index)
 
82
        
 
83
        pages = process_index('index')
 
84
        for page in pages:
 
85
                #if not 'endpoint' in page:
 
86
                #       continue
 
87
                url = url_format % (page)
 
88
                fetch_rst(url)
 
89
                
 
90
        print 'Done.'
 
91