File size: 1,604 Bytes
985c397
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
61
62
63
64
65
66
67
68
69
#! python
# SPDX-License-Identifier: LGPL-2.1-or-later

# (c) 2009 Juergen Riegel GPL

Usage = """examplePy2wiki - generating a wiki text out of a python example



Usage:

   examplePy2wiki [Optionen]



Options:

 -o  --out-file=FILENAME  use this file name for output, default resources.qrc

 -i, --in-file=FILENAME   directory to search, default PWD

 -h, --help               print this help message



This program reads python files and generate a output suited for a Mediawiki page.

The python comments get translated to text and the code blocks get intended to

show up us code in the wiki.





Author:

  (c) 2009 Juergen Riegel

  juergen.riegel@web.de

  Licence: GPL V2



Version:

  0.1

"""

import os, sys, string, getopt


def Process(line):
    if line[0:2] == "# ":
        return line[2:]
    else:
        return " " + line


def main():

    try:
        opts, args = getopt.getopt(
            sys.argv[1:], "hi:o:", ["help", "verbose", "in-file=", "out-file="]
        )
    except getopt.GetoptError:
        # print help information and exit:
        sys.stderr.write(Usage)
        sys.exit(2)

    # checking on the options
    for o, a in opts:
        if o in ("-h", "--help"):
            sys.stderr.write(Usage)
            sys.exit()
        if o in ("-o", "--out-file"):
            outfile = open(a, "w")
        if o in ("-i", "--in-file"):
            infile = open(a, "r")

    lines = infile.readlines()
    for l in lines:
        outfile.write(Process(l))
        # print l


if __name__ == "__main__":
    main()