MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / processFiles

Method processFiles

src/App/Application.cpp:3046–3118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3044}
3045
3046std::list<std::string> Application::processFiles(const std::list<std::string>& files)
3047{
3048 std::list<std::string> processed;
3049 Base::Console().log("Init: Processing command line files\n");
3050 for (const auto & it : files) {
3051 Base::FileInfo file(it);
3052 // Can we safely remove the isSymlink check and directly query the canonical
3053 // path for every string? The reason for avoiding it currently is that
3054 // getCannonicalPath will log an error if the file doesn't exist
3055 if (file.isSymlink()) {
3056 if (auto cannonicalPath = file.getCannonicalPath()) {
3057 file = Base::FileInfo(*cannonicalPath);
3058 } else {
3059 Base::Console().error("Failed to process symlink file: %s\n", file.filePath());
3060 }
3061 }
3062
3063 Base::Console().log("Init: Processing file: %s\n",file.filePath().c_str());
3064
3065 try {
3066 if (file.hasExtension("fcstd") || file.hasExtension("fcbak")
3067 || file.hasExtension("std")) {
3068 // try to open
3069 Application::_pcSingleton->openDocument(file.filePath().c_str());
3070 processed.push_back(it);
3071 }
3072 else if (file.hasExtension("fcscript") || file.hasExtension("fcmacro")) {
3073 Base::Interpreter().runFile(file.filePath().c_str(), true);
3074 processed.push_back(it);
3075 }
3076 else if (file.hasExtension("py")) {
3077 try {
3078 Base::Interpreter().addPythonPath(file.dirPath().c_str());
3079 Base::Interpreter().loadModule(file.fileNamePure().c_str());
3080 processed.push_back(it);
3081 }
3082 catch (const Base::PyException&) {
3083 // if loading the module does not work, try just running the script (run in __main__)
3084 Base::Interpreter().runFile(file.filePath().c_str(),true);
3085 processed.push_back(it);
3086 }
3087 }
3088 else {
3089 std::vector<std::string> mods = GetApplication().getImportModules(file.extension());
3090 if (!mods.empty()) {
3091 std::string escapedstr = Base::Tools::escapedUnicodeFromUtf8(file.filePath().c_str());
3092 escapedstr = Base::Tools::escapeEncodeFilename(escapedstr);
3093
3094 Base::Interpreter().loadModule(mods.front().c_str());
3095 Base::Interpreter().runStringArg("import %s",mods.front().c_str());
3096 Base::Interpreter().runStringArg("%s.open(u\"%s\")",mods.front().c_str(),
3097 escapedstr.c_str());
3098 processed.push_back(it);
3099 Base::Console().log("Command line open: %s.open(u\"%s\")\n",mods.front().c_str(),escapedstr.c_str());
3100 }
3101 else if (file.exists()) {
3102 Base::Console().warning("File format not supported: %s \n", file.filePath().c_str());
3103 }

Callers

nothing calls this directly

Calls 15

isSymlinkMethod · 0.80
getCannonicalPathMethod · 0.80
openDocumentMethod · 0.80
runFileMethod · 0.80
addPythonPathMethod · 0.80
dirPathMethod · 0.80
loadModuleMethod · 0.80
fileNamePureMethod · 0.80
getImportModulesMethod · 0.80
runStringArgMethod · 0.80
FileInfoClass · 0.50
logMethod · 0.45

Tested by

no test coverage detected