Back to index

nordugrid-arc-nox  1.1.0~rc6
test_jobdescription.cpp
Go to the documentation of this file.
00001 // -*- indent-tabs-mode: nil -*-
00002 
00003 #ifdef HAVE_CONFIG_H
00004 #include <config.h>
00005 #endif
00006 
00007 #include <sys/stat.h>
00008 #include <fstream>
00009 #include <arc/client/JobDescription.h>
00010 #include <arc/OptionParser.h>
00011 #include <arc/IString.h>
00012 #include <arc/Logger.h>
00013 
00014 int main(int argc, char **argv) {
00015 
00016   Arc::LogStream logcerr(std::cerr);
00017   Arc::Logger::getRootLogger().addDestination(logcerr);
00018   Arc::Logger::getRootLogger().setThreshold(Arc::WARNING);
00019 
00020   Arc::OptionParser options(istring("[job description ...]"),
00021                             istring("This tiny tool can be used for testing"
00022                                     "the JobDescription's conversion abilities."),
00023                             istring("The job description also can be a file or a string in JDL, POSIX JSDL, JSDL, or XRSL format."));
00024 
00025   std::string requested_format = "";
00026   options.AddOption('f', "format",
00027                     istring("define the requested format (ARCJSDL, JDL, XRSL)"),
00028                     istring("format"),
00029                     requested_format);
00030 
00031   bool show_original_description = false;
00032   options.AddOption('o', "original",
00033                     istring("show the original job description"),
00034                     show_original_description);
00035 
00036   std::string debug;
00037   options.AddOption('d', "debug",
00038                     istring("FATAL, ERROR, WARNING, INFO, VERBOSE or DEBUG"),
00039                     istring("debuglevel"), debug);
00040 
00041   std::list<std::string> descriptions = options.Parse(argc, argv);
00042   if (descriptions.empty()) {
00043     std::cout << "Use --help option for detailed usage information" << std::endl;
00044     return 1;
00045   }
00046 
00047   if (!debug.empty())
00048     Arc::Logger::getRootLogger().setThreshold(Arc::string_to_level(debug));
00049 
00050   std::cout << " [ JobDescription tester ] " << std::endl;
00051 
00052   for (std::list<std::string>::iterator it = descriptions.begin(); it != descriptions.end(); it++) {
00053     struct stat stFileInfo;
00054     int intStat;
00055     std::string original_description;
00056 
00057     // Attempt to get the file attributes
00058     intStat = stat((*it).c_str(), &stFileInfo);
00059 
00060     if (intStat == 0) {
00061       // We were able to get the file attributes
00062       // so the file obviously exists.
00063       std::ifstream ifs;
00064       std::string buffer;
00065       ifs.open((*it).c_str(), std::ios::in);
00066       while (std::getline(ifs, buffer))
00067         original_description += buffer + "\n";
00068     }
00069     else
00070       original_description = (*it);
00071 
00072     if (requested_format == "JDL" || requested_format == "ARCJSDL" || requested_format == "XRSL" || requested_format == "") {
00073       Arc::JobDescription jd;
00074 
00075       if (show_original_description) {
00076         std::cout << std::endl << " [ Parsing the orignal text ] " << std::endl << std::endl;
00077         std::cout << original_description << std::endl;
00078       }
00079 
00080       jd.Parse(original_description);
00081 
00082       std::string test;
00083       if (requested_format == "")
00084         jd.Print(true);
00085 
00086       if (requested_format == "JDL" || requested_format == "") {
00087         test = jd.UnParse("JDL");
00088         std::cout << std::endl << " [ JDL ] " << std::endl << test << std::endl;
00089       }
00090 
00091       if (requested_format == "XRSL" || requested_format == "") {
00092         test = jd.UnParse("XRSL");
00093         std::cout << std::endl << " [ XRSL ] " << std::endl << test << std::endl;
00094       }
00095 
00096       if (requested_format == "ARCJSDL" || requested_format == "") {
00097         test = jd.UnParse("ARCJSDL");
00098         std::cout << std::endl << " [ ARCJSDL ] " << std::endl << test << std::endl;
00099       }
00100     }
00101   }
00102 
00103   return 0;
00104 
00105 }