-
Notifications
You must be signed in to change notification settings - Fork 15
/
import-upstream
executable file
·101 lines (82 loc) · 2.83 KB
/
import-upstream
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
#!/usr/bin/env python3
from __future__ import annotations
import argparse
import os.path
import re
import subprocess
import tempfile
from typing import NamedTuple
TOOLS = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'tools')
VERSION_RE = re.compile(r'^(\d+\.\d+\.\d+)((?:a|b|rc)\d+)?$')
class Version(NamedTuple):
version: str
extra: str
@property
def pkg_name(self) -> str:
minor = '.'.join(self.version.split('.')[:2])
return f'python{minor}'
@property
def debian_version(self) -> str:
extra = f'~{self.extra}' if self.extra else ''
return f'{self.version}{extra}'
@property
def filename(self) -> str:
return f'{self.pkg_name}_{self.debian_version}.tgz'
@property
def download_url(self) -> str:
extra = self.extra or ''
return (
f'https://www.python.org/ftp/python/{self.version}/'
f'Python-{self.version}{extra}.tgz'
)
@classmethod
def parse(cls, s: str) -> Version:
match = VERSION_RE.match(s)
if not match:
raise argparse.ArgumentTypeError(
'Expected #.#.# or #.#.#(a|b|rc)#',
)
ret = Version(*match.groups())
if os.path.basename(os.getcwd()) != ret.pkg_name:
raise argparse.ArgumentTypeError(f'`cd` to {ret.pkg_name} repo')
return ret
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument('version', type=Version.parse)
parser.add_argument('--repo', default='.')
args = parser.parse_args()
os.chdir(args.repo)
tag = f'upstream/{args.version.version}'
print(f"checking for pre-existing '{tag}' tag", end='... ', flush=True)
ret = subprocess.call(
('git', 'rev-parse', '--quiet', '--verify', tag),
stdout=subprocess.DEVNULL,
)
if ret == 0:
print('found, exiting.')
return 0
else:
print('not found, continuing.')
print('ensuring branches available...')
subprocess.check_output(('git', 'checkout', '-q', 'pristine-tar'))
subprocess.check_output(('git', 'checkout', '-q', 'upstream'))
print('downloading src...')
with tempfile.TemporaryDirectory() as td:
dest = os.path.join(td, args.version.filename)
subprocess.check_call((
'wget',
'--quiet',
'--output-document', dest,
args.version.download_url,
))
subprocess.check_call((
TOOLS,
'--volume', f'{dest}:{dest}:ro',
'gbp', 'import-orig', dest, '--pristine-tar', '--no-interactive',
'--no-symlink-orig', '--no-merge',
))
print('pushing new branches...')
cmd = ('git', 'push', 'origin', 'pristine-tar', 'upstream', '--tags')
return subprocess.check_call(cmd)
if __name__ == '__main__':
raise SystemExit(main())