FreeCAD

Форк
0
/
CreatePyModule.py 
135 строк · 4.3 Кб
1
# ***************************************************************************
2
# *   Copyright (c) 2003 Werner Mayer <werner.wm.mayer@gmx.de>              *
3
# *                                                                         *
4
# *   This file is part of the FreeCAD CAx development system.              *
5
# *                                                                         *
6
# *   This program is free software; you can redistribute it and/or modify  *
7
# *   it under the terms of the GNU Lesser General Public License (LGPL)    *
8
# *   as published by the Free Software Foundation; either version 2 of     *
9
# *   the License, or (at your option) any later version.                   *
10
# *   for detail see the LICENCE text file.                                 *
11
# *                                                                         *
12
# *   FreeCAD is distributed in the hope that it will be useful,            *
13
# *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
14
# *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
15
# *   GNU Lesser General Public License for more details.                   *
16
# *                                                                         *
17
# *   You should have received a copy of the GNU Library General Public     *
18
# *   License along with FreeCAD; if not, write to the Free Software        *
19
# *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
20
# *   USA                                                                   *
21
# *                                                                         *
22
# ***************************************************************************
23

24
# FreeCAD MakeNewBuildNbr script
25
# Creates a new application
26

27
import os, sys
28
import MakeAppTools
29
import re
30

31
FilFilter = [
32
    "^.*\\.o$",
33
    "^.*Makefile$",
34
    "^.*\\.la$",
35
    "^.*\\.lo$",
36
    "^.*\\.positions$",
37
    "^.*\\.aux$",
38
    "^.*\\.bsc$",
39
    "^.*\\.exp$",
40
    "^.*\\.ilg$",
41
    "^.*\\.ilk$",
42
    "^.*\\.in$",
43
    "^.*\\.mak$",
44
    "^.*\\.ncb$",
45
    "^.*\\.opt$",
46
    "^.*\\.pyc$",
47
    "^.*\\.pyd$",
48
    "^.*\\.pdb$",
49
    "^.*\\.plg$",
50
]
51

52
DirFilter = [
53
    "^.*\\.o$",
54
    "^Debug$",
55
    "^DebugCmd$",
56
    "^DebugPy$",
57
    "^Release$",
58
    "^ReleaseCmd$",
59
    "^ReleasePy$",
60
    "^Attic$",
61
    "^CVS$",
62
    "^\\.svn$",
63
    "^\\.deps$",
64
    "^\\.libs$",
65
]
66

67

68
def SetupFilter(MatchList):
69
    RegList = []
70
    for regexp in MatchList:
71
        a = re.compile(regexp)
72
        RegList.append(a)
73
    return RegList
74

75

76
def createApp(Application):
77
    """
78
    Create a new application by copying the template
79
    """
80
    # create directory ../Mod/<Application>
81
    if not os.path.isdir("../Mod/" + Application):
82
        os.mkdir("../Mod/" + Application)
83
    else:
84
        sys.stdout.write(Application + " already exists. Please enter another name.\n")
85
        sys.exit()
86

87
    # copying files from _TEMPLATEPY_ to ../Mod/<Application>
88
    sys.stdout.write("Copying files...")
89
    MakeAppTools.copyTemplate(
90
        "_TEMPLATEPY_",
91
        "../Mod/" + Application,
92
        "_TEMPLATEPY_",
93
        Application,
94
        SetupFilter(FilFilter),
95
        SetupFilter(DirFilter),
96
    )
97
    sys.stdout.write("Ok\n")
98

99
    # replace the _TEMPLATEPY_ string by <Application>
100
    sys.stdout.write("Modifying files...\n")
101
    MakeAppTools.replaceTemplate("../Mod/" + Application, "_TEMPLATEPY_", Application)
102
    MakeAppTools.replaceTemplate(
103
        "../Mod/" + Application,
104
        "${CMAKE_SOURCE_DIR}/src/Tools/",
105
        "${CMAKE_SOURCE_DIR}/src/Mod/",
106
    )
107
    # make the configure script executable
108
    # os.chmod("../Mod/" + Application + "/configure", 0777);
109
    sys.stdout.write("Modifying files done.\n")
110

111
    sys.stdout.write(Application + " module created successfully.\n")
112

113

114
def validateApp(AppName):
115
    """
116
    Validates the class name
117
    """
118
    if len(AppName) < 2:
119
        sys.stdout.write("Too short name: '" + AppName + "'\n")
120
        sys.exit()
121
    # name is long enough
122
    clName = "class " + AppName + ": self=0"
123
    try:
124
        exec(clName)
125
    except Exception:
126
        # Invalid class name
127
        sys.stdout.write("Invalid name: '" + AppName + "'\n")
128
        sys.exit()
129

130

131
sys.stdout.write("Please enter a name for your application:")
132
sys.stdout.flush()
133
AppName = sys.stdin.readline()[:-1]
134
validateApp(AppName)
135
createApp(AppName)
136

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

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

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

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