|
| 1 | +import os |
| 2 | +from rdopkg import helpers |
| 3 | +import rdopkg.utils.cmd |
| 4 | +from rdopkg.utils import specfile |
| 5 | + |
| 6 | + |
| 7 | +SAMPLE_SPEC = u""" |
| 8 | +Name: {name} |
| 9 | +Epoch: 1 |
| 10 | +Version: {version} |
| 11 | +Release: {release}%{{?dist}} |
| 12 | +Summary: Amazing {name} package |
| 13 | +
|
| 14 | +Group: Development/Languages |
| 15 | +License: ASL 2.0 |
| 16 | +URL: http://pypi.python.org/pypi/%{{name}} |
| 17 | +Source0: http://pypi.python.org/lul/%{{name}}/%{{name}}-%{{version}}.tar.gz |
| 18 | +
|
| 19 | +BuildArch: noarch |
| 20 | +BuildRequires: python-setuptools |
| 21 | +BuildRequires: python2-devel |
| 22 | +
|
| 23 | +Requires: python-argparse |
| 24 | +Requires: python-iso8601 |
| 25 | +Requires: python-prettytable |
| 26 | +
|
| 27 | +%description |
| 28 | +{name} is incredibly interesting and useful to all beings in universe. |
| 29 | +
|
| 30 | +It's pretty good stuff for a testing package that doesn't even exist. |
| 31 | +
|
| 32 | +%prep |
| 33 | +%setup -q |
| 34 | +
|
| 35 | +%build |
| 36 | +%{{__python}} setup.py build |
| 37 | +
|
| 38 | +%install |
| 39 | +%{{__python}} setup.py install -O1 --skip-build --root %{{buildroot}} |
| 40 | +
|
| 41 | +%files |
| 42 | +%doc README.rst |
| 43 | +%{{_bindir}}/{name} |
| 44 | +
|
| 45 | +%changelog |
| 46 | +* Mon Apr 23 2017 Jakub Ruzicka <jruzicka@redhat.com> {version}-{release} |
| 47 | +- Update to upstream {version} |
| 48 | +- Introduce new bugs (rhbz#123456) |
| 49 | +
|
| 50 | +* Tue Mar 23 2016 Jakub Ruzicka <jruzicka@redhat.com> 1.2.2-1 |
| 51 | +- Update to upstream 1.2.2 |
| 52 | +
|
| 53 | +* Tue Jun 23 2015 Jakub Ruzicka <jruzicka@redhat.com> 1.1.1-1 |
| 54 | +- Update to upstream 1.1.1 |
| 55 | +- Lorem Ipsum |
| 56 | +- Dolor sit Amet |
| 57 | +""" # noqa |
| 58 | + |
| 59 | + |
| 60 | +# silent run() by default |
| 61 | +def run(*args, **kwargs): |
| 62 | + kwargs['log_cmd'] = False |
| 63 | + return rdopkg.utils.cmd.run(*args, **kwargs) |
| 64 | + |
| 65 | + |
| 66 | +class SilentGit(rdopkg.utils.cmd.Git): |
| 67 | + def __call__(self, *args, **kwargs): |
| 68 | + if kwargs.get('log_cmd', None) is None: |
| 69 | + kwargs['log_cmd'] = False |
| 70 | + return super(SilentGit, self).__call__(*args, **kwargs) |
| 71 | + |
| 72 | + |
| 73 | +# silent git() by default |
| 74 | +git = SilentGit() |
| 75 | + |
| 76 | + |
| 77 | +def do_patch(fn, content, msg): |
| 78 | + f = open(fn, 'a') |
| 79 | + f.write(content) |
| 80 | + f.close() |
| 81 | + git('add', fn) |
| 82 | + git('commit', '-m', msg) |
| 83 | + |
| 84 | + |
| 85 | +def add_n_patches(n, patch_name='Test Patch %d', |
| 86 | + branch='master-patches'): |
| 87 | + if branch: |
| 88 | + old_branch = rdopkg.utils.cmd.git.current_branch() |
| 89 | + git('checkout', branch) |
| 90 | + for i in range(1, n + 1): |
| 91 | + pn = patch_name % i |
| 92 | + do_patch(pn, pn + '\n', pn) |
| 93 | + if branch: |
| 94 | + git('checkout', old_branch) |
| 95 | + |
| 96 | + |
| 97 | +def create_sample_distgit(name, version='1.2.3', release='1', path=None): |
| 98 | + if not path: |
| 99 | + path = name |
| 100 | + assert not os.path.exists(path) |
| 101 | + os.makedirs(path) |
| 102 | + with helpers.cdir(path): |
| 103 | + txt = SAMPLE_SPEC.format(name=name, version=version, release=release) |
| 104 | + spec = specfile.Spec(fn='%s.spec' % name, txt=txt) |
| 105 | + spec.set_tag('Name', name) |
| 106 | + spec.save() |
| 107 | + git('init',) |
| 108 | + git('add', '.') |
| 109 | + git('commit', '-m', 'Initial import', isolated=True) |
| 110 | + return os.path.abspath(path) |
| 111 | + |
| 112 | + |
| 113 | +def create_sample_patches_branch(n): |
| 114 | + version = specfile.Spec().get_tag('Version') |
| 115 | + branch = rdopkg.utils.cmd.git.current_branch() |
| 116 | + git('tag', version, fatal=False, log_fail=False) |
| 117 | + git('branch', '%s-patches' % branch) |
| 118 | + add_n_patches(n, patch_name="Original Patch %d") |
| 119 | + |
| 120 | + |
| 121 | +def create_sample_upstream_new_version( |
| 122 | + new_version, n_patches, n_from_patches_branch): |
| 123 | + branch = rdopkg.utils.cmd.git.current_branch() |
| 124 | + old_version = specfile.Spec().get_tag('Version') |
| 125 | + git('checkout', '-b', 'upstream', old_version) |
| 126 | + add_n_patches(n_patches, |
| 127 | + patch_name='Upstream Commit %d', |
| 128 | + branch=None) |
| 129 | + for i in range(n_from_patches_branch): |
| 130 | + # emulate upstream patches that were backported |
| 131 | + git('cherry-pick', 'master-patches' + i * '~') |
| 132 | + git('tag', new_version) |
| 133 | + git('checkout', branch) |
0 commit comments