PageRenderTime 722ms CodeModel.GetById 703ms RepoModel.GetById 0ms app.codeStats 0ms

/silverlining/mgr-scripts/app-diff.py

https://bitbucket.org/ianb/silverlining/
Python | 56 lines | 54 code | 1 blank | 1 comment | 0 complexity | 9b3060ed7d4767af1b9554ae1a5a4001 MD5 | raw file
Possible License(s): GPL-2.0
  1. #!/usr/bin/env python
  2. import sys
  3. sys.path.insert(0, '/usr/local/share/silverlining/lib')
  4. import os
  5. import shutil
  6. from optparse import OptionParser
  7. from silversupport import appdata
  8. from silversupport.shell import run
  9. from silversupport.transfermethods import make_temp_name
  10. parser = OptionParser(
  11. usage="%prog TMP_LOCATION HOSTNAME APP_NAME",
  12. description="""\
  13. Diff between the files in TMP_LOCATION and the identified application.
  14. Will delete the files in TMP_LOCATION unless --keep-tmp is given
  15. """)
  16. parser.add_option(
  17. '--instance-name',
  18. metavar='NAME',
  19. help="A specific instance name to select")
  20. parser.add_option(
  21. '--keep-tmp',
  22. action='store_true',
  23. help="Keep the files in TMP_LOCATION instead of removing them after the diff")
  24. def main():
  25. options, args = parser.parse_args()
  26. tmp_location = args[0]
  27. hostname = args[1]
  28. app_name = args[2]
  29. instance_name = options.instance_name
  30. if not instance_name:
  31. instance_name = appdata.instance_for_app_name(hostname, app_name)
  32. if not instance_name:
  33. print 'Error: No instance can be found under http://%s with the name %r' % (
  34. hostname, app_name)
  35. location = os.path.join('/var/www', instance_name)
  36. tmp = make_temp_name('.diffing')
  37. for magic_file in ['silver-env-variables.php']:
  38. if os.path.exists(os.path.join(location, magic_file)):
  39. shutil.copy(os.path.join(location, magic_file),
  40. os.path.join(tmp_location, magic_file))
  41. os.mkdir(tmp)
  42. os.symlink(location, os.path.join(tmp, instance_name))
  43. os.symlink(tmp_location, os.path.join(tmp, 'local'))
  44. run(['diff', '-u', instance_name, 'local'],
  45. cwd=tmp)
  46. shutil.rmtree(tmp)
  47. if not options.keep_tmp:
  48. shutil.rmtree(tmp_location)
  49. if __name__ == '__main__':
  50. main()