Debian Codegraph @

update-on-ox

raw
1 #!/usr/bin/env python3
2 # License: GPL v3 Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net>
3
4 import ast
5 import atexit
6 import glob
7 import os
8 import re
9 import shlex
10 import shutil
11 import subprocess
12 import sys
13 import tempfile
14
15 if False:
16 dmg = sys.argv[-1]
17 mp = tempfile.mkdtemp()
18 atexit.register(os.rmdir, mp)
19 subprocess.check_call(f'hdiutil attach {dmg} -mountpoint {mp}'.split())
20 try:
21 os.chdir(mp)
22 for app in glob.glob('*.app'):
23 d = os.path.join('/Applications', app)
24 if os.path.exists(d):
25 shutil.rmtree(d)
26 subprocess.check_call('ditto -v {} {}'.format(app, os.path.join('/Applications', app)).split())
27 finally:
28 os.chdir('/')
29 subprocess.check_call(f'hdiutil detach {mp}'.split())
30
31 # EOF_REMOTE
32
33 HOST = 'ox'
34
35 base = os.path.dirname(os.path.abspath(__file__))
36 if True:
37 with open(os.path.join(base, 'src/calibre/constants.py')) as f:
38 raw = f.read()
39 v = re.search(r'numeric_version\s*=\s*(\(.+?\))', raw).group(1)
40 v = '.'.join(map(str, ast.literal_eval(v)))
41 dmg = f'calibre-{v}.dmg'
42
43
44 def run(what):
45 ret = subprocess.run(shlex.split(what))
46 if ret.returncode != 0:
47 raise SystemExit(ret.returncode)
48
49
50 with open(__file__, 'rb') as f:
51 script = f.read().decode('utf-8')
52 script = script[:script.find('# EOF_REMOTE')].replace('if False:', 'if True:', 1)
53
54 with tempfile.NamedTemporaryFile(prefix='install-dmg-', suffix='.py') as f:
55 cmd = './setup.py osx --dont-shutdown'
56 if 'develop' in sys.argv:
57 print('Disabling code-signing and notarization')
58 cmd += ' --dont-sign --dont-notarize --dont-strip'
59 run(cmd)
60 f.write(script.encode('utf-8'))
61 f.flush()
62 run(f'scp dist/{dmg} {f.name} {HOST}:/tmp')
63 run(f'ssh {HOST} python3 /tmp/{os.path.basename(f.name)} /tmp/{dmg}')