FreeCAD
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
27import os, sys28import MakeAppTools29import re30
31FilFilter = [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
52DirFilter = [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
68def SetupFilter(MatchList):69RegList = []70for regexp in MatchList:71a = re.compile(regexp)72RegList.append(a)73return RegList74
75
76def createApp(Application):77"""78Create a new application by copying the template
79"""
80# create directory ../Mod/<Application>81if not os.path.isdir("../Mod/" + Application):82os.mkdir("../Mod/" + Application)83else:84sys.stdout.write(Application + " already exists. Please enter another name.\n")85sys.exit()86
87# copying files from _TEMPLATEPY_ to ../Mod/<Application>88sys.stdout.write("Copying files...")89MakeAppTools.copyTemplate(90"_TEMPLATEPY_",91"../Mod/" + Application,92"_TEMPLATEPY_",93Application,94SetupFilter(FilFilter),95SetupFilter(DirFilter),96)97sys.stdout.write("Ok\n")98
99# replace the _TEMPLATEPY_ string by <Application>100sys.stdout.write("Modifying files...\n")101MakeAppTools.replaceTemplate("../Mod/" + Application, "_TEMPLATEPY_", Application)102MakeAppTools.replaceTemplate(103"../Mod/" + Application,104"${CMAKE_SOURCE_DIR}/src/Tools/",105"${CMAKE_SOURCE_DIR}/src/Mod/",106)107# make the configure script executable108# os.chmod("../Mod/" + Application + "/configure", 0777);109sys.stdout.write("Modifying files done.\n")110
111sys.stdout.write(Application + " module created successfully.\n")112
113
114def validateApp(AppName):115"""116Validates the class name
117"""
118if len(AppName) < 2:119sys.stdout.write("Too short name: '" + AppName + "'\n")120sys.exit()121# name is long enough122clName = "class " + AppName + ": self=0"123try:124exec(clName)125except Exception:126# Invalid class name127sys.stdout.write("Invalid name: '" + AppName + "'\n")128sys.exit()129
130
131sys.stdout.write("Please enter a name for your application:")132sys.stdout.flush()133AppName = sys.stdin.readline()[:-1]134validateApp(AppName)135createApp(AppName)136