forked from hroncok/freeworld-syncer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
freeworld-syncer.py
115 lines (85 loc) · 3.69 KB
/
freeworld-syncer.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
import sys
import click
from syncer.koji import koji_builds, latest_complete_builds, compare_evr
from syncer.koji import FEDORA_KOJI, FUSION_KOJI
from syncer.git import clone_or_reset, git_merge, sources_magic, squash
FEDORA_PKGNAME = 'chromium'
SUFFIX = 'freeworld'
FUSION_PKGNAME = f'{FEDORA_PKGNAME}-{SUFFIX}'
def pkgname_freeworldname(ctx):
pkgname = ctx.obj['pkgname']
freeworldname = ctx.obj['freeworldname'] or f'{pkgname}-{SUFFIX}'
return pkgname, freeworldname
def welcome(what, pkgname, freeworldname):
line = f'{what} for '
line += click.style(pkgname, bold=True, fg='blue')
line += ' and '
line += click.style(freeworldname, bold=True, fg='magenta')
click.echo(line)
@click.group()
@click.option('-p', '--pkgname', default=FEDORA_PKGNAME, metavar='NAME',
help=f'Name of the Fedora package (default: {FEDORA_PKGNAME})')
@click.option('-f', '--freeworldname', default=None, metavar='NAME',
help=f'Name of the RPM Fusion package '
f'(default: <pkgname>-{SUFFIX})')
@click.pass_context
def fsyncer(ctx, pkgname, freeworldname):
"""Compare package across Fedora and RPM Fusion"""
ctx.obj['pkgname'] = pkgname
ctx.obj['freeworldname'] = freeworldname
@fsyncer.command()
@click.pass_context
def koji(ctx):
"""Show sync status on Koji builds"""
pkgname, freeworldname = pkgname_freeworldname(ctx)
welcome('Koji check', pkgname, freeworldname)
fedora_builds = latest_complete_builds(
koji_builds(FEDORA_KOJI, pkgname))
fusion_builds = latest_complete_builds(
koji_builds(FUSION_KOJI, freeworldname))
exitcode = 0
for dist in reversed(sorted(fedora_builds.keys())):
line = click.style(f'{dist}: ', bold=True)
fedora_build = fedora_builds[dist]
fusion_build = fusion_builds.get(dist)
if compare_evr(fedora_build, fusion_build):
fg = 'green'
else:
fg = 'red'
exitcode = 1
line += click.style(f'{fedora_build} {fusion_build}', fg=fg)
click.echo(line)
sys.exit(exitcode)
def yellow(text):
return click.echo(click.style(text, fg='yellow'))
@fsyncer.command()
@click.option('-b', '--branch', default='master', metavar='BRANCH',
help='RPMFusion git branch (default: master)')
@click.option('-m', '--merge-branch', default=None, metavar='FEDORA_BRANCH',
help='Fedora git branch/tag/commit to merge (default: same as '
'--branch)')
@click.option('-n', '--namespace', default='free',
type=click.Choice(['free', 'nonfree']),
help='RPM Fusion namespace (default: free)')
@click.option('-S', '--no-sources', is_flag=True,
help='Do not perform sources magic (useful with plain release '
'bumps')
@click.pass_context
def git(ctx, branch, merge_branch, namespace, no_sources):
"""Merge Fedora git to RPMFusion (does not push)"""
pkgname, freeworldname = pkgname_freeworldname(ctx)
merge_branch = merge_branch or branch
welcome('Git sync', pkgname, freeworldname)
yellow('\nSetting up git-scm in ./scm...')
clone_or_reset(pkgname, freeworldname, rffree=namespace == 'free')
yellow(f'Merging {merge_branch} from Fedora to RPM Fusion {branch}...')
git_merge(pkgname, freeworldname, branch, merge_branch)
if no_sources is not True:
yellow('Getting sources...')
sources_magic(pkgname, freeworldname, branch, merge_branch)
yellow('Squashing source change to merge commit...')
squash(pkgname, freeworldname)
yellow(f'\nReady in ./scm/{freeworldname}')
yellow('Inspect the commit and push manually at will')
if __name__ == '__main__':
fsyncer(obj={})