-
Notifications
You must be signed in to change notification settings - Fork 31
/
mkubuntu.py
executable file
·653 lines (609 loc) · 21.6 KB
/
mkubuntu.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
#!/usr/bin/env python3
# vi: set sw=4 et:
"""
How to take a ChimeraX.app on Linux and turn it into a debian package
for Ubuntu
References:
https://wiki.debian.org/FilesystemHierarchyStandard
https://www.debian.org/doc/debian-policy/
https://www.freedesktop.org/wiki/Specifications/desktop-entry-spec/
#
Designed for Ubuntu, would mostly work on Debian except that ffmpeg
not available in Debian
Steps:
1. build ChimeraX without Debian supplied prerequisites
2. create Debian binary package layout
3. build Deiban package
"""
import os
import subprocess
import sys
import tempfile
import textwrap
# app_author and app_name are the same as ChimeraX_main.py
app_author = "UCSF"
app_name = "ChimeraX"
CHIMERAX_INSTALL = f"{app_name}.app"
CHIMERAX_BIN = f"{CHIMERAX_INSTALL}/bin/{app_name}"
# lintian(1) complains about files /opt
# INST_DIR = "opt"
INST_DIR = "usr/lib"
UBUNTU_DEPENDENCIES = {
"16.04": {
"libasound2": "1.1.0",
"libatk1.0-0": "2.18.0",
"libbz2-1.0": "1.0.6",
"libc6": "2.23",
"libcairo-gobject2": "1.14.6",
"libcairo2": "1.14.6",
"libcups2": "2.1.3",
"libdbus-1-3": "1.10.6",
"libdrm2": "2.4.83",
"libegl1-mesa": "17.2.8",
"libexpat1": "2.1.0",
"libfftw3-single3": "3.3.4",
"libfontconfig1": "2.11.94",
"libfreetype6": "2.6.1",
"libgcc1": "6.0.1",
"libgdk-pixbuf2.0-0": "2.32.2",
"libgfortran3": "5.4.0",
"libgl1-mesa-glx": "17.2.8",
"libglib2.0-0": "2.48.2",
"libglu1-mesa": "9.0.0",
"libgstreamer-plugins-base1.0-0": "1.8.3",
"libgstreamer1.0-0": "1.8.3",
"libgtk-3-0": "3.18.9",
"libllvm3.8": "3.8",
"liblzma5": "5.1.1alpha+20120614",
"libnspr4": "4.13.1",
"libnss3": "3.28.4",
"libpango-1.0-0": "1.38.1",
"libpangocairo-1.0-0": "1.38.1",
"libpulse-mainloop-glib0": "8.0",
"libpulse0": "8.0",
"libsqlite3-0": "3.11.0",
"libssl1.0.0": "1.0.2g",
"libstdc++6": "5.4.0",
"libx11-6": "1.6.3",
"libx11-xcb1": "1.6.3",
"libxcb-glx0": "1.11.1",
"libxcb-util1": "0.4.0",
"libxcb-xfixes0": "1.11.1",
"libxcb-xinerama0": "1.11.1",
"libxcb1": "1.11.1",
"libxcomposite1": "0.4.4",
"libxcursor1": "1.1.14",
"libxdamage1": "1.1.4",
"libxext6": "1.3.3",
"libxfixes3": "5.0.1",
"libxi6": "1.7.6",
"libxrandr2": "1.5.0",
"libxrender1": "0.9.9",
"libxtst6": "1.2.2",
"zlib1g": "1.2.8.dfsg",
"xdg-utils": "1.0", # TODO: get right version
},
"18.04": {
"libasound2": "1.1.3",
"libatk1.0-0": "2.28.1",
"libbz2-1.0": "1.0.6",
"libc6": "2.27",
"libcairo-gobject2": "1.15.10",
"libcairo2": "1.15.10",
"libcups2": "2.2.7",
"libdbus-1-3": "1.12.2",
"libdrm2": "2.4.91",
"libegl1": "1.0.0",
"libexpat1": "2.2.5",
"libffi6": "3.2.1",
"libfftw3-single3": "3.3.7",
"libfontconfig1": "2.12.6",
"libfreetype6": "2.8.1",
"libgcc1": "8-20180414",
"libgdk-pixbuf2.0-0": "2.36.11",
"libgfortran4": "7.5.0",
"libgl1": "1.0.0",
"libglib2.0-0": "2.56.1",
"libglu1-mesa": "9.0.0",
"libgstreamer-plugins-base1.0-0": "1.14.1",
"libgstreamer1.0-0": "1.14.1",
"libgtk-3-0": "3.22.30",
"liblzma5": "5.2.2",
"libnspr4": "4.18",
"libnss3": "3.35",
"libosmesa6": "18.0.0",
"libpango-1.0-0": "1.40.14",
"libpangocairo-1.0-0": "1.40.14",
"libpulse-mainloop-glib0": "11.1",
"libpulse0": "11.1",
"libsqlite3-0": "3.22.0",
"libssl1.1": "1.1.0g",
"libstdc++6": "8-20180414",
"libx11-6": "1.6.4",
"libx11-xcb1": "1.6.4",
"libxcb-glx0": "1.13",
"libxcb-util1": "0.4.0",
"libxcb-xfixes0": "1.13",
"libxcb-xinerama0": "1.13",
"libxcb1": "1.13",
"libxcomposite1": "0.4.4",
"libxcursor1": "1.1.15",
"libxdamage1": "1.1.4",
"libxext6": "1.3.3",
"libxfixes3": "5.0.3",
"libxi6": "1.7.9",
"libxrandr2": "1.5.1",
"libxrender1": "0.9.10",
"libxtst6": "1.2.3",
"xdg-utils": "1.1.2",
"zlib1g": "1.2.11.dfsg",
},
"20.04": {
"libasound2": "1.2.2",
"libatk1.0-0": "2.35.1",
"libbz2-1.0": "1.0.8",
"libc6": "2.31",
"libcairo-gobject2": "1.16.0",
"libcairo2": "1.16.0",
"libcrypt1": "4.4.10",
"libcups2": "2.3.1",
"libdbus-1-3": "1.12.16",
"libdrm2": "2.4.101",
"libegl1": "1.3.1",
"libexpat1": "2.2.9",
"libffi7": "3.3",
"libfftw3-single3": "3.3.8",
"libfontconfig1": "2.13.1",
"libfreetype6": "2.10.1",
"libgcc-s1": "10-20200411",
"libgdk-pixbuf2.0-0": "2.40.0+dfsg",
"libgfortran5": "10-20200411",
"libgl1": "1.3.1",
"libglib2.0-0": "2.64.2",
"libglu1-mesa": "9.0.1",
"libgstreamer-plugins-base1.0-0": "1.16.2",
"libgstreamer1.0-0": "1.16.2",
"libgtk-3-0": "3.24.18",
"liblzma5": "5.2.4",
"libncursesw6": "6.2",
"libnspr4": "4.25",
"libnss3": "3.49.1",
"libopenjp2-7": "2.3.1",
"libosmesa6": "20.0.4",
"libpango-1.0-0": "1.44.7",
"libpangocairo-1.0-0": "1.44.7",
"libpulse-mainloop-glib0": "13.99.1",
"libpulse0": "13.99.1",
"libsqlite3-0": "3.31.1",
"libssl1.1": "1.1.1f",
"libstdc++6": "10-20200411",
"libtinfo6": "6.2",
"libuuid1": "2.34",
"libwayland-client0": "1.18.0",
"libwayland-cursor0": "1.18.0",
"libwayland-egl1": "1.18.0",
"libwayland-server0": "1.18.0",
"libx11-6": "1.6.9",
"libx11-xcb1": "1.6.9",
"libxcb-cursor0": "0.1.1",
"libxcb-glx0": "1.14",
"libxcb-icccm4": None,
"libxcb-image0": None,
"libxcb-keysyms1": None,
"libxcb-render-util0": None,
"libxcb-util1": "0.4.0",
"libxcb-xinerama0": "1.14",
"libxcb1": "1.14",
"libxcomposite1": "0.4.5",
"libxcursor1": "1.2.0",
"libxdamage1": "1.1.5",
"libxext6": "1.3.4",
"libxfixes3": "5.0.3",
"libxi6": "1.7.10",
"libxkbcommon0": "0.10.0",
"libxkbcommon-x11-0": None,
"libxrender1": "0.9.10",
"libxtst6": "1.2.3",
"xdg-utils": "1.1.3",
"zlib1g": "1.2.11.dfsg",
},
"22.04": {
# TODO: update versions
"libasound2": "1.2.6.1",
"libatk1.0-0": "2.36.0",
"libbz2-1.0": "1.0.8",
"libc6": "2.35",
"libcairo-gobject2": "1.16.0",
"libcairo2": "1.16.0",
"libcrypt1": "1:4.4.17",
"libcups2": "2.3.1",
"libdbus-1-3": "1.12.16",
"libdrm2": "2.4.101",
"libegl1": "1.3.1",
"libexpat1": "2.2.9",
"libffi7": "3.3",
"libfftw3-single3": "3.3.8",
"libfontconfig1": "2.13.1",
"libfreetype6": "2.10.1",
"libgcc-s1": "10-20200411",
"libgdk-pixbuf2.0-0": "2.40.0+dfsg",
"libgfortran5": "10-20200411",
"libgl1": "1.3.1",
"libglib2.0-0": "2.64.2",
"libglu1-mesa": "9.0.1",
"libgstreamer-plugins-base1.0-0": "1.16.2",
"libgstreamer1.0-0": "1.16.2",
"libgtk-3-0": "3.24.18",
"liblzma5": "5.2.4",
"libncursesw6": "6.2",
"libnspr4": "4.25",
"libnss3": "3.49.1",
"libopenjp2-7": "2.3.1",
"libosmesa6": "20.0.4",
"libpango-1.0-0": "1.44.7",
"libpangocairo-1.0-0": "1.44.7",
"libpulse-mainloop-glib0": "13.99.1",
"libpulse0": "13.99.1",
"libsqlite3-0": "3.31.1",
"libssl3": "3.0.2",
"libstdc++6": "10-20200411",
"libtinfo6": "6.2",
"libuuid1": "2.34",
"libwayland-client0": "1.18.0",
"libwayland-cursor0": "1.18.0",
"libwayland-egl1": "1.18.0",
"libwayland-server0": "1.18.0",
"libx11-6": "1.6.9",
"libx11-xcb1": "1.6.9",
"libxcb-cursor0": "0.1.1",
"libxcb-glx0": "1.14",
"libxcb-icccm4": None,
"libxcb-image0": None,
"libxcb-keysyms1": None,
"libxcb-render-util0": None,
"libxcb-util1": "0.4.0",
"libxcb-xinerama0": "1.14",
"libxcb1": "1.14",
"libxcomposite1": "0.4.5",
"libxcursor1": "1.2.0",
"libxdamage1": "1.1.5",
"libxext6": "1.3.4",
"libxfixes3": "5.0.3",
"libxi6": "1.7.10",
"libxkbcommon0": "0.10.0",
"libxkbcommon-x11-0": None,
"libxrender1": "0.9.10",
"libxtst6": "1.2.3",
"xdg-utils": "1.1.3",
"zlib1g": "1.2.11.dfsg",
},
"24.04": {
# TODO: update versions
"libasound2": "1.2.6.1",
"libatk1.0-0": "2.36.0",
"libbz2-1.0": "1.0.8",
"libc6": "2.35",
"libcairo-gobject2": "1.16.0",
"libcairo2": "1.16.0",
"libcrypt1": "1:4.4.17",
"libcups2": "2.3.1",
"libdbus-1-3": "1.12.16",
"libdrm2": "2.4.101",
"libegl1": "1.3.1",
"libexpat1": "2.2.9",
"libffi8": "3.3",
"libfftw3-single3": "3.3.8",
"libfontconfig1": "2.13.1",
"libfreetype6": "2.10.1",
"libgcc-s1": "10-20200411",
"libgdk-pixbuf2.0-0": "2.40.0+dfsg",
"libgfortran5": "10-20200411",
"libgl1": "1.3.1",
"libglib2.0-0": "2.64.2",
"libglu1-mesa": "9.0.1",
"libgstreamer-plugins-base1.0-0": "1.16.2",
"libgstreamer1.0-0": "1.16.2",
"libgtk-3-0": "3.24.18",
"liblzma5": "5.2.4",
"libncursesw6": "6.2",
"libnspr4": "4.25",
"libnss3": "3.49.1",
"libopenjp2-7": "2.3.1",
"libosmesa6": "20.0.4",
"libpango-1.0-0": "1.44.7",
"libpangocairo-1.0-0": "1.44.7",
"libpulse-mainloop-glib0": "13.99.1",
"libpulse0": "13.99.1",
"libsqlite3-0": "3.31.1",
"libssl3": "3.0.2",
"libstdc++6": "10-20200411",
"libtinfo6": "6.2",
"libuuid1": "2.34",
"libwayland-client0": "1.18.0",
"libwayland-cursor0": "1.18.0",
"libwayland-egl1": "1.18.0",
"libwayland-server0": "1.18.0",
"libx11-6": "1.6.9",
"libx11-xcb1": "1.6.9",
"libxcb-cursor0": "0.1.1",
"libxcb-glx0": "1.14",
"libxcb-icccm4": None,
"libxcb-image0": None,
"libxcb-keysyms1": None,
"libxcb-render-util0": None,
"libxcb-util1": "0.4.0",
"libxcb-xinerama0": "1.14",
"libxcb1": "1.14",
"libxcomposite1": "0.4.5",
"libxcursor1": "1.2.0",
"libxdamage1": "1.1.5",
"libxext6": "1.3.4",
"libxfixes3": "5.0.3",
"libxi6": "1.7.10",
"libxkbcommon0": "0.10.0",
"libxkbcommon-x11-0": None,
"libxrender1": "0.9.10",
"libxtst6": "1.2.3",
"xdg-utils": "1.1.3",
"zlib1g": "1.2.11.dfsg",
},
}
def main():
"""main program"""
# assume ChimeraX.app already has appropriate binaries
error = False
os_version = None
build = 'release'
if len(sys.argv) >= 2:
os_version = sys.argv[1]
else:
error = True
if len(sys.argv) >= 3:
build = sys.argv[2]
if build not in ['release', 'candidate', 'daily', 'github-techpreview', 'techpreview', 'canary']:
error = True
if error or len(sys.argv) > 3 or os_version not in UBUNTU_DEPENDENCIES:
print(f'Usage: {sys.argv[0]} ubuntu-version [build-type]', file=sys.stderr)
print(' Supported Ubuntu versions are:', ', '.join(UBUNTU_DEPENDENCIES.keys()),
file=sys.stderr)
print(' Build-type is one of "release", "candidate", or "daily"', file=sys.stderr)
raise SystemExit(2)
dependencies = UBUNTU_DEPENDENCIES[os_version]
output = subprocess.check_output([
CHIMERAX_BIN, "--nocolor", "--version"], stderr=subprocess.DEVNULL).decode()
full_version = [line for line in output.split('\n') if 'version:' in line]
if not full_version:
print("Not able to determine version number")
raise SystemExit(1)
full_version = full_version[0].split(':', maxsplit=1)[1].strip()
version_number, version_date = full_version.split(maxsplit=1)
from packaging.version import Version
version = Version(version_number)
version_date = version_date[1:-1].replace('-', '.')
pkg_name = f"{app_author.lower()}-{app_name.lower()}"
bin_name = app_name.lower() # name of command in /usr/bin
if build == 'daily':
# daily build, version is date
version = version_date
pkg_name += "-daily"
bin_name += "-daily"
elif build == 'techpreview':
# like daily build, version is date
version = version_date
pkg_name += "-techpreview"
bin_name += "-techpreview"
elif build == 'github-techpreview':
# like daily build, version is date
version = version_date
pkg_name += "-github-techpreview"
bin_name += "-github-techpreview"
elif build == 'canary':
# like daily build, version is date
version = version_date
pkg_name += "-canary"
bin_name += "-canary"
elif build == 'release':
# release build
version = version.base_version
else:
# candidate build
version = f"{version.base_version}+rc{version_date}"
version = f"{version}ubuntu{os_version}"
deb_name = f"{pkg_name}-{version}" # name of .deb file
# print('full_version:', repr(full_version))
# print('version_number:', version_number)
# print('version_date:', version_date)
# print('deb_name:', deb_name)
# print('pkg_name:', pkg_name)
# print('bin_name:', bin_name)
os.umask(0o22) # turn off group and other writability
pkg_root = f"{deb_name}"
os.mkdir(pkg_root)
debian_dir = f"{pkg_root}/DEBIAN"
os.mkdir(debian_dir)
make_control_file(debian_dir, pkg_name, version, dependencies)
make_postinst(debian_dir, pkg_name, bin_name)
make_prerm(debian_dir, pkg_name, bin_name)
doc_dir = f"{pkg_root}/usr/share/doc/{pkg_name}"
os.makedirs(doc_dir)
make_copyright_file(doc_dir)
make_changelog_file(doc_dir)
# add_readme(doc_dir)
copy_app(pkg_root, pkg_name)
make_bin(pkg_root, pkg_name, bin_name)
src = f'{app_name}.app/share/man/man1/{app_name}.1'
make_man_file(src, pkg_root, bin_name)
subprocess.check_call(['/bin/chmod', '-R', 'a+rX,go-w', pkg_root])
dst_dir = f'./ubuntu-{os_version}'
os.makedirs(dst_dir, exist_ok=True)
# fakeroot environment file
frenv = tempfile.NamedTemporaryFile(prefix='frenv-', suffix='.db')
subprocess.check_call([
'/usr/bin/fakeroot',
'-s', frenv.name,
'--',
'/bin/chown',
'-hRP',
'0:0',
pkg_root
], env={'FAKEROOTDONTTRYCHOWN':'1'})
subprocess.check_call([
'/usr/bin/fakeroot',
'-i', frenv.name,
'--',
'/usr/bin/dpkg-deb',
'--build',
pkg_root,
dst_dir
])
def copy_app(pkg_root, pkg_name):
"""Copy application to correct place in package hierarchy"""
import shutil
src = f'{app_name}.app'
dst_dir = f'{pkg_root}/{INST_DIR}'
dst = f'{pkg_root}/{INST_DIR}/{pkg_name}'
os.makedirs(dst_dir)
shutil.copytree(src, dst, symlinks=True)
# cleanup -- remove __pycache__ directories
cache_dirs = subprocess.check_output([
'/usr/bin/find',
dst,
'-name', '__pycache__'
]).strip().decode().split('\n')
for d in cache_dirs:
shutil.rmtree(d)
# cleanup -- remove python shell scripts
for fn in os.listdir(f'{dst}/bin'):
filename = f'{dst}/bin/{fn}'
if not os.path.isfile(filename):
continue
with open(filename, 'rb') as f:
header = f.read(64)
if header[0:2] != b'#!':
continue
program = header[2:].lstrip()
if program.startswith(b'/bin/') or \
program.startswith(b'/usr/bin/'):
continue
os.remove(filename)
def make_bin(pkg_root, pkg_name, bin_name):
"""Make symbolic link to executable"""
bin_dir = f'{pkg_root}/usr/bin'
os.makedirs(bin_dir, exist_ok=True)
os.symlink(f'../../{INST_DIR}/{pkg_name}/bin/{app_name}', f'{bin_dir}/{bin_name}')
def make_control_file(debian_dir, pkg_name, version, dependencies):
"""Make control file"""
# see "man 1 deb-control"
if dependencies is not None:
deps = list(dependencies)
else:
deps = []
deps.insert(0, 'ffmpeg')
depends = ', '.join(deps)
with open(f"{debian_dir}/control", 'w') as f:
print(textwrap.dedent(f"""\
Package: {pkg_name}
Version: {version}
Architecture: amd64
Depends: {depends}
Maintainer: Chimera Staff <[email protected]>
Description: molecular visualization
UCSF ChimeraX (or simply ChimeraX) is the next-generation
molecular visualization program from the Resource for Biocomputing
Visualization, and Informatics (RBVI), following UCSF Chimera.
ChimeraX can be downloaded free of charge for academic, government
nonprofit, and personal use. Commercial users, please see licensing.
Homepage: https://www.rbvi.ucsf.edu/chimerax/
Bugs: mailto:[email protected]
Section: contrib/science
Priority: optional
Suggests: opencl-icd
Tag: science::visualisation, science::modelling, field::biology, field::chemistry,
field::biology:structural, field::biology:bioinformatics,
biology::nucleic-acids, biology::peptidic,
use::viewing, use::analysing,
scope::application, x11::application, role::program,
interface::3d, interface::graphical, interface::commandline,
implemented-in::c++, implemented-in::python, uitoolkit::qt,
network::client
"""), file=f)
def make_postinst(debian_dir, pkg_name, bin_name):
# see "man 1 deb-postinst"
with open(f"{debian_dir}/postinst", 'w') as f:
print(textwrap.dedent(f"""\
#!/bin/sh
set -e
case "$1" in
configure)
echo "Install desktop menu and associated mime types"
{bin_name} --exit --nogui --silent --cmd 'linux xdg-install system true'
echo "Precompiling Python packages"
({bin_name} -m compileall /{INST_DIR}/{pkg_name} || exit 0)
;;
esac
"""), file=f)
os.fchmod(f.fileno(), 0o755)
def make_prerm(debian_dir, pkg_name, bin_name):
# see "man 1 deb-prerm"
with open(f"{debian_dir}/prerm", 'w') as f:
print(textwrap.dedent(f"""\
#!/bin/sh
set -e
echo "Deregister desktop menu and associated mime types"
{bin_name} --exit --nogui --silent --cmd 'linux xdg-uninstall system true'
echo "Remove Python cache files"
find /{INST_DIR}/{pkg_name} -name __pycache__ -print0 | xargs -0 /bin/rm -rf
"""), file=f)
os.fchmod(f.fileno(), 0o755)
def make_copyright_file(doc_dir):
"""Copy the copyright file"""
# copyright file
with open("copyright.txt") as f:
our_copyright = f.read()
with open(f"{doc_dir}/copyright", 'w') as f:
print(textwrap.dedent("""\
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: ChimeraX
Upstream-Contact: [email protected]
Source: https://www.rbvi.ucsf.edu/chimerax/
Disclaimer: Package is maintained by the ChimeraX team
Copyrights for embedded code are given in the documentation
in INSTALLDIR/share/docs/embeded.html
Comment:
The computer code and documentation that comprises UCSF ChimeraX is protected
by copyrights held by The Regents of the University of California ("The Regents")
and is licensed for non-commercial use at no cost by The Regents.
COMMERCIAL USE OF UCSF CHIMERAX IS COVERED BY A SEPARATE WRITTEN LICENSE AGREEMENT.
Commercial licensing costs are tier-based, depending on the number of users.
Please email [email protected]
if you are interested in using ChimeraX for commercial purposes.
License: free for non-commercial use
"""), file=f)
for line in our_copyright.split('\n'):
if line.startswith("=== UCSF ChimeraX"):
continue
print(' ', line, file=f)
def gzip(filename):
"""Gzip without saving timestamp (nor name) so it is reproducible"""
subprocess.check_call(['gzip', '-n9', filename])
def make_changelog_file(doc_dir):
"""Copy the change log file"""
filename = f"{doc_dir}/changelog"
with open(filename, 'wt') as f:
print("See https://www.rbvi.ucsf.edu/trac/ChimeraX/wiki/ChangeLog", file=f)
gzip(filename)
def make_man_file(src_file, pkg_root, bin_name):
base, ext = os.path.splitext(src_file)
if not ext or not os.path.exists(src_file):
return
section = ext[1:]
man_dir = f'{pkg_root}/usr/share/man/man{section}'
man_file = f'{man_dir}/{bin_name}.{section}'
os.makedirs(man_dir, exist_ok=True)
with open(src_file, 'rb') as f:
src = f.read()
with open(man_file, 'wb') as f:
f.write(src)
gzip(man_file)
if __name__ == '__main__':
main()