wuget.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #include "jlib.hpp"
  14. #include "jfile.hpp"
  15. #include "thorplugin.hpp"
  16. #include "workunit.hpp"
  17. void usage(const char *progname)
  18. {
  19. printf("%s - extract workunit information from query dll.\nUsage: %s [-m] [-w] filename\n", progname, progname);
  20. printf("Options:\n");
  21. printf(" -m Display manifest information\n");
  22. printf(" -w Display embedded workunit\n");
  23. printf(" -a Display embedded archive\n");
  24. printf("/nIf no options specified, -w is assumed\n");
  25. }
  26. int main(int argc, char **argv)
  27. {
  28. InitModuleObjects();
  29. bool doManifestInfo = false;
  30. bool doWorkunit = false;
  31. bool doArchive = false;
  32. for (int i = 1; i < argc; i++)
  33. {
  34. if (argv[i][0]=='-')
  35. {
  36. if (strcmp(argv[i], "-m")==0)
  37. doManifestInfo = true;
  38. else if (strcmp(argv[i], "-w")==0)
  39. doWorkunit = true;
  40. else if (strcmp(argv[i], "-a")==0)
  41. doArchive = true;
  42. else
  43. {
  44. usage(argv[0]);
  45. return 1;
  46. }
  47. }
  48. }
  49. if (!doArchive && !doManifestInfo && !doWorkunit)
  50. doWorkunit = true;
  51. int filesSeen = 0;
  52. int errors = 0;
  53. for (int i = 1; i < argc; i++)
  54. {
  55. if (argv[i][0]!='-')
  56. {
  57. try
  58. {
  59. filesSeen++;
  60. if (doWorkunit || doArchive)
  61. {
  62. const char *filename = argv[i];
  63. const char *ext = pathExtension(filename);
  64. StringBuffer xml;
  65. if (strisame(ext, ".xml"))
  66. xml.loadFile(filename, false);
  67. else
  68. getWorkunitXMLFromFile(filename, xml);
  69. if (xml.length())
  70. {
  71. Owned<ILocalWorkUnit> wu = createLocalWorkUnit(xml);
  72. if (getArchiveXMLFromFile(filename, xml.clear()))
  73. {
  74. Owned<IWUQuery> q = wu->updateQuery();
  75. q->setQueryText(xml);
  76. }
  77. if (doWorkunit)
  78. {
  79. exportWorkUnitToXML(wu, xml.clear(), true, false, true);
  80. printf("%s\n", xml.str());
  81. }
  82. if (doArchive)
  83. {
  84. Owned<IConstWUQuery> query = wu->getQuery();
  85. if (query)
  86. {
  87. SCMStringBuffer text;
  88. query->getQueryText(text);
  89. printf("%s\n", text.s.str());
  90. }
  91. else
  92. printf("No archive found\n");
  93. }
  94. }
  95. else
  96. {
  97. fprintf(stderr, "Could not load workunit from %s\n", argv[i]);
  98. errors++;
  99. }
  100. }
  101. if (doManifestInfo)
  102. {
  103. StringBuffer xml;
  104. if (getManifestXMLFromFile(argv[i], xml))
  105. {
  106. printf("%s\n", xml.str());
  107. }
  108. else
  109. {
  110. fprintf(stderr, "Could not load manifest from %s\n", argv[i]);
  111. errors++;
  112. }
  113. }
  114. }
  115. catch (IException *E)
  116. {
  117. StringBuffer msg;
  118. fprintf(stderr, "Exception %d: %s processing argument %s\n", E->errorCode(), E->errorMessage(msg).str(), argv[i]);
  119. errors++;
  120. E->Release();
  121. }
  122. }
  123. }
  124. if (!filesSeen)
  125. {
  126. fprintf(stderr, "No files specified\n");
  127. errors++;
  128. }
  129. return errors ? 1 : 0;
  130. }