Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

124 righe
4.1 KiB

  1. #!/usr/bin/env python
  2. import os
  3. import tempfile
  4. import sys
  5. import urllib.parse
  6. JS = [
  7. 'js/libpannellum.js',
  8. 'js/RequestAnimationFrame.js',
  9. 'js/pannellum.js'
  10. ]
  11. CSS = [
  12. 'css/pannellum.css'
  13. ]
  14. HTML = [
  15. 'pannellum.htm'
  16. ]
  17. def merge(files):
  18. buffer = []
  19. for filename in files:
  20. with open(os.path.join('../..', 'src', filename), 'r') as f:
  21. buffer.append(f.read())
  22. return "".join(buffer)
  23. def read(filename):
  24. with open(os.path.join('../..','src',filename), 'r') as f:
  25. return f.read()
  26. def output(text, filename):
  27. with open(os.path.join('../..', 'build', filename), 'w') as f:
  28. f.write(text)
  29. def JScompress(text):
  30. in_tuple = tempfile.mkstemp()
  31. with os.fdopen(in_tuple[0], 'w') as handle:
  32. handle.write(text)
  33. out_tuple = tempfile.mkstemp()
  34. os.system("java -jar compiler.jar --language_in=ECMASCRIPT5 --js %s --js_output_file %s" % (in_tuple[1], out_tuple[1]))
  35. with os.fdopen(out_tuple[0], 'r') as handle:
  36. compressed = handle.read()
  37. os.unlink(in_tuple[1])
  38. os.unlink(out_tuple[1])
  39. return compressed
  40. def cssCompress(text):
  41. in_tuple = tempfile.mkstemp()
  42. with os.fdopen(in_tuple[0], 'w') as handle:
  43. handle.write(text)
  44. out_tuple = tempfile.mkstemp()
  45. os.system("java -jar yuicompressor-2.4.7.jar %s --type css -o %s --charset utf-8 -v" % (in_tuple[1], out_tuple[1]))
  46. with os.fdopen(out_tuple[0], 'r') as handle:
  47. compressed = handle.read()
  48. os.unlink(in_tuple[1])
  49. os.unlink(out_tuple[1])
  50. return compressed
  51. def htmlCompress(text):
  52. in_tuple = tempfile.mkstemp()
  53. with os.fdopen(in_tuple[0], 'w') as handle:
  54. handle.write(text)
  55. out_tuple = tempfile.mkstemp()
  56. os.system("java -jar htmlcompressor-1.5.3.jar --remove-intertag-spaces --remove-quotes -o %s %s" % (out_tuple[1], in_tuple[1]))
  57. with os.fdopen(out_tuple[0], 'r') as handle:
  58. compressed = handle.read()
  59. os.unlink(in_tuple[1])
  60. os.unlink(out_tuple[1])
  61. return compressed
  62. def addHeader(text):
  63. text = text.replace('<!DOCTYPE HTML>','');
  64. header = '<!DOCTYPE HTML>\n<!-- Pannellum ' + read('../VERSION') + ', https://github.com/mpetroff/pannellum -->\n'
  65. return header + text
  66. def build(files, css, html, filename):
  67. folder = ''
  68. os.makedirs('../../build', exist_ok=True)
  69. cssfilename = filename + '.css'
  70. htmlfilename = filename + '.htm'
  71. filename = filename + '.js'
  72. print('=' * 40)
  73. print('Compiling', filename)
  74. print('=' * 40)
  75. js = merge(files)
  76. js = JScompress(js)
  77. print('=' * 40)
  78. print('Compiling', cssfilename)
  79. print('=' * 40)
  80. css = merge(css)
  81. css = css.replace("'img/grab.svg'","'data:image/svg+xml," + urllib.parse.quote(read('css/img/grab.svg'),'') + "'")
  82. css = css.replace("'img/grabbing.svg'","'data:image/svg+xml," + urllib.parse.quote(read('css/img/grabbing.svg'),'') + "'")
  83. css = cssCompress(css)
  84. css = css.replace("'img/sprites.svg'","'data:image/svg+xml," + urllib.parse.quote(read('css/img/sprites.svg'),'') + "'")
  85. css = css.replace("'img/background.svg'","'data:image/svg+xml," + urllib.parse.quote(read('css/img/background.svg'),'') + "'")
  86. css = css.replace("'img/compass.svg'","'data:image/svg+xml," + urllib.parse.quote(read('css/img/compass.svg'),'') + "'")
  87. print('=' * 40)
  88. print('Compiling', htmlfilename)
  89. print('=' * 40)
  90. html = merge(html)
  91. html = html.replace('<link type="text/css" rel="Stylesheet" href="css/pannellum.css" />','<style type="text/css">' + css + '</style>')
  92. html = html.replace('<script type="text/javascript" src="js/libpannellum.js"></script>','')
  93. html = html.replace('<script type="text/javascript" src="js/RequestAnimationFrame.js"></script>','')
  94. html = html.replace('<script type="text/javascript" src="js/pannellum.js"></script>','<script type="text/javascript">' + js + '</script>')
  95. html = html.replace('"_blank">Pannellum</a></span>','"_blank">Pannellum</a> ' + read('../VERSION') + '</span>')
  96. html = htmlCompress(html)
  97. output(addHeader(html), folder + htmlfilename)
  98. def main():
  99. build(JS, CSS, HTML, 'pannellum')
  100. if __name__ == "__main__":
  101. main()