utils.tin 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 {existsJobPlugin} {
  58. #local job {%1};
  59. #return {@existsPlugin{job/$job}};
  60. };
  61. #func {existsPlugin} {
  62. #local plugin {%1};
  63. #if { @existsFile{plugins/${plugin}.tin} } {
  64. #return 1;
  65. };
  66. #if { @existsFile{plugins/$plugin/__init__.tin} } {
  67. #return 1;
  68. };
  69. #if { @existsFile{plugins/$plugin/__main__.tin} } {
  70. #return 1;
  71. };
  72. #return 0;
  73. };
  74. #func {mkdir} {
  75. #local dir {%1};
  76. #local output {};
  77. #line quiet #script output {mkdir -p $dir 2>/dev/null && test -d $dir && echo 1 || echo 0};
  78. #return $output[1];
  79. };
  80. #func {uuid} {
  81. #local now {};
  82. #local random {};
  83. #math random {1d1000};
  84. #format random {%%03d} {$random};
  85. #format now {%U};
  86. #return {${now}.$random};
  87. };
  88. #alias {load-config} {
  89. #local config {%1};
  90. #if { @isEmpty{$config} } {
  91. xtt.Usage load-config;
  92. #return;
  93. };
  94. load-file etc/${config}.tin;
  95. };