File: ppa.py

package info (click to toggle)
cruft-ng 0.9.77
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,836 kB
  • sloc: cpp: 1,748; sh: 816; python: 233; makefile: 97; ansic: 82; perl: 75
file content (97 lines) | stat: -rwxr-xr-x 3,160 bytes parent folder | download
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
#!/usr/bin/python3
# encoding=utf-8
#
# Copyright © 2015 Alexandre Detiste <alexandre@detiste.be>
# SPDX-License-Identifier: GPL-2.0-or-later
#
# https://launchpad.net/~alexandre-detiste/+archive/ubuntu/ppa

import os
import subprocess
import sys
import time

import distro_info

CRUFT = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
BASE = os.path.dirname(CRUFT)

info = distro_info.UbuntuDistroInfo()
stable = str(info.stable())
lts = str(info.lts())
old_lts = str(info.supported()[-3])

releases = sorted(set([old_lts, lts, stable]))
if len(sys.argv) > 1:
    release = sys.argv[1]
    assert release in releases
    releases = [release]

print('RELEASES:', releases)

subprocess.check_call(['git', 'checkout', 'debian/changelog'],
                       cwd = CRUFT)
subprocess.check_call(['git', 'checkout', 'debian/control'],
                       cwd = CRUFT)

from debian.changelog import Changelog
with open('debian/changelog', encoding='utf-8') as log:
    cl = Changelog(log, strict=False)

assert cl.distributions in ('unstable','UNRELEASED'), cl.distributions

if cl.distributions == 'unstable':
   build_type = 'Backport to PPA'
   build_number = 'release+'
else:
   build_type = 'Git snapshot'
   build_number = time.strftime('git%Y%m%d+')

with open('debian/control', 'r') as compat:
    for line in compat:
        if 'debhelper-compat' in line:
            current_debhelper =  int(line.split('(')[1].strip(' =),\n'))
            break

for release in sorted(releases):

    supported_debhelper = {
            'focal': 12,
            }.get(release, current_debhelper)
    BACKPORT = supported_debhelper < current_debhelper

    if BACKPORT:
        build_dep = 'debhelper-compat ( = %d)' %  supported_debhelper
        subprocess.check_call(['sed', '-i',
                               r's/\ *debhelper-compat.*/ ' + build_dep + ',/',
                               'debian/control'],
                              cwd = CRUFT)

    snapshot = str(cl.version).split('~')[0] + '~' + build_number + release
    subprocess.check_call(['dch', '-b',
                           '-D', release,
                           '-v', snapshot,
                           build_type],
                          cwd = CRUFT)

    subprocess.check_call(['debuild', '--no-lintian', '-S', '-i'], cwd = CRUFT)
    subprocess.check_call(['dput', 'my-ppa',
                           'cruft-ng_%s_source.changes' % snapshot],
                           cwd = BASE)

    subprocess.check_call(['git', 'checkout', 'debian/changelog'],
                          cwd = CRUFT)
    if BACKPORT:
        subprocess.check_call(['git', 'checkout', 'debian/control'],
                               cwd = CRUFT)
        subprocess.check_call(['git', 'checkout', 'debian/dh-cruft.manpages'],
                               cwd = CRUFT)

    for file in ('.tar.xz',
                 '.dsc',
                 '_source.build',
                 '_source.changes',
                 '_source.my-ppa.upload'):
        subprocess.check_call(['rm', '-v',
                               'cruft-ng_%s%s' % (snapshot, file)],
                              cwd = BASE)