From 4c63ec2e56e699f0a59f26a20c94ec709e77ce8c Mon Sep 17 00:00:00 2001 From: Sascha Peilicke Date: Wed, 19 Dec 2012 12:23:45 +0100 Subject: [PATCH] Get rid of macro %majorversion. Instead, we can directly modify the %setup line in the spec file to "%setup -q -n $PARENT_FOLDER_IN_TARBALL". --- README.rst | 13 +++---------- git_tarballs | 16 +++++++++------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/README.rst b/README.rst index 88dd3af..ead7938 100644 --- a/README.rst +++ b/README.rst @@ -6,16 +6,9 @@ This is an `Open Build Service`_ source service. Requires argparse which is part of python2.7, but available as a third-party dependency in python2.6. -Uses a ``majorversion`` macro in the spec file which contains the upstream stable version number. - -The spec files should already contain the macro and ``%setup`` should use it e.g:: - - %define majorversion 201 - ... - %setup -q -n %{component}-%{majorversion} - - -The ``git_tarballs`` service will also change the specfile's ``Source:`` to the ``filename`` argument of the service. +The ``git_tarballs`` service will also change the specfile's ``Source:`` to the +``filename`` argument of the service and the ``%setup -q`` line to match the +parent folder name in the tarball. TODO: diff --git a/git_tarballs b/git_tarballs index 7d383e8..a917609 100755 --- a/git_tarballs +++ b/git_tarballs @@ -49,10 +49,12 @@ def get_changelog_from_tarball(tar_name): return changelog -def get_version_from_tarball(tar_name): +def get_parent_dir_and_version_from_tarball(tar_name): with tarfile.open(tar_name) as tar: try: - return tar.firstmember.name.rsplit('-', 1)[1] + parent_dir = tar.firstmember.name + version = parent_dir.rsplit('-', 1)[1] + return (parent_dir, version) except IndexError: sys.exit("Could not figure out version from directory " "inside tarball: " + tar.firstmember.name) @@ -100,7 +102,7 @@ def package_version(upstream_version, upstream_commit): upstream_commit[:COMMIT_HASH_SIZE]) -def update_spec_file(package_version, upstream_version, filename): +def update_spec_file(package_version, tarball_parent_dir, filename): for specfile in glob.glob('./*.spec'): with open(specfile, 'r+') as f: contents = f.read() @@ -109,8 +111,8 @@ def update_spec_file(package_version, upstream_version, filename): contents = re.sub(r'\n((Version:\s+).*)\n', r'\n\g<2>%s\n' % package_version, contents, count=1) - contents = re.sub(r'\n((%define majorversion ).*)\n', - r'\n\g<2>%s\n' % upstream_version, + contents = re.sub(r'\n((%setup\s+).*)\n', + r'\n\g<2>-q -n %s\n' % tarball_parent_dir, contents, count=1) contents = re.sub(r'\n((Source:\s+).*)\n', r'\n\g<2>%s\n' % filename, @@ -199,11 +201,11 @@ if __name__ == '__main__': changelog = get_changelog_from_tarball(args.filename) changes_list = parse_changelog(changelog) upstream_commit = get_upstream_commit(changelog) - upstream_version = get_version_from_tarball(args.filename) + tarball_parent_dir, upstream_version = get_parent_dir_and_version_from_tarball(args.filename) package_commit = get_commit_from_spec(args.package) package_version = package_version(upstream_version, upstream_commit) changes = create_changes(changes_list, package_version, package_commit, args.email) update_changes_file(args.package, changes) - update_spec_file(package_version, upstream_version, args.filename) + update_spec_file(package_version, tarball_parent_dir, args.filename)