update-on-ox 1.8 KB

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