FreeCAD

Форк
0
/
examplePy2wiki.py 
66 строк · 1.5 Кб
1
#! python
2
# (c) 2009 Juergen Riegel GPL
3

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

6
Usage:
7
   examplePy2wiki [Optionen]
8

9
Options:
10
 -o  --out-file=FILENAME  use this file name for output, default resources.qrc
11
 -i, --in-file=FILENAME   directory to search, default PWD
12
 -h, --help               print this help message
13

14
This program reads python files and generate a output suited for a Mediawiki page.
15
The python comments get translated to text and the code blocks get intended to
16
show up us code in the wiki.
17

18

19
Author:
20
  (c) 2009 Juergen Riegel
21
  juergen.riegel@web.de
22
  Licence: GPL V2
23

24
Version:
25
  0.1
26
"""
27

28
import os, sys, string, getopt
29

30

31
def Process(line):
32
    if line[0:2] == "# ":
33
        return line[2:]
34
    else:
35
        return " " + line
36

37

38
def main():
39

40
    try:
41
        opts, args = getopt.getopt(
42
            sys.argv[1:], "hi:o:", ["help", "verbose", "in-file=", "out-file="]
43
        )
44
    except getopt.GetoptError:
45
        # print help information and exit:
46
        sys.stderr.write(Usage)
47
        sys.exit(2)
48

49
    # checking on the options
50
    for o, a in opts:
51
        if o in ("-h", "--help"):
52
            sys.stderr.write(Usage)
53
            sys.exit()
54
        if o in ("-o", "--out-file"):
55
            outfile = open(a, "w")
56
        if o in ("-i", "--in-file"):
57
            infile = open(a, "r")
58

59
    lines = infile.readlines()
60
    for l in lines:
61
        outfile.write(Process(l))
62
        # print l
63

64

65
if __name__ == "__main__":
66
    main()
67

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.