PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/dev-tools/get-bwc-version.py

https://gitlab.com/sharadag/elasticsearch
Python | 89 lines | 56 code | 12 blank | 21 comment | 15 complexity | 2e8248a5d9af470a96a6f61866a3e1a3 MD5 | raw file
  1. # Licensed to Elasticsearch under one or more contributor
  2. # license agreements. See the NOTICE file distributed with
  3. # this work for additional information regarding copyright
  4. # ownership. Elasticsearch licenses this file to you under
  5. # the Apache License, Version 2.0 (the "License"); you may
  6. # not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing,
  12. # software distributed under the License is distributed on
  13. # an 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  14. # either express or implied. See the License for the specific
  15. # language governing permissions and limitations under the License.
  16. '''
  17. Downloads and extracts elasticsearch for backwards compatibility tests.
  18. '''
  19. import argparse
  20. import os
  21. import platform
  22. import shutil
  23. import subprocess
  24. import urllib.request
  25. import zipfile
  26. def parse_config():
  27. parser = argparse.ArgumentParser(description=__doc__)
  28. parser.add_argument('--path', metavar='DIR', default='./backwards',
  29. help='Where to extract elasticsearch')
  30. parser.add_argument('--force', action='store_true', default=False,
  31. help='Delete and redownload if the version already exists')
  32. parser.add_argument('version', metavar='X.Y.Z',
  33. help='Version of elasticsearch to grab')
  34. return parser.parse_args()
  35. def main():
  36. c = parse_config()
  37. if not os.path.exists(c.path):
  38. print('Creating %s' % c.path)
  39. os.mkdir(c.path)
  40. is_windows = platform.system() == 'Windows'
  41. os.chdir(c.path)
  42. version_dir = 'elasticsearch-%s' % c.version
  43. if os.path.exists(version_dir):
  44. if c.force:
  45. print('Removing old download %s' % version_dir)
  46. shutil.rmtree(version_dir)
  47. else:
  48. print('Version %s exists at %s' % (c.version, version_dir))
  49. return
  50. # before 1.4.0, the zip file contains windows scripts, and tar.gz contained *nix scripts
  51. if is_windows:
  52. filename = '%s.zip' % version_dir
  53. else:
  54. filename = '%s.tar.gz' % version_dir
  55. if c.version == '1.2.0':
  56. # 1.2.0 was pulled from download.elasticsearch.org because of routing bug:
  57. url = 'http://central.maven.org/maven2/org/elasticsearch/elasticsearch/1.2.0/%s' % filename
  58. elif c.version.startswith('0.') or c.version.startswith('1.'):
  59. url = 'https://download.elasticsearch.org/elasticsearch/elasticsearch/%s' % filename
  60. else:
  61. url = 'http://download.elasticsearch.org/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/%s/%s' % (c.version, filename)
  62. print('Downloading %s' % url)
  63. urllib.request.urlretrieve(url, filename)
  64. print('Extracting to %s' % version_dir)
  65. if is_windows:
  66. archive = zipfile.ZipFile(filename)
  67. archive.extractall()
  68. else:
  69. # for some reason python's tarfile module has trouble with ES tgz?
  70. subprocess.check_call('tar -xzf %s' % filename, shell=True)
  71. print('Cleaning up %s' % filename)
  72. os.remove(filename)
  73. if __name__ == '__main__':
  74. try:
  75. main()
  76. except KeyboardInterrupt:
  77. print('Ctrl-C caught, exiting')