void SolveSpace::ReloadAllImported(void) { allConsistent = false; int i; for(i = 0; i < SK.group.n; i++) { Group *g = &(SK.group.elem[i]); if(g->type != Group::IMPORTED) continue; g->impEntity.Clear(); g->impMesh.Clear(); g->impShell.Clear(); FILE *test = fopen(g->impFile, "rb"); if(test) { fclose(test); // okay, exists } else { // It doesn't exist. Perhaps the entire tree has moved, and we // can use the relative filename to get us back. if(SS.saveFile[0]) { char fromRel[MAX_PATH]; strcpy(fromRel, g->impFileRel); MakePathAbsolute(SS.saveFile, fromRel); test = fopen(fromRel, "rb"); if(test) { fclose(test); // It worked, this is our new absolute path strcpy(g->impFile, fromRel); } } } if(LoadEntitiesFromFile(g->impFile, &(g->impEntity), &(g->impMesh), &(g->impShell))) { if(SS.saveFile[0]) { // Record the imported file's name relative to our filename; // if the entire tree moves, then everything will still work strcpy(g->impFileRel, g->impFile); MakePathRelative(SS.saveFile, g->impFileRel); } else { // We're not yet saved, so can't make it absolute strcpy(g->impFileRel, g->impFile); } } else { Error("Failed to load imported file '%s'", g->impFile); } } }
//--------------------------------------------------------------------------- void parseCommandLine(SubmitDagDeepOptions &deepOpts, SubmitDagShallowOptions &shallowOpts, int argc, const char * const argv[]) { for (int iArg = 1; iArg < argc; iArg++) { MyString strArg = argv[iArg]; if (strArg[0] != '-') { // We assume an argument without a leading hyphen is // a DAG file name. shallowOpts.dagFiles.append(strArg.Value()); if ( shallowOpts.primaryDagFile == "" ) { shallowOpts.primaryDagFile = strArg; } } else if (shallowOpts.primaryDagFile != "") { // Disallow hyphen args after DAG file name(s). printf("ERROR: no arguments allowed after DAG file name(s)\n"); printUsage(); } else { strArg.lower_case(); // Note: in checking the argument names here, we only check for // as much of the full name as we need to unambiguously define // the argument. if (strArg.find("-no_s") != -1) // -no_submit { shallowOpts.bSubmit = false; } else if (strArg.find("-vers") != -1) // -version { printf( "%s\n%s\n", CondorVersion(), CondorPlatform() ); exit( 0 ); } else if (strArg.find("-help") != -1 || strArg.find("-h") != -1) // -help { printUsage(0); } // submit and stick to a specific schedd else if (strArg.find("-schedd-daemon-ad-file") != -1) { if (iArg + 1 >= argc) { fprintf(stderr, "-schedd-daemon-ad-file argument needs a value\n"); printUsage(); } shallowOpts.strScheddDaemonAdFile = argv[++iArg]; } // submit and stick to a specific schedd else if (strArg.find("-schedd-address-file") != -1) { if (iArg + 1 >= argc) { fprintf(stderr, "-schedd-address-file argument needs a value\n"); printUsage(); } shallowOpts.strScheddAddressFile = argv[++iArg]; } else if (strArg.find("-f") != -1) // -force { deepOpts.bForce = true; } else if (strArg.find("-not") != -1) // -notification { if (iArg + 1 >= argc) { fprintf(stderr, "-notification argument needs a value\n"); printUsage(); } deepOpts.strNotification = argv[++iArg]; } else if (strArg.find("-r") != -1) // submit to remote schedd { if (iArg + 1 >= argc) { fprintf(stderr, "-r argument needs a value\n"); printUsage(); } shallowOpts.strRemoteSchedd = argv[++iArg]; } else if (strArg.find("-dagman") != -1) { if (iArg + 1 >= argc) { fprintf(stderr, "-dagman argument needs a value\n"); printUsage(); } deepOpts.strDagmanPath = argv[++iArg]; } else if (strArg.find("-de") != -1) // -debug { if (iArg + 1 >= argc) { fprintf(stderr, "-debug argument needs a value\n"); printUsage(); } shallowOpts.iDebugLevel = atoi(argv[++iArg]); } else if (strArg.find("-noev") != -1) // -noeventchecks { shallowOpts.bNoEventChecks = true; } else if (strArg.find("-allowlog") != -1) // -allowlogerror { deepOpts.bAllowLogError = true; } else if (strArg.find("-use") != -1) // -usedagdir { deepOpts.useDagDir = true; } else if (strArg.find("-out") != -1) // -outfile_dir { if (iArg + 1 >= argc) { fprintf(stderr, "-outfile_dir argument needs a value\n"); printUsage(); } deepOpts.strOutfileDir = argv[++iArg]; } else if (strArg.find("-con") != -1) // -config { if (iArg + 1 >= argc) { fprintf(stderr, "-config argument needs a value\n"); printUsage(); } shallowOpts.strConfigFile = argv[++iArg]; // Internally we deal with all configuration file paths // as full paths, to make it easier to determine whether // several paths point to the same file. MyString errMsg; if (!MakePathAbsolute(shallowOpts.strConfigFile, errMsg)) { fprintf( stderr, "%s\n", errMsg.Value() ); exit( 1 ); } } else if (strArg.find("-app") != -1) // -append { if (iArg + 1 >= argc) { fprintf(stderr, "-append argument needs a value\n"); printUsage(); } shallowOpts.appendLines.append(argv[++iArg]); } else if (strArg.find("-insert") != -1) // -insert_sub_file { if (iArg + 1 >= argc) { fprintf(stderr, "-insert_sub_file argument needs a value\n"); printUsage(); } ++iArg; if (shallowOpts.appendFile != "") { printf("Note: -insert_sub_file value (%s) overriding " "DAGMAN_INSERT_SUB_FILE setting (%s)\n", argv[iArg], shallowOpts.appendFile.Value()); } shallowOpts.appendFile = argv[iArg]; } else if (strArg.find("-autor") != -1) // -autorescue { if (iArg + 1 >= argc) { fprintf(stderr, "-autorescue argument needs a value\n"); printUsage(); } deepOpts.autoRescue = (atoi(argv[++iArg]) != 0); } else if (strArg.find("-dores") != -1) // -dorescuefrom { if (iArg + 1 >= argc) { fprintf(stderr, "-dorescuefrom argument needs a value\n"); printUsage(); } deepOpts.doRescueFrom = atoi(argv[++iArg]); } else if (strArg.find("-allowver") != -1) // -AllowVersionMismatch { deepOpts.allowVerMismatch = true; } else if (strArg.find("-no_rec") != -1) // -no_recurse { deepOpts.recurse = false; } else if (strArg.find("-do_rec") != -1) // -do_recurse { deepOpts.recurse = true; } else if (strArg.find("-updat") != -1) // -update_submit { deepOpts.updateSubmit = true; } else if (strArg.find("-import_env") != -1) // -import_env { deepOpts.importEnv = true; } else if (strArg.find("-dumpr") != -1) // -DumpRescue { shallowOpts.dumpRescueDag = true; } else if (strArg.find("-valgrind") != -1) // -valgrind { shallowOpts.runValgrind = true; } // This must come last, so we can have other arguments // that start with -v. else if ( (strArg.find("-v") != -1) ) // -verbose { deepOpts.bVerbose = true; } else if ( (strArg.find("-dontalwaysrun") != -1) ) // DontAlwaysRunPost { shallowOpts.bPostRun = false; } else if ( (strArg.find("-dont_use_default_node_log") != -1) ) { fprintf( stderr, "Error: -dont_use_default_node_log is no longer allowed\n" ); printUsage(); } else if ( (strArg.find("-suppress_notification") != -1) ) { deepOpts.suppress_notification = true; } else if ( (strArg.find("-dont_suppress_notification") != -1) ) { deepOpts.suppress_notification = false; } else if( (strArg.find("-prio") != -1) ) // -priority { if(iArg + 1 >= argc) { fprintf(stderr, "-priority argument needs a value\n"); printUsage(); } deepOpts.priority = atoi(argv[++iArg]); } else if ( (strArg.find("-dorecov") != -1) ) { shallowOpts.doRecovery = true; } else if ( parsePreservedArgs( strArg, iArg, argc, argv, shallowOpts) ) { // No-op here } else { fprintf( stderr, "ERROR: unknown option %s\n", strArg.Value() ); printUsage(); } } } if (shallowOpts.primaryDagFile == "") { fprintf( stderr, "ERROR: no dag file specified; aborting.\n" ); printUsage(); } if (deepOpts.doRescueFrom < 0) { fprintf( stderr, "-dorescuefrom value must be non-negative; aborting.\n"); printUsage(); } }
//------------------------------------------------------------------------- bool GetConfigAndAttrs( /* const */ StringList &dagFiles, bool useDagDir, MyString &configFile, StringList &attrLines, MyString &errMsg ) { bool result = true; // Note: destructor will change back to original directory. TmpDir dagDir; dagFiles.rewind(); char *dagFile; while ( (dagFile = dagFiles.next()) != NULL ) { // // Change to the DAG file's directory if necessary, and // get the filename we need to use for it from that directory. // const char * newDagFile; if ( useDagDir ) { MyString tmpErrMsg; if ( !dagDir.Cd2TmpDirFile( dagFile, tmpErrMsg ) ) { AppendError( errMsg, MyString("Unable to change to DAG directory ") + tmpErrMsg ); return false; } newDagFile = condor_basename( dagFile ); } else { newDagFile = dagFile; } StringList configFiles; // Note: destructor will close file. MultiLogFiles::FileReader reader; errMsg = reader.Open( newDagFile ); if ( errMsg != "" ) { return false; } MyString logicalLine; while ( reader.NextLogicalLine( logicalLine ) ) { if ( logicalLine != "" ) { // Note: StringList constructor removes leading // whitespace from lines. StringList tokens( logicalLine.Value(), " \t" ); tokens.rewind(); const char *firstToken = tokens.next(); if ( !strcasecmp( firstToken, "config" ) ) { // Get the value. const char *newValue = tokens.next(); if ( !newValue || !strcmp( newValue, "" ) ) { AppendError( errMsg, "Improperly-formatted " "file: value missing after keyword " "CONFIG" ); result = false; } else { // Add the value we just found to the config // files list (if it's not already in the // list -- we don't want duplicates). configFiles.rewind(); char *existingValue; bool alreadyInList = false; while ( ( existingValue = configFiles.next() ) ) { if ( !strcmp( existingValue, newValue ) ) { alreadyInList = true; } } if ( !alreadyInList ) { // Note: append copies the string here. configFiles.append( newValue ); } } //some DAG commands are needed for condor_submit_dag, too... } else if ( !strcasecmp( firstToken, "SET_JOB_ATTR" ) ) { // Strip of DAGMan-specific command name; the // rest we pass to the submit file. logicalLine.replaceString( "SET_JOB_ATTR", "" ); logicalLine.trim(); if ( logicalLine == "" ) { AppendError( errMsg, "Improperly-formatted " "file: value missing after keyword " "SET_JOB_ATTR" ); result = false; } else { attrLines.append( logicalLine.Value() ); } } } } reader.Close(); // // Check the specified config file(s) against whatever we // currently have, setting the config file if it hasn't // been set yet, flagging an error if config files conflict. // configFiles.rewind(); char * cfgFile; while ( (cfgFile = configFiles.next()) ) { MyString cfgFileMS = cfgFile; MyString tmpErrMsg; if ( MakePathAbsolute( cfgFileMS, tmpErrMsg ) ) { if ( configFile == "" ) { configFile = cfgFileMS; } else if ( configFile != cfgFileMS ) { AppendError( errMsg, MyString("Conflicting DAGMan ") + "config files specified: " + configFile + " and " + cfgFileMS ); result = false; } } else { AppendError( errMsg, tmpErrMsg ); result = false; } } // // Go back to our original directory. // MyString tmpErrMsg; if ( !dagDir.Cd2MainDir( tmpErrMsg ) ) { AppendError( errMsg, MyString("Unable to change to original directory ") + tmpErrMsg ); result = false; } } return result; }
bool SolveSpaceUI::ReloadAllImported(bool canCancel) { std::map<std::string, std::string> importMap; allConsistent = false; int i; for(i = 0; i < SK.group.n; i++) { Group *g = &(SK.group.elem[i]); if(g->type != Group::IMPORTED) continue; if(isalpha(g->impFile[0]) && g->impFile[1] == ':') { // Make sure that g->impFileRel always contains a relative path // in an UNIX format, even after we load an old file which had // the path in Windows format PathSepNormalize(g->impFileRel); } g->impEntity.Clear(); g->impMesh.Clear(); g->impShell.Clear(); if(importMap.count(g->impFile)) { std::string newPath = importMap[g->impFile]; if(!newPath.empty()) g->impFile = newPath; } FILE *test = ssfopen(g->impFile, "rb"); if(test) { fclose(test); // okay, exists } else { // It doesn't exist. Perhaps the entire tree has moved, and we // can use the relative filename to get us back. if(!SS.saveFile.empty()) { std::string rel = PathSepUNIXToPlatform(g->impFileRel); std::string fromRel = MakePathAbsolute(SS.saveFile, rel); test = ssfopen(fromRel, "rb"); if(test) { fclose(test); // It worked, this is our new absolute path g->impFile = fromRel; } } } try_load_file: if(LoadEntitiesFromFile(g->impFile, &(g->impEntity), &(g->impMesh), &(g->impShell))) { if(!SS.saveFile.empty()) { // Record the imported file's name relative to our filename; // if the entire tree moves, then everything will still work std::string rel = MakePathRelative(SS.saveFile, g->impFile); g->impFileRel = PathSepPlatformToUNIX(rel); } else { // We're not yet saved, so can't make it absolute. // This will only be used for display purposes, as SS.saveFile // is always nonempty when we are actually writing anything. g->impFileRel = g->impFile; } } else if(!importMap.count(g->impFile)) { switch(LocateImportedFileYesNoCancel(g->impFileRel, canCancel)) { case DIALOG_YES: { std::string oldImpFile = g->impFile; if(!GetOpenFile(g->impFile, "", SLVS_PATTERN)) { if(canCancel) return false; break; } else { importMap[oldImpFile] = g->impFile; goto try_load_file; } } case DIALOG_NO: importMap[g->impFile] = ""; /* Geometry will be pruned by GenerateAll(). */ break; case DIALOG_CANCEL: return false; } } else { // User was already asked to and refused to locate a missing // imported file. } } return true; }