Util.ecl 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*##############################################################################
  2. ## HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®. All rights reserved.
  3. ############################################################################## */
  4. import lib_fileservices;
  5. /**
  6. * Various utility functions for accessing system function.
  7. */
  8. RETURN MODULE
  9. /**
  10. * Execute an external program.
  11. *
  12. * @param prog The name of the program to excute. Can include command line options.
  13. * @param src The text that is piped into the program as stdin.
  14. * @returns The text output from the pipe program.
  15. */
  16. EXPORT string CmdProcess(varstring prog, string src) :=
  17. lib_fileservices.FileServices.CmdProcess2(prog, src);
  18. /**
  19. * Returns the host name associated with a particular ip.
  20. *
  21. * @param ipaddress The ip address to resolve.
  22. * @returns The host name.
  23. */
  24. EXPORT varstring GetHostName(varstring ipaddress ) :=
  25. lib_fileservices.FileServices.GetHostName(ipaddress );
  26. /**
  27. * Returns the ip address for a host name.
  28. *
  29. * @param hostname The name of the host to resolve.
  30. * @returns The associated ip address.
  31. */
  32. EXPORT varstring ResolveHostName(varstring hostname ) :=
  33. lib_fileservices.FileServices.ResolveHostName(hostname );
  34. /**
  35. * Returns a number that is unique for a particular dali.
  36. *
  37. * @param foreigndali The ip address of the dali to provide the unique number. Defaults to current.
  38. * @returns A 64bit integer which is unique (e.g., across all slaves) to the dali that provided it.
  39. */
  40. EXPORT unsigned8 getUniqueInteger(varstring foreigndali='') :=
  41. lib_fileservices.FileServices.getUniqueInteger(foreigndali);
  42. /**
  43. * Simple function that tests a full version string against the individual
  44. * platform version constants to determine if the platform's version is at
  45. * least as high as the argument.
  46. *
  47. * Note that this function will be evaluated at compile-time if the argument
  48. * is a constant. This makes it useful for embedding in #IF() declarations:
  49. *
  50. * #IF(PlatformVersionCheck('6.2.0-1'))
  51. * OUTPUT('Platform check TRUE');
  52. * #ELSE
  53. * OUTPUT('Platform check FALSE');
  54. * #END
  55. *
  56. * @param v The minimum platform version in either xx.xx.xx, xx.xx,
  57. * or xx format (where xx is an integer and does not need
  58. * to be zero-padded); extra trailing characters (such as
  59. * the '-1' in the example above) are ignored; REQUIRED
  60. *
  61. * @return If TRUE, the platform's current version is equal to or higher than
  62. * the argument.
  63. */
  64. EXPORT PlatformVersionCheck(STRING v) := FUNCTION
  65. major := (INTEGER)REGEXFIND('^(\\d+)', v, 1);
  66. minor := (INTEGER)REGEXFIND('^\\d+\\.(\\d+)', v, 1);
  67. subminor := (INTEGER)REGEXFIND('^\\d+\\.\\d+\\.(\\d+)', v, 1);
  68. RETURN MAP
  69. (
  70. __ecl_version_major__ > major => TRUE,
  71. __ecl_version_major__ = major AND __ecl_version_minor__ > minor => TRUE,
  72. __ecl_version_major__ = major AND __ecl_version_minor__ = minor AND __ecl_version_subminor__ >= subminor => TRUE,
  73. FALSE
  74. );
  75. END;
  76. END;