File: download-examples-from-wiki.py

package info (click to toggle)
pycuda 2020.1~dfsg1-1
  • links: PTS, VCS
  • area: contrib
  • in suites: bullseye, sid
  • size: 1,600 kB
  • sloc: python: 8,932; cpp: 8,136; makefile: 106
file content (60 lines) | stat: -rwxr-xr-x 1,706 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#! /usr/bin/env python3
from __future__ import print_function, absolute_import
try:
    import six.moves.xmlrpc_client
except:
    import xmlrpc.client as xmlrpclib

destwiki = six.moves.xmlrpc_client.ServerProxy("https://wiki.tiker.net?action=xmlrpc2")

import os
try:
    os.mkdir("wiki-examples")
except OSError:
    pass

print("downloading  wiki examples from http://wiki.tiker.net/PyCuda/Examples to wiki-examples/...")
print("fetching page list...")
all_pages = destwiki.getAllPages()


from os.path import exists

for page in all_pages:
    if not page.startswith("PyCuda/Examples/"):
        continue

    print(page)
    try:
        content = destwiki.getPage(page)

        import re
        match = re.search(r"\{\{\{\#\!python(.*)\}\}\}", content, re.DOTALL)
        code = match.group(1)

        match = re.search("([^/]+)$", page)
        fname = match.group(1)

        outfname = os.path.join("wiki-examples", fname+".py")
        if exists(outfname):
            print("%s exists, refusing to overwrite." % outfname)
        else:
            outf = open(outfname, "w")
            outf.write(code)
            outf.close()

        for att_name in destwiki.listAttachments(page):
            content = destwiki.getAttachment(page, att_name)

            outfname = os.path.join("wiki-examples", att_name)
            if exists(outfname):
                print("%s exists, refusing to overwrite." % outfname)
            else:
                outf = open(outfname, "w")
                outf.write(str(content))
                outf.close()

    except Exception as e:
        print("Error when processing %s: %s" % (page, e))
        from traceback import print_exc
        print_exc()