Indexer.hx 2.9 KB

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