Indexer.hx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package runci;
  2. import sys.io.*;
  3. using StringTools;
  4. class Indexer
  5. {
  6. static function main():Void {
  7. switch (Sys.args()) {
  8. case []:
  9. throw "missing s3 path argument";
  10. case [s3path]:
  11. index(s3path);
  12. }
  13. }
  14. public static function index(s3path:String)
  15. {
  16. var spaceRegex = ~/[ \t]+/g,
  17. s3pathRegex = ~/s3:\/\/([^\/]+)/;
  18. if (!s3path.endsWith('/')) {
  19. s3path = '$s3path/';
  20. }
  21. if (!s3pathRegex.match(s3path)) {
  22. throw 'Invalid s3 path $s3path';
  23. }
  24. var basePath = 'http://' + s3pathRegex.matched(1) + '.s3-website-us-east-1.amazonaws.com' + s3pathRegex.matchedRight();
  25. var proc = new Process('aws',['s3','ls',s3path,'--region','us-east-1']);
  26. var records = [],
  27. dirs = [];
  28. try
  29. {
  30. var i = proc.stdout;
  31. while(true)
  32. {
  33. var ln = spaceRegex.split(i.readLine());
  34. // trace(ln);
  35. inline function getPath(path:String)
  36. {
  37. return basePath + path;
  38. }
  39. switch(ln[1])
  40. {
  41. case 'PRE':
  42. dirs.push(getPath(ln[2]));
  43. case _:
  44. var size = ln[2];
  45. var path = ln[3];
  46. path = getPath(path);
  47. records.push({ date: ln[0] + ' ' + ln[1], size: ln[2], path: path, fname:haxe.io.Path.withoutDirectory(path) });
  48. }
  49. }
  50. }
  51. catch(e:haxe.io.Eof) {}
  52. var maxSizes = { date:25, size:15, fname:0 };
  53. for (r in records)
  54. {
  55. if (r.date.length > maxSizes.date)
  56. maxSizes.date = r.date.length;
  57. if (r.size.length > maxSizes.size)
  58. maxSizes.size = r.size.length;
  59. if (r.fname.length > maxSizes.fname)
  60. maxSizes.fname = r.fname.length;
  61. }
  62. records.sort(function(v1,v2) return Reflect.compare(v2.date,v1.date));
  63. var index = sys.io.File.write('index.html');
  64. index.writeString(
  65. '
  66. <html>
  67. <head>
  68. <title>Haxe git builds</title>
  69. </head>
  70. <body>
  71. <!-- Google Tag Manager -->
  72. <noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-M4JZKD"
  73. height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
  74. <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({"gtm.start":
  75. new Date().getTime(),event:"gtm.js"});var f=d.getElementsByTagName(s)[0],
  76. j=d.createElement(s),dl=l!="dataLayer"?"&l="+l:"";j.async=true;j.src=
  77. "//www.googletagmanager.com/gtm.js?id="+i+dl;f.parentNode.insertBefore(j,f);
  78. })(window,document,"script","dataLayer","GTM-M4JZKD");</script>
  79. <!-- End Google Tag Manager -->
  80. <div id="listing">
  81. <pre>
  82. ');
  83. inline function data(date:String,size:String,key:String,path:String)
  84. {
  85. index.writeString(date.rpad(' ',maxSizes.date));
  86. index.writeString(size.rpad(' ',maxSizes.size));
  87. if (path != null && path != '')
  88. index.writeString('<a href="$path">$key</a>\n');
  89. else
  90. index.writeString('$key\n');
  91. }
  92. data('Last Modified', 'Size', 'Path','');
  93. for (i in 0...(maxSizes.date + maxSizes.size + maxSizes.fname + 5))
  94. index.writeString('-');
  95. index.writeString('\n\n');
  96. for (dir in dirs)
  97. data('','DIR',haxe.io.Path.withoutDirectory(dir.substr(0,dir.length-1)),dir);
  98. for (r in records)
  99. if (r.fname != 'index.html')
  100. data(r.date,r.size,r.fname,r.path);
  101. index.writeString(
  102. '
  103. </pre>
  104. </div>
  105. </body>
  106. </html>
  107. ');
  108. index.close();
  109. }
  110. }