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

10 лет назад
12 лет назад
12 лет назад
12 лет назад
12 лет назад
12 лет назад
12 лет назад
10 лет назад
12 лет назад
10 лет назад
12 лет назад
10 лет назад
12 лет назад
10 лет назад
12 лет назад
12 лет назад
12 лет назад
12 лет назад
10 лет назад
8 лет назад
10 лет назад
12 лет назад
12 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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/pannellum.js',
  10. ]
  11. CSS = [
  12. 'css/pannellum.css',
  13. ]
  14. HTML = [
  15. 'standalone/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 --warning_level=QUIET --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 addHeaderHTML(text, version):
  63. text = text.replace('<!DOCTYPE HTML>','');
  64. header = '<!DOCTYPE HTML>\n<!-- Pannellum ' + version + ', https://github.com/mpetroff/pannellum -->\n'
  65. return header + text
  66. def addHeaderCSS(text, version):
  67. header = '/* Pannellum ' + version + ', https://github.com/mpetroff/pannellum */\n'
  68. return header + text
  69. def addHeaderJS(text, version):
  70. header = '// Pannellum ' + version + ', https://github.com/mpetroff/pannellum\n'
  71. return header + text
  72. def build(files, css, html, filename, release=False):
  73. folder = ''
  74. os.makedirs('../../build', exist_ok=True)
  75. cssfilename = filename + '.css'
  76. htmlfilename = filename + '.htm'
  77. filename = filename + '.js'
  78. print('=' * 40)
  79. print('Compiling', filename)
  80. print('=' * 40)
  81. js = merge(files)
  82. if release:
  83. version = read('../VERSION').strip()
  84. else:
  85. if os.path.exists('../../.git'):
  86. version = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode('utf-8').strip()
  87. else:
  88. print('No .git folder detected, setting version to testing')
  89. version = "testing"
  90. js = js.replace('"_blank">Pannellum</a>','"_blank">Pannellum</a> ' + version)
  91. with open('../../src/standalone/standalone.js', 'r') as f:
  92. standalone_js = f.read()
  93. standalone_js = JScompress(js + standalone_js)
  94. js = JScompress(js)
  95. print('=' * 40)
  96. print('Compiling', cssfilename)
  97. print('=' * 40)
  98. css = merge(css)
  99. css = css.replace("'img/grab.svg'","'data:image/svg+xml," + urllib.parse.quote(read('css/img/grab.svg'),'') + "'")
  100. css = css.replace("'img/grabbing.svg'","'data:image/svg+xml," + urllib.parse.quote(read('css/img/grabbing.svg'),'') + "'")
  101. with open('../../src/standalone/standalone.css', 'r') as f:
  102. standalone_css = f.read()
  103. standalone_css = cssCompress(css + standalone_css)
  104. standalone_css = standalone_css.replace("'img/sprites.svg'","'data:image/svg+xml," + urllib.parse.quote(read('css/img/sprites.svg'),'') + "'")
  105. standalone_css = standalone_css.replace("'img/background.svg'","'data:image/svg+xml," + urllib.parse.quote(read('css/img/background.svg'),'') + "'")
  106. standalone_css = standalone_css.replace("'img/compass.svg'","'data:image/svg+xml," + urllib.parse.quote(read('css/img/compass.svg'),'') + "'")
  107. css = cssCompress(css)
  108. css = css.replace("'img/sprites.svg'","'data:image/svg+xml," + urllib.parse.quote(read('css/img/sprites.svg'),'') + "'")
  109. css = css.replace("'img/background.svg'","'data:image/svg+xml," + urllib.parse.quote(read('css/img/background.svg'),'') + "'")
  110. css = css.replace("'img/compass.svg'","'data:image/svg+xml," + urllib.parse.quote(read('css/img/compass.svg'),'') + "'")
  111. print('=' * 40)
  112. print('Compiling', htmlfilename)
  113. print('=' * 40)
  114. html = merge(html)
  115. html = html.replace('<link type="text/css" rel="Stylesheet" href="../css/pannellum.css"/>','<style type="text/css">' + standalone_css + '</style>')
  116. html = html.replace('<script type="text/javascript" src="../js/libpannellum.js"></script>','')
  117. html = html.replace('<script type="text/javascript" src="../js/pannellum.js"></script>','<script type="text/javascript">' + standalone_js + '</script>')
  118. html = html.replace('<script type="text/javascript" src="standalone.js"></script>','')
  119. html = html.replace('<link type="text/css" rel="Stylesheet" href="standalone.css"/>', '')
  120. html = htmlCompress(html)
  121. output(addHeaderHTML(html, version), folder + htmlfilename)
  122. output(addHeaderCSS(css, version), folder + cssfilename)
  123. output(addHeaderJS(js, version), folder + filename)
  124. def main():
  125. os.chdir(os.path.dirname(os.path.abspath(__file__))) # cd to script dir
  126. if (len(sys.argv) > 1 and sys.argv[1] == 'release'):
  127. build(JS, CSS, HTML, 'pannellum', True)
  128. else:
  129. build(JS, CSS, HTML, 'pannellum')
  130. if __name__ == "__main__":
  131. main()