utils.tin 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #nop vim: set filetype=tt:;
  2. /*
  3. 模块名称:框架依赖的工具函数
  4. 模块说明:本文件属于框架代码的一部分,不建议修改。如有需求请在 GitHub 发 issue 或者 PR
  5. 版权声明:本文件属于 PaoTin++ 的一部分
  6. ===========
  7. PaoTin++ © 2020~2023 的所有版权均由担子炮(dzp <danzipao@gmail.com>) 享有并保留一切法律权利
  8. 你可以在遵照 GPLv3 协议的基础之上使用、修改及重新分发本程序。
  9. ===========
  10. */
  11. #func {existsSession} {
  12. #local session {%1};
  13. #if { !@existsFunction{$session} && {@{$session}{true}} == {true} } {
  14. #return 1;
  15. };
  16. #else {
  17. #return 0;
  18. };
  19. };
  20. #func {existsVar} {
  21. #local var {%1};
  22. #if { &{$var} > 0 } {
  23. #return 1;
  24. };
  25. #else {
  26. #return 0;
  27. };
  28. };
  29. #func {existsAlias} {
  30. #local pName {%1};
  31. #local pClass {%2};
  32. #info alias save;
  33. #local idx {};
  34. #foreach {*{info[ALIASES][]}} {idx} {
  35. #local name {$info[ALIASES][$idx][arg1]};
  36. #local class {$info[ALIASES][$idx][class]};
  37. #if { "$name" == "$pName" && ( "$pClass" == "" || "$class" == "$pClass" ) } {
  38. #return 1;
  39. };
  40. };
  41. #return 0;
  42. };
  43. #func {existsFunction} {
  44. #local pName {%1};
  45. #local pClass {%2};
  46. #info function save;
  47. #local idx {};
  48. #foreach {*{info[FUNCTIONS][]}} {idx} {
  49. #local name {$info[FUNCTIONS][$idx][arg1]};
  50. #local class {$info[FUNCTIONS][$idx][class]};
  51. #if { "$name" == "$pName" && ( "$pClass" == "" || "$class" == "$pClass" ) } {
  52. #return 1;
  53. };
  54. };
  55. #return 0;
  56. };
  57. #func {existsFile} {
  58. #local file {%1};
  59. #local output {};
  60. #script output {test -f $file && echo 1 || test -f var/$file && echo 1 || echo 0};
  61. #return $output[1];
  62. };
  63. #func {existsJobPlugin} {
  64. #local job {%1};
  65. #return {@existsPlugin{job/$job}};
  66. };
  67. #func {existsPlugin} {
  68. #local plugin {%1};
  69. #if { @existsFile{plugins/${plugin}.tin} } {
  70. #return 1;
  71. };
  72. #if { @existsFile{plugins/$plugin/__init__.tin} } {
  73. #return 1;
  74. };
  75. #if { @existsFile{plugins/$plugin/__main__.tin} } {
  76. #return 1;
  77. };
  78. #return 0;
  79. };
  80. #func {mkdir} {
  81. #local dir {%1};
  82. #local output {};
  83. #script output {mkdir -p $dir 2>/dev/null && test -d $dir && echo 1 || echo 0};
  84. #return $output[1];
  85. };
  86. #func {uuid} {
  87. #local now {};
  88. #local random {};
  89. #math random {1d1000};
  90. #format random {%%03d} {$random};
  91. #format now {%U};
  92. #return {${now}.$random};
  93. };
  94. #alias {load-config} {
  95. #local config {%1};
  96. #if { @isEmpty{$config} } {
  97. xtt.Usage load-config;
  98. #return;
  99. };
  100. load-file etc/${config}.tin;
  101. };