/silverlining/mgr-scripts/prepare-temp.py

https://bitbucket.org/ianb/silverlining/ · Python · 35 lines · 30 code · 4 blank · 1 comment · 3 complexity · f26701f19557798f937a2f5242d98d50 MD5 · raw file

  1. #!/usr/bin/env python
  2. import sys
  3. sys.path.insert(0, '/usr/local/share/silverlining/lib')
  4. import os
  5. from optparse import OptionParser
  6. from silversupport import appdata
  7. from silversupport.shell import run
  8. parser = OptionParser(
  9. usage="%prog TMP_LOCATION HOSTNAME APP_NAME",
  10. description="""\
  11. Copy the application (or app instance) into the temporary location
  12. """)
  13. parser.add_option(
  14. '--instance-name',
  15. metavar='NAME',
  16. help="A specific instance name to select")
  17. def main():
  18. options, args = parser.parse_args()
  19. tmp_location = args[0]
  20. hostname = args[1]
  21. app_name = args[2]
  22. instance_name = options.instance_name
  23. if not instance_name:
  24. instance_name = appdata.instance_for_app_name(hostname, app_name)
  25. if not instance_name:
  26. print 'Error: No instance can be found under http://%s with the name %r' % (
  27. hostname, app_name)
  28. location = os.path.join('/var/www', instance_name)
  29. run(['cp', '-arl', location, tmp_location])
  30. if __name__ == '__main__':
  31. main()