File: build_cfitsio_patches.py

package info (click to toggle)
python-fitsio 1.1.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 884 kB
  • sloc: python: 5,350; ansic: 3,436; makefile: 8
file content (35 lines) | stat: -rw-r--r-- 1,013 bytes parent folder | download | duplicates (2)
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
import os
import sys
import subprocess

VERSION = '3.47'
SRC_URL = (
    "https://heasarc.gsfc.nasa.gov/FTP/software/"
    "fitsio/c/cfitsio-%s.tar.gz" % VERSION)
SRC_TARBALL = os.path.basename(SRC_URL)
SRC_DIR = os.path.basename(SRC_URL).replace('.tar.gz', '')

# download
os.system(
    'rm -rf %s && rm -f %s && wget %s && tar xzvf %s && ls -alh' % (
        SRC_DIR, SRC_TARBALL, SRC_URL, SRC_TARBALL))

# diff src files
# the sources are all at the top level
os.makedirs('patches', exist_ok=True)

for root, _, files in os.walk(SRC_DIR):
    print(files)
    for fname in files:
        src = os.path.join(SRC_DIR, fname)
        dst = os.path.join('cfitsio-%spatch' % VERSION, fname)
        patch = os.path.join('patches', fname + '.patch')
        os.system('diff -u %s %s > %s' % (src, dst, patch))
        with open(patch, 'rb') as fp:
            buff = fp.read()
        if len(buff) == 0:
            os.remove(patch)
    break

# clean up
os.system('rm -rf %s && rm -f %s' % (SRC_DIR, SRC_TARBALL))