update-on-ox 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/env python
  2. # vim:fileencoding=utf-8
  3. # License: GPL v3 Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net>
  4. import atexit
  5. import glob
  6. import os
  7. import shlex
  8. import shutil
  9. import subprocess
  10. import sys
  11. import tempfile
  12. if False:
  13. dmg = sys.argv[-1]
  14. mp = tempfile.mkdtemp()
  15. atexit.register(os.rmdir, mp)
  16. subprocess.check_call(f'hdiutil attach {dmg} -mountpoint {mp}'.split())
  17. try:
  18. os.chdir(mp)
  19. for app in glob.glob('*.app'):
  20. d = os.path.join('/Applications', app)
  21. if os.path.exists(d):
  22. shutil.rmtree(d)
  23. subprocess.check_call(f'ditto -v {app} {d}'.split())
  24. finally:
  25. os.chdir('/')
  26. subprocess.check_call(f'hdiutil detach {mp}'.split())
  27. # EOF_REMOTE
  28. HOST = 'ox'
  29. base = os.path.dirname(os.path.abspath(__file__))
  30. if True:
  31. sys.path.insert(0, base)
  32. from kitty.constants import str_version
  33. dmg = f'kitty-{str_version}.dmg'
  34. def run(what):
  35. ret = subprocess.run(shlex.split(what))
  36. if ret.returncode != 0:
  37. raise SystemExit(ret.returncode)
  38. with open(__file__, 'rb') as f:
  39. script = f.read().decode('utf-8')
  40. script = script[:script.find('# EOF_REMOTE')].replace('if False:', 'if True:', 1)
  41. with tempfile.NamedTemporaryFile(prefix='install-dmg-', suffix='.py') as f:
  42. cmd = 'python ../bypy macos program --dont-strip'
  43. if 'sign' in sys.argv:
  44. cmd += ' --sign-installers --notarize'
  45. if 'skip_tests' in sys.argv:
  46. cmd += ' --skip-tests'
  47. run(cmd)
  48. f.write(script.encode('utf-8'))
  49. f.flush()
  50. run(f'scp bypy/b/macos/dist/{dmg} {f.name} {HOST}:/tmp')
  51. run(f'ssh {HOST} python3 /tmp/{os.path.basename(f.name)} /tmp/{dmg}')