File: get-orig-source.py

package info (click to toggle)
osinfo-db 0.20210215-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 18,204 kB
  • sloc: python: 1,453; makefile: 91; sh: 62
file content (34 lines) | stat: -rwxr-xr-x 1,389 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env python3

# SPDX-FileCopyrightText: 2020 Pino Toscano <pino@debian.org>
# SPDX-License-Identifier: GPL-2.0-or-later

import os
import subprocess
import tempfile
import xml.etree.ElementTree as ET

import git

OSINFO_DB_REPO = 'https://gitlab.com/libosinfo/osinfo-db.git'

scriptdir = os.path.dirname(os.path.realpath(__file__))
uscan_args = ['uscan', '--dehs', '--skip-signature',
              '--watchfile', os.path.join(scriptdir, 'watch')]
uscan_proc = subprocess.run(uscan_args, stdout=subprocess.PIPE,
                            stderr=subprocess.DEVNULL)
uscan_xml = uscan_proc.stdout.decode('utf-8')
root = ET.fromstring(uscan_xml)
upstream_version = root.find('upstream-version').text
print('Downloading version {} ...'.format(upstream_version))

with tempfile.TemporaryDirectory() as tmpdir:
    repo = git.Repo.clone_from(OSINFO_DB_REPO, os.path.join(tmpdir, 'git'))
    tmparchive = os.path.join(tmpdir, 'archive.tar')
    with open(tmparchive, 'wb') as tmpfile:
        repo.archive(tmpfile, treeish='v{}'.format(upstream_version),
                     prefix='osinfo-db-{}/'.format(upstream_version))
    outarchive = 'osinfo-db_0.{}.orig.tar.xz'.format(upstream_version)
    with open(tmparchive, 'r') as tmpfile, open(outarchive, 'w') as outfile:
        subprocess.run(['xz', '-c'], stdin=tmpfile, stdout=outfile)
    print('Written {}'.format(outarchive))