update-on-ox 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 'dont_sign' not in sys.argv:
  44. cmd += ' --sign-installers'
  45. if 'notarize' in sys.argv:
  46. cmd += ' --sign-installers --notarize'
  47. if 'tests' not in sys.argv:
  48. cmd += ' --skip-tests'
  49. run(cmd)
  50. f.write(script.encode('utf-8'))
  51. f.flush()
  52. run(f'scp bypy/b/macos/dist/{dmg} {f.name} {HOST}:/tmp')
  53. run(f'ssh {HOST} python3 /tmp/{os.path.basename(f.name)} /tmp/{dmg}')