Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

10 лет назад
12 лет назад
12 лет назад
12 лет назад
12 лет назад
12 лет назад
12 лет назад
12 лет назад
10 лет назад
12 лет назад
10 лет назад
12 лет назад
10 лет назад
12 лет назад
10 лет назад
12 лет назад
12 лет назад
12 лет назад
12 лет назад
10 лет назад
8 лет назад
10 лет назад
12 лет назад
12 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #!/usr/bin/env python3
  2. import os
  3. import tempfile
  4. import sys
  5. import subprocess
  6. import urllib.parse
  7. JS = [
  8. 'js/libpannellum.js',
  9. 'js/RequestAnimationFrame.js',
  10. 'js/pannellum.js',
  11. ]
  12. CSS = [
  13. 'css/pannellum.css',
  14. ]
  15. HTML = [
  16. 'standalone/pannellum.htm'
  17. ]
  18. def merge(files):
  19. buffer = []
  20. for filename in files:
  21. with open(os.path.join('../..', 'src', filename), 'r') as f:
  22. buffer.append(f.read())
  23. return "".join(buffer)
  24. def read(filename):
  25. with open(os.path.join('../..','src',filename), 'r') as f:
  26. return f.read()
  27. def output(text, filename):
  28. with open(os.path.join('../..', 'build', filename), 'w') as f:
  29. f.write(text)
  30. def JScompress(text):
  31. in_tuple = tempfile.mkstemp()
  32. with os.fdopen(in_tuple[0], 'w') as handle:
  33. handle.write(text)
  34. out_tuple = tempfile.mkstemp()
  35. os.system("java -jar compiler.jar --language_in=ECMASCRIPT5 --warning_level=QUIET --js %s --js_output_file %s" % (in_tuple[1], out_tuple[1]))
  36. with os.fdopen(out_tuple[0], 'r') as handle:
  37. compressed = handle.read()
  38. os.unlink(in_tuple[1])
  39. os.unlink(out_tuple[1])
  40. return compressed
  41. def cssCompress(text):
  42. in_tuple = tempfile.mkstemp()
  43. with os.fdopen(in_tuple[0], 'w') as handle:
  44. handle.write(text)
  45. out_tuple = tempfile.mkstemp()
  46. os.system("java -jar yuicompressor-2.4.7.jar %s --type css -o %s --charset utf-8 -v" % (in_tuple[1], out_tuple[1]))
  47. with os.fdopen(out_tuple[0], 'r') as handle:
  48. compressed = handle.read()
  49. os.unlink(in_tuple[1])
  50. os.unlink(out_tuple[1])
  51. return compressed
  52. def htmlCompress(text):
  53. in_tuple = tempfile.mkstemp()
  54. with os.fdopen(in_tuple[0], 'w') as handle:
  55. handle.write(text)
  56. out_tuple = tempfile.mkstemp()
  57. os.system("java -jar htmlcompressor-1.5.3.jar --remove-intertag-spaces --remove-quotes -o %s %s" % (out_tuple[1], in_tuple[1]))
  58. with os.fdopen(out_tuple[0], 'r') as handle:
  59. compressed = handle.read()
  60. os.unlink(in_tuple[1])
  61. os.unlink(out_tuple[1])
  62. return compressed
  63. def addHeaderHTML(text, version):
  64. text = text.replace('<!DOCTYPE HTML>','');
  65. header = '<!DOCTYPE HTML>\n<!-- Pannellum ' + version + ', https://github.com/mpetroff/pannellum -->\n'
  66. return header + text
  67. def addHeaderCSS(text, version):
  68. header = '/* Pannellum ' + version + ', https://github.com/mpetroff/pannellum */\n'
  69. return header + text
  70. def addHeaderJS(text, version):
  71. header = '// Pannellum ' + version + ', https://github.com/mpetroff/pannellum\n'
  72. return header + text
  73. def build(files, css, html, filename, release=False):
  74. folder = ''
  75. os.makedirs('../../build', exist_ok=True)
  76. cssfilename = filename + '.css'
  77. htmlfilename = filename + '.htm'
  78. filename = filename + '.js'
  79. print('=' * 40)
  80. print('Compiling', filename)
  81. print('=' * 40)
  82. js = merge(files)
  83. if release:
  84. version = read('../VERSION').strip()
  85. else:
  86. version = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode('utf-8').strip()
  87. js = js.replace('"_blank">Pannellum</a>','"_blank">Pannellum</a> ' + version)
  88. with open('../../src/standalone/standalone.js', 'r') as f:
  89. standalone_js = f.read()
  90. standalone_js = JScompress(js + standalone_js)
  91. js = JScompress(js)
  92. print('=' * 40)
  93. print('Compiling', cssfilename)
  94. print('=' * 40)
  95. css = merge(css)
  96. css = css.replace("'img/grab.svg'","'data:image/svg+xml," + urllib.parse.quote(read('css/img/grab.svg'),'') + "'")
  97. css = css.replace("'img/grabbing.svg'","'data:image/svg+xml," + urllib.parse.quote(read('css/img/grabbing.svg'),'') + "'")
  98. with open('../../src/standalone/standalone.css', 'r') as f:
  99. standalone_css = f.read()
  100. standalone_css = cssCompress(css + standalone_css)
  101. standalone_css = standalone_css.replace("'img/sprites.svg'","'data:image/svg+xml," + urllib.parse.quote(read('css/img/sprites.svg'),'') + "'")
  102. standalone_css = standalone_css.replace("'img/background.svg'","'data:image/svg+xml," + urllib.parse.quote(read('css/img/background.svg'),'') + "'")
  103. standalone_css = standalone_css.replace("'img/compass.svg'","'data:image/svg+xml," + urllib.parse.quote(read('css/img/compass.svg'),'') + "'")
  104. css = cssCompress(css)
  105. css = css.replace("'img/sprites.svg'","'data:image/svg+xml," + urllib.parse.quote(read('css/img/sprites.svg'),'') + "'")
  106. css = css.replace("'img/background.svg'","'data:image/svg+xml," + urllib.parse.quote(read('css/img/background.svg'),'') + "'")
  107. css = css.replace("'img/compass.svg'","'data:image/svg+xml," + urllib.parse.quote(read('css/img/compass.svg'),'') + "'")
  108. print('=' * 40)
  109. print('Compiling', htmlfilename)
  110. print('=' * 40)
  111. html = merge(html)
  112. html = html.replace('<link type="text/css" rel="Stylesheet" href="../css/pannellum.css"/>','<style type="text/css">' + standalone_css + '</style>')
  113. html = html.replace('<script type="text/javascript" src="../js/libpannellum.js"></script>','')
  114. html = html.replace('<script type="text/javascript" src="../js/RequestAnimationFrame.js"></script>','')
  115. html = html.replace('<script type="text/javascript" src="../js/pannellum.js"></script>','<script type="text/javascript">' + standalone_js + '</script>')
  116. html = html.replace('<script type="text/javascript" src="standalone.js"></script>','')
  117. html = html.replace('<link type="text/css" rel="Stylesheet" href="standalone.css"/>', '')
  118. html = htmlCompress(html)
  119. output(addHeaderHTML(html, version), folder + htmlfilename)
  120. output(addHeaderCSS(css, version), folder + cssfilename)
  121. output(addHeaderJS(js, version), folder + filename)
  122. def main():
  123. if (len(sys.argv) > 1 and sys.argv[1] == 'release'):
  124. build(JS, CSS, HTML, 'pannellum', True)
  125. else:
  126. build(JS, CSS, HTML, 'pannellum')
  127. if __name__ == "__main__":
  128. main()