INSTALL.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/usr/bin/env python
  2. """
  3. installation script for talos. This script:
  4. - creates a virtualenv in the current directory
  5. - sets up talos in development mode: `python setup.py develop`
  6. - downloads pageloader and packages to talos/page_load_test/pageloader.xpi
  7. """
  8. import os
  9. import subprocess
  10. import sys
  11. import urllib2
  12. try:
  13. from subprocess import check_call as call
  14. except:
  15. from subprocess import call
  16. # globals
  17. here = os.path.dirname(os.path.abspath(__file__))
  18. VIRTUALENV = 'https://raw.github.com/pypa/virtualenv/1.10/virtualenv.py'
  19. def which(binary, path=os.environ['PATH']):
  20. dirs = path.split(os.pathsep)
  21. for dir in dirs:
  22. if os.path.isfile(os.path.join(dir, path)):
  23. return os.path.join(dir, path)
  24. if os.path.isfile(os.path.join(dir, path + ".exe")):
  25. return os.path.join(dir, path + ".exe")
  26. def main(args=sys.argv[1:]):
  27. # sanity check
  28. # ensure setup.py exists
  29. setup_py = os.path.join(here, 'setup.py')
  30. assert os.path.exists(setup_py), "setup.py not found"
  31. # create a virtualenv
  32. virtualenv = which('virtualenv') or which('virtualenv.py')
  33. if virtualenv:
  34. call([virtualenv, '--system-site-packages', here])
  35. else:
  36. process = subprocess.Popen([sys.executable,
  37. '-',
  38. '--system-site-packages',
  39. here],
  40. stdin=subprocess.PIPE)
  41. stdout, stderr = process.communicate(input=urllib2.urlopen(VIRTUALENV).read())
  42. # find the virtualenv's python
  43. for i in ('bin', 'Scripts'):
  44. bindir = os.path.join(here, i)
  45. if os.path.exists(bindir):
  46. break
  47. else:
  48. raise AssertionError('virtualenv binary directory not found')
  49. for i in ('python', 'python.exe'):
  50. virtualenv_python = os.path.join(bindir, i)
  51. if os.path.exists(virtualenv_python):
  52. break
  53. else:
  54. raise AssertionError('virtualenv python not found')
  55. # install talos into the virtualenv
  56. call([os.path.abspath(virtualenv_python), 'setup.py', 'develop'], cwd=here)
  57. if __name__ == '__main__':
  58. main()