FreeCADInit.py

Go to the documentation of this file.
00001 # FreeCAD init module
00002 # (c) 2001 Jürgen Riegel
00003 #
00004 # Gathering all the information to start FreeCAD
00005 # This is the second one of three init scripts, the third one
00006 # runs when the gui is up
00007 
00008 #***************************************************************************
00009 #*   (c) Jürgen Riegel (juergen.riegel@web.de) 2002                        *
00010 #*                                                                         *
00011 #*   This file is part of the FreeCAD CAx development system.              *
00012 #*                                                                         *
00013 #*   This program is free software; you can redistribute it and/or modify  *
00014 #*   it under the terms of the GNU General Public License (GPL)            *
00015 #*   as published by the Free Software Foundation; either version 2 of     *
00016 #*   the License, or (at your option) any later version.                   *
00017 #*   for detail see the LICENCE text file.                                 *
00018 #*                                                                         *
00019 #*   FreeCAD is distributed in the hope that it will be useful,            *
00020 #*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00021 #*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00022 #*   GNU Library General Public License for more details.                  *
00023 #*                                                                         *
00024 #*   You should have received a copy of the GNU Library General Public     *
00025 #*   License along with FreeCAD; if not, write to the Free Software        *
00026 #*   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
00027 #*   USA                                                                   *
00028 #*                                                                         *
00029 #*   Juergen Riegel 2002                                                   *
00030 #***************************************************************************/
00031 
00032 
00033 # imports the one and only
00034 import FreeCAD
00035 
00036 
00037 def InitApplications():
00038         try:
00039                 import sys,os
00040         except:
00041                 FreeCAD.PrintError("\n\nSeems the python standard libs are not installed, bailing out!\n\n")
00042                 raise
00043         # Checking on FreeCAD module path ++++++++++++++++++++++++++++++++++++++++++
00044         ModDir = FreeCAD.getHomePath()+'Mod'
00045         ModDir = os.path.realpath(ModDir)
00046         BinDir = FreeCAD.getHomePath()+'bin'
00047         BinDir = os.path.realpath(BinDir)
00048         LibDir = FreeCAD.getHomePath()+'lib'
00049         LibDir = os.path.realpath(LibDir)
00050         AddPath = FreeCAD.ConfigGet("AdditionalModulePaths").split(";")
00051         HomeMod = FreeCAD.ConfigGet("UserAppData")+"Mod"
00052         HomeMod = os.path.realpath(HomeMod)
00053         MacroMod = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macro").GetString("MacroPath")+"/Mod"
00054         MacroMod = os.path.realpath(MacroMod)
00055         ModPar = FreeCAD.ParamGet("System parameter:Modules")
00056 
00057         #print FreeCAD.getHomePath()
00058         if os.path.isdir(FreeCAD.getHomePath()+'src\\Tools'):
00059                 sys.path.append(FreeCAD.getHomePath()+'src\\Tools')
00060         # Searching for module dirs +++++++++++++++++++++++++++++++++++++++++++++++++++
00061         # Use dict to handle duplicated module names
00062         ModDict = {}
00063         if os.path.isdir(ModDir):
00064                 ModDirs = os.listdir(ModDir)
00065                 for i in ModDirs: ModDict[i.lower()] = os.path.join(ModDir,i)
00066         else:
00067                 Wrn ("No modules found in " + ModDir + "\n")
00068         # Search for additional modules in the home directory
00069         if os.path.isdir(HomeMod):
00070                 HomeMods = os.listdir(HomeMod)
00071                 for i in HomeMods: ModDict[i.lower()] = os.path.join(HomeMod,i)
00072         # Search for additional modules in the macro directory
00073         if os.path.isdir(MacroMod):
00074                 MacroMods = os.listdir(MacroMod)
00075                 for i in MacroMods: ModDict[i.lower()] = os.path.join(MacroMod,i)
00076         # Search for additional modules in command line
00077         for i in AddPath:
00078                 if os.path.isdir(i): ModDict[i] = i
00079         #AddModPaths = App.ParamGet("System parameter:AdditionalModulePaths")
00080         #Err( AddModPaths)
00081         # add also this path so that all modules search for libraries
00082         # they depend on first here
00083         PathExtension = BinDir + os.pathsep
00084         # prepend all module paths to Python search path
00085         Log('Init:   Searching for modules...\n')
00086         FreeCAD.__path__ = ModDict.values()
00087         for Dir in ModDict.values():
00088                 if ((Dir != '') & (Dir != 'CVS') & (Dir != '__init__.py')):
00089                         ModGrp = ModPar.GetGroup(Dir)
00090                         sys.path.insert(0,Dir)
00091                         PathExtension += Dir + os.pathsep
00092                         InstallFile = os.path.join(Dir,"Init.py")
00093                         if (os.path.exists(InstallFile)):
00094                                 try:
00095                                         execfile(InstallFile)
00096                                 except Exception, inst:
00097                                         Log('Init:      Initializing ' + Dir + '... failed\n')
00098                                         Err('During initialization the error ' + str(inst) + ' occurred in ' + InstallFile + '\n')
00099                                 else:
00100                                         Log('Init:      Initializing ' + Dir + '... done\n')
00101                         else:
00102                                 Log('Init:      Initializing ' + Dir + '(Init.py not found)... ignore\n')
00103         sys.path.insert(0,LibDir)
00104         sys.path.insert(0,ModDir)
00105         Log("Using "+ModDir+" as module path!\n")
00106         # new paths must be prepended to avoid to load a wrong version of a library
00107         os.environ["PATH"] = PathExtension + os.environ["PATH"]
00108         path = os.environ["PATH"].split(os.pathsep)
00109         Log("System path after init:\n")
00110         for i in path:
00111                 Log("   " + i + "\n")
00112         # add special path for MacOSX (bug #0000307)
00113         import platform
00114         if len(platform.mac_ver()[0]) > 0:
00115                 sys.path.append(os.path.expanduser('~/Library/Application Support/FreeCAD/Mod'))
00116 
00117 # some often used shortcuts (for lazy people like me ;-)
00118 App = FreeCAD
00119 Log = FreeCAD.Console.PrintLog
00120 Msg = FreeCAD.Console.PrintMessage
00121 Err = FreeCAD.Console.PrintError
00122 Wrn = FreeCAD.Console.PrintWarning
00123 
00124 Log ('Init: starting App::FreeCADInit.py\n')
00125 
00126 # init every application by importing Init.py
00127 InitApplications()
00128 
00129 FreeCAD.EndingAdd("FreeCAD document (*.FCStd)","FreeCAD")
00130 
00131 # set to no gui, is overwritten by InitGui
00132 App.GuiUp = 0
00133 
00134 # clean up namespace
00135 del(InitApplications)
00136 
00137 Log ('Init: App::FreeCADInit.py done\n')
00138 
00139 
00140 
00141 

Generated on Wed Nov 23 19:00:15 2011 for FreeCAD by  doxygen 1.6.1