FreeCAD

Форк
0
/
CreateModule.py 
138 строк · 4.5 Кб
1
# FreeCAD MakeNewBuildNbr script
2
# (c) 2003 Werner Mayer
3
#
4
# Creates a new application
5

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

30
import os, sys
31
import MakeAppTools
32
import re
33

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

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

70

71
def SetupFilter(MatchList):
72
    RegList = []
73
    for regexp in MatchList:
74
        a = re.compile(regexp)
75
        RegList.append(a)
76
    return RegList
77

78

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

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

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

114
    sys.stdout.write(Application + " module created successfully.\n")
115

116

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

133

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

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

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

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

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