make_apk_list.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #! /usr/bin/env python
  2. # Copyright 2018 Google LLC.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. from subprocess import check_output, CalledProcessError
  6. import os
  7. import re
  8. import sys
  9. import tempfile
  10. HEADER = '''<!DOCTYPE html>
  11. <html lang="en">
  12. <head>
  13. <meta charset="utf-8">
  14. <title>SkQP Pre-built APKs</title>
  15. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  16. <style>
  17. body {
  18. font-family:sans-serif;
  19. max-width:50em;
  20. margin:8px auto;
  21. padding:0 8px;
  22. }
  23. table { max-width:100%; border-collapse: collapse; }
  24. td { padding:12px 8px; vertical-align:top; }
  25. tr:nth-child(even) {background: #F2F2F2; color:#000;}
  26. tr:nth-child(odd) {background: #FFFFFF; color:#000;}
  27. </style>
  28. </head>
  29. <body>
  30. <h1>SkQP Pre-built APKs</h1>
  31. '''
  32. FOOTER = '</body>\n</html>\n'
  33. BUCKET = 'skia-skqp'
  34. NAME_FMT = 'skqp-universal-%s.apk'
  35. def get_existing_files():
  36. cmd = ['gsutil', 'ls', 'gs://' + BUCKET]
  37. try:
  38. output = check_output(cmd)
  39. except (OSError, CalledProcessError):
  40. sys.stderr.write('command: "%s" failed.\n' % ' '.join(cmd))
  41. sys.exit(1)
  42. result = set()
  43. regex = re.compile('gs://%s/%s' % (BUCKET, NAME_FMT % '([0-9a-f]+)'))
  44. for line in output.split('\n'):
  45. m = regex.match(line.strip())
  46. if m is not None:
  47. result.add(m.group(1))
  48. return result
  49. def find(v, extant):
  50. l = min(16, len(v))
  51. while l > 8:
  52. if v[:l] in extant:
  53. return v[:l]
  54. l -= 1
  55. return None
  56. def nowrap(s):
  57. return (s.replace(' ', u'\u00A0'.encode('utf-8'))
  58. .replace('-', u'\u2011'.encode('utf-8')))
  59. def table(o, from_commit, to_commit):
  60. env_copy = os.environ.copy()
  61. env_copy['TZ'] = ''
  62. extant = get_existing_files()
  63. o.write('<h2>%s %s</h2>\n' % (to_commit, ' '.join(from_commit)))
  64. o.write('<table>\n<tr><th>APK</th><th>Date</th><th>Commit</th></tr>\n')
  65. git_cmd = ['git', 'log', '--format=%H;%cd;%<(100,trunc)%s',
  66. '--date=format-local:%Y-%m-%d %H:%M:%S %Z'
  67. ] + from_commit + [to_commit]
  68. commits = check_output(git_cmd, env=env_copy)
  69. for line in commits.split('\n'):
  70. line = line.strip()
  71. if not line:
  72. continue
  73. commit, date, subj = line.split(';', 2)
  74. short = find(commit, extant)
  75. if short is not None:
  76. apk_name = NAME_FMT % short
  77. url = 'https://storage.googleapis.com/%s/%s' % (BUCKET, apk_name)
  78. else:
  79. apk_name, url = '', ''
  80. commit_url = 'https://skia.googlesource.com/skia/+/' + commit
  81. o.write('<tr>\n<td><a href="%s">%s</a></td>\n'
  82. '<td>%s</td>\n<td><a href="%s">%s</a></td>\n</tr>\n' %
  83. (url, nowrap(apk_name), nowrap(date), commit_url, subj))
  84. o.write('</table>\n')
  85. def main():
  86. assert '/' in [os.sep, os.altsep] and '..' == os.pardir
  87. os.chdir(os.path.join(os.path.dirname(__file__), '../..'))
  88. d = tempfile.mkdtemp()
  89. path = os.path.join(d, 'apklist.html')
  90. with open(path, 'w') as o:
  91. o.write(HEADER)
  92. table(o, ['^origin/master', '^3e34285f2a0'], 'origin/skqp/dev')
  93. table(o, ['^origin/master'], 'origin/skqp/release')
  94. o.write(FOOTER)
  95. print path
  96. gscmd = 'gsutil -h "Content-Type:text/html" cp "%s" gs://skia-skqp/apklist'
  97. print gscmd % path
  98. if __name__ == '__main__':
  99. main()