From 9a5e74df13c0e92fc1c21f029cf52859af0bc2f1 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Jun 01 2018 09:45:33 +0000 Subject: [PATCH 1/2] EL7 compatibility fixes This is fixing issues on several fronts, because on RHEL7, there: * is only python2 support, where: - io.StringIO behaves badly - is no unittests.mock - is no print(.., file=...) syntax * is old git <= v2, where - is no '-C' option - git tag --list format='%(taggerdate:format:..) doesn't work - git tag --list --sort=... doesn't work * is also pretty old GNU tar, where's no --exclude-vcs-ignores --- diff --git a/rpkg-util.spec.rpkg b/rpkg-util.spec.rpkg index 884dcf4..c25d5a5 100644 --- a/rpkg-util.spec.rpkg +++ b/rpkg-util.spec.rpkg @@ -1,3 +1,18 @@ +%if 0%{?fedora} || 0%{?rhel} > 7 +%global python python3 +%global python_pfx python3 +%global python_build %py3_build +%global python_install %py3_install +%global rpm_pyparsing python3-pyparsing +%else +%global python python2 +%global python_pfx python +%global python_build %py2_build +%global python_install %py2_install +%global rpm_pyparsing pyparsing +%endif + + # vim: syntax=spec Name: {{{ git_name }}} Version: {{{ git_version lead=2 }}} @@ -25,19 +40,19 @@ however, does not actually produce rpkg rpm whereas rpkg-util does. Summary: RPM packaging utility BuildArch: noarch -BuildRequires: python3 -BuildRequires: python3-setuptools -BuildRequires: python3-devel -BuildRequires: python3-rpkg -BuildRequires: python3-mock -BuildRequires: python3-munch -BuildRequires: python3-pytest -BuildRequires: python3-pyparsing -BuildRequires: python3-configparser +BuildRequires: %python +BuildRequires: %python-setuptools +BuildRequires: %python-devel +BuildRequires: %python-rpkg +BuildRequires: %python-mock +BuildRequires: %python_pfx-munch +BuildRequires: %python-pytest +BuildRequires: %rpm_pyparsing +BuildRequires: %python-configparser -Requires: python3-rpkg -Requires: python3-pyparsing -Requires: python3-configparser +Requires: %python-rpkg +Requires: %rpm_pyparsing +Requires: %python-configparser %description -n rpkg This is an RPM packaging utility based on python-rpkg library. @@ -48,14 +63,14 @@ it handles packed directory content as well as unpacked content. %setup -q %check -FULL=1 ./run_tests.sh +FULL=1 PYTHON=%python ./run_tests.sh %build -version=%{version} %py3_build -%{__python3} man/rpkg_man_page.py > rpkg.1 +version=%{version} %python_build +%python man/rpkg_man_page.py > rpkg.1 %install -%py3_install +%python_install install -d %{buildroot}%{_mandir}/man1 install -p -m 0644 rpkg.1 %{buildroot}%{_mandir}/man1 @@ -67,7 +82,7 @@ cp -a rpkg.bash %{buildroot}%{_datarootdir}/bash-completion/completions/ %files -n rpkg %license LICENSE -%{python3_sitelib}/* +%{expand:%%%{python}_sitelib}/* %config(noreplace) %{_sysconfdir}/rpkg.conf %{_datadir}/bash-completion/completions/rpkg.bash @@ -75,6 +90,7 @@ cp -a rpkg.bash %{buildroot}%{_datarootdir}/bash-completion/completions/ %{_bindir}/rpkg %{_mandir}/*/* + %changelog {{{ git_changelog }}} diff --git a/rpkglib/__init__.py b/rpkglib/__init__.py index df72d99..765b48f 100644 --- a/rpkglib/__init__.py +++ b/rpkglib/__init__.py @@ -7,7 +7,10 @@ import tempfile import git import glob -from urllib.parse import urlparse +try: + from urllib.parse import urlparse +except ImportError: + from urlparse import urlparse import pyrpkg from pyrpkg.utils import cached_property @@ -412,18 +415,14 @@ class Commands(pyrpkg.Commands): self.load_spec() def get_tag_message(self, new_tagname, skip_edit=False): - tag_pattern = '{}*'.format(self.module_name) - - tagnames = self.repo.git.tag( - '--list', '--sort=-taggerdate:unix', tag_pattern, - '--merged').split() - + tag_pattern = '{}.*'.format(self.module_name) last_matching_tagname = None - for tagname in tagnames: - expr = r'^{}-[^-]+-[^-]+$'.format(self.module_name) - if re.match(expr, tagname): - last_matching_tagname = tagname - break + + matching_tagnames = utils.list_tags( + self.repo.working_dir, + pattern=tag_pattern) + if matching_tagnames: + last_matching_tagname = matching_tagnames[-1] if last_matching_tagname: rev_list_expr = '{}..HEAD'.format( diff --git a/rpkglib/cli.py b/rpkglib/cli.py index c52d097..c3b84dc 100644 --- a/rpkglib/cli.py +++ b/rpkglib/cli.py @@ -204,7 +204,7 @@ class rpkgClient(cliClient): print('\n'.join(unused)) def make_source(self): - print('This function is deprecated and will be removed in a future release.', file=sys.stderr) + sys.stderr.write('This function is deprecated and will be removed in a future release.\n') self.cmd.sources() self.cmd.make_source() @@ -216,7 +216,7 @@ class rpkgClient(cliClient): except NotUnpackedException: pass else: - print('Auto-packing is deprecated and will be removed in a future release.', file=sys.stderr) + sys.stderr.write('Auto-packing is deprecated and will be removed in a future release.\n') return self.cmd.srpm(target=getattr(self.args, 'target', None), bcond_with=getattr(self.args, 'with', []), bcond_without=getattr(self.args, 'without', [])) @@ -298,7 +298,7 @@ class rpkgClient(cliClient): self.args.copr_config) def is_packed(self): - print('This function is deprecated and will be removed in a future release.', file=sys.stderr) + sys.stderr.write('This function is deprecated and will be removed in a future release.\n') self.cmd.dump_spec_only = True ts = rpm.ts() try: diff --git a/rpkglib/preproc.py b/rpkglib/preproc.py index 39d908c..9e12b52 100644 --- a/rpkglib/preproc.py +++ b/rpkglib/preproc.py @@ -1,4 +1,5 @@ import os +import sys import subprocess import tempfile import re @@ -27,11 +28,12 @@ def invoke_wrapper(cwd, input_path, outdir, version_bump, env_store_name, app_lo 'VERSION_BUMP': version_bump, 'INPUT_PATH': input_path, 'ENV_STORE': env_store_name, + 'PYTHONPATH': ':'.join(sys.path), + 'PYTHON': sys.executable, } p = subprocess.Popen(cmd, env=env, cwd=cwd, stderr=subprocess.PIPE, - stdout=subprocess.PIPE, - encoding='utf8') + stdout=subprocess.PIPE) app_log.debug('> {}'.format(token)) app_log.debug('> cwd: {}'.format(cwd)) @@ -39,7 +41,7 @@ def invoke_wrapper(cwd, input_path, outdir, version_bump, env_store_name, app_lo (stdout, stderr) = p.communicate() - for line in stderr.split('\n'): + for line in stderr.decode('utf-8').split('\n'): if not line: continue @@ -64,7 +66,7 @@ def invoke_wrapper(cwd, input_path, outdir, version_bump, env_store_name, app_lo app_log.debug('---') retval += '\n' if retval else '' - retval += stdout + retval += stdout.decode('utf-8') return retval return invoke diff --git a/rpkglib/preproc/lib.sh b/rpkglib/preproc/lib.sh index ee17a37..3020b8a 100644 --- a/rpkglib/preproc/lib.sh +++ b/rpkglib/preproc/lib.sh @@ -37,10 +37,6 @@ function name_convert { sed -e 's|/|-|g' -e 's|-$||' } -function filter_tags { - grep -E "^$1-[^-]+-[^-]+$" -} - function output { __cached["${FUNCNAME[1]}"]="$*" echo -n "${__cached[${FUNCNAME[1]}]}" @@ -140,6 +136,26 @@ function git_bumped_version { echo -n "$lead.$bumped_follow" } + +git_list_tags () +{ + __merged= + case "$1" in + --merged) + __merged=', only_merged=True' + shift + ;; + esac + + ${PYTHON-python3} -c "\ +from rpkglib.utils import list_tags +tags = list_tags(pattern='$1-[^-]+-[^-]+$'$__merged) +for tag in tags: + print(tag) +" 2>/dev/null +} + + function git_version { declare name="$(cached git_name)" lead=0 follow= "$@" @@ -157,8 +173,8 @@ function git_version { log_error "follow cannot contain dots." return 1 fi - - mapfile -t tags < <(git tag --list --sort=taggerdate:unix "$name*" --merged 2> /dev/null | filter_tags "$name") + + mapfile -t tags < <(git_list_tags --merged "$name") if [ ${#tags[@]} -gt 0 ]; then latest_tag="${tags[-1]}" @@ -270,7 +286,7 @@ function git_archive { return 2 fi - cmd_stdout="$(git -C "$path" archive --prefix="$dir_name/" -o "$OUTDIR/$source_name" HEAD)" + cmd_stdout="$(cd "$path" && git archive --prefix="$dir_name/" -o "$OUTDIR/$source_name" HEAD)" cmd_retcode=$? log_debug "$cmd_stdout" @@ -293,13 +309,7 @@ function git_setup_macro { function git_changelog { declare name="$(cached git_name)" since_tag= until_tag= header_locale=POSIX header_date_format="%a %b %d %Y" body_wrap=80 "$@" - mapfile -t tags < <(git tag --list --sort=taggerdate:unix "$name*" --merged 2> /dev/null | filter_tags "$name") - - if [ -n "$header_date_format" ]; then - header_date_format_suffix=":format:$header_date_format" - else - header_date_format_suffix= - fi + mapfile -t tags < <(git_list_tags --merged "$name") changelog= until_tag_hit= @@ -309,13 +319,20 @@ function git_changelog { fi since_tag_hit=1 - data="$(git tag -l "$tag" --format='%(body)')" + data="$(git for-each-ref "refs/tags/$tag" --format='%(body)')" if [ -z "$data" ]; then data="(none)" fi + ref=refs/tags/$tag + header_date='%(taggerdate)' + if [ -n "$header_date_format" ]; then + realdate=$(git for-each-ref "$ref" --format '%(taggerdate:iso8601)') + header_date=$(date --date "$realdate" +"$header_date_format") + fi + verrel="$(echo "$tag" | sed -E -n "s/^$name-([^-]+)(-[^-]+)$/\1\2/p")" - header="$(LC_ALL="$header_locale" git tag -l "$tag" --format="* %(taggerdate$header_date_format_suffix) %(taggername) %(taggeremail)") $verrel" + header="$(LC_ALL="$header_locale" git for-each-ref "refs/tags/$tag" --format="* $header_date %(taggername) %(taggeremail)") $verrel" formatted_data="$(echo "$data" | fold -cs --width="$body_wrap" | sed -E -e 's/(\s+)%([^%])/\1%%\2/g' -e 's/\s*$//')" if [ -n "$changelog" ]; then @@ -335,7 +352,7 @@ function git_changelog { ############## DIR FUNCTIONS ############## function git_dir_name { - git_name append="-$(git -C "$(dirname "$INPUT_PATH")" rev-parse --show-prefix | name_convert)" "$@" + git_name append="-$(cd "$(dirname "$INPUT_PATH")" && git rev-parse --show-prefix | name_convert)" "$@" } function git_dir_version { @@ -343,7 +360,7 @@ function git_dir_version { } function git_dir_vcs { - git_vcs subtree="$(git -C "$(dirname "$INPUT_PATH")" rev-parse --show-prefix)" "$@" + git_vcs subtree="$(cd "$(dirname "$INPUT_PATH")" && git rev-parse --show-prefix)" "$@" } function git_dir_pack { @@ -365,7 +382,7 @@ function git_dir_changelog { ############## CURRENT WORKING DIR FUNCTIONS ############## function git_cwd_name { - git_name append="-$(git -C "$(pwd)" rev-parse --show-prefix | name_convert)" "$@" + git_name append="-$(cd "$(pwd)" && git rev-parse --show-prefix | name_convert)" "$@" } function git_cwd_version { @@ -373,7 +390,7 @@ function git_cwd_version { } function git_cwd_vcs { - git_vcs subtree="$(git -C "$(pwd)" rev-parse --show-prefix)" "$@" + git_vcs subtree="$(cd "$(pwd)" && git rev-parse --show-prefix)" "$@" } function git_cwd_pack { diff --git a/rpkglib/preproc/scripts/pack_sources.sh b/rpkglib/preproc/scripts/pack_sources.sh index 9f2647b..177a10b 100755 --- a/rpkglib/preproc/scripts/pack_sources.sh +++ b/rpkglib/preproc/scripts/pack_sources.sh @@ -28,7 +28,11 @@ CONTENT_PATH="" DIR_NAME="" SOURCE_NAME="" EXCLUDE_VCS="--exclude-vcs" -EXCLUDE_VCS_IGNORES="--exclude-vcs-ignores" +if tar --help | grep -q -- --exclude-vcs-ignores; then + EXCLUDE_VCS_IGNORES="--exclude-vcs-ignores" +else + EXCLUDE_VCS_IGNORES="--exclude=.gitignore" ## TODO +fi while [ -n "$1" ] ; do case "$1" in diff --git a/rpkglib/utils.py b/rpkglib/utils.py index b1de42a..fedfc54 100644 --- a/rpkglib/utils.py +++ b/rpkglib/utils.py @@ -6,6 +6,7 @@ import tarfile import textwrap import subprocess import tempfile +import git from pyrpkg.errors import rpkgError @@ -57,14 +58,14 @@ def get_changelog_entry(commit_message): def run_command(cmd, shell=False, env=None, cwd=None): try: - output = subprocess.check_output(cmd, shell=shell, env=env, cwd=cwd, encoding='utf8') + output = subprocess.check_output(cmd, shell=shell, env=env, cwd=cwd) except (subprocess.CalledProcessError, OSError) as e: raise rpkgError(e) except KeyboardInterrupt: raise rpkgError('Command is terminated by user.') except Exception as e: raise rpkgError(e) - return output + return output.decode('utf-8') def edit(editor, text): @@ -77,3 +78,34 @@ def edit(editor, text): tmp_f.close() os.unlink(tmp_f.name) return result + + +def list_tags(repo=None, pattern=None, only_merged=False): + def sort_tags(tags): + return sorted(tags, key=lambda t: t.commit.committed_date) + + repo = git.Repo(repo, search_parent_directories=True) + tags = repo.tags + if pattern: + regexp = re.compile(pattern) + tags = [t for t in tags if regexp.match(t.name)] + if not tags: + return [] + + if not only_merged: + return sort_tags(tags) + + found_tags = [] + tagged_hashes = {} + for tag in tags: + sha = tag.commit.hexsha + if sha in tagged_hashes: + tagged_hashes[sha].append(tag) + else: + tagged_hashes[sha] = [tag] + + for commit in repo.iter_commits(): + if commit.hexsha in tagged_hashes: + found_tags.extend(tagged_hashes[commit.hexsha]) + + return sort_tags(found_tags) diff --git a/run_tests.sh b/run_tests.sh index df42021..1328ad2 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -2,7 +2,9 @@ path="${1:-tests}" -PYTHONPATH=.:$PYTHONPATH python3 -m pytest -s $path +export PYTHONPATH=".${PYTHONPATH+:$PYTHONPATH}" + +${PYTHON-python3} -m pytest -s $path if [ -n "$FULL" ] && [ -z "$FULL_OVERRIDE" ]; then ./tests/preproc/run.sh diff --git a/tests/preproc/lib.sh b/tests/preproc/lib.sh index 2b7ab86..0ec13c0 100644 --- a/tests/preproc/lib.sh +++ b/tests/preproc/lib.sh @@ -22,8 +22,8 @@ function wtree_sub { } function head_commit_sub { - full_hash=$(git -C "$1" rev-parse HEAD) - short_hash=$(git -C "$1" rev-parse --short HEAD) + full_hash=$(cd "$1" && git rev-parse HEAD) + short_hash=$(cd "$1" && git rev-parse --short HEAD) sed -Ei -e "s|(\.git\.[0-9]+)\.[a-zA-Z0-9]+|\1.$short_hash|" -e "s|#\w{40}:|#$full_hash:|" "$2" } @@ -36,7 +36,7 @@ function generic_test { local out="$(mktemp -d)" - run "../preproc.py --path $path --input $input --output $out/output $opts | log_filter &> $out/log" + run "${PYTHON-python3} ../preproc.py --path $path --input $input --output $out/output $opts | log_filter &> $out/log" if [ -n "$copy_only" ]; then cp "$out/log" "$out/output" . diff --git a/tests/preproc/test_bash/run.sh b/tests/preproc/test_bash/run.sh index 70eaf74..3182994 100755 --- a/tests/preproc/test_bash/run.sh +++ b/tests/preproc/test_bash/run.sh @@ -7,8 +7,11 @@ output=`mktemp` prepare_input input $repo/input git init $repo -git -C $repo config user.email "clime@redhat.com" -git -C $repo config user.name "clime" +( + cd "$repo" + git config user.email "clime@redhat.com" + git config user.name "clime" +) touch output && cp output $output wtree_sub $repo $output diff --git a/tests/preproc/test_committed/run.sh b/tests/preproc/test_committed/run.sh index 1a5c5f7..8b6a5d1 100755 --- a/tests/preproc/test_committed/run.sh +++ b/tests/preproc/test_committed/run.sh @@ -8,18 +8,20 @@ output=`mktemp` prepare_input ../input $repo/input git init $repo -git -C $repo config user.email "clime@redhat.com" -git -C $repo config user.name "clime" - -git -C $repo remote add origin https://pagure.io/clime/test.git -git -C $repo add -A -git -C $repo commit -m 'commit 1' -touch $repo/foo -git -C $repo add foo -git -C $repo commit -m 'commit 2' -touch $repo/bar -git -C $repo add bar -git -C $repo commit -m 'commit 3' +( + cd "$repo" + git config user.email "clime@redhat.com" + git config user.name "clime" + git remote add origin https://pagure.io/clime/test.git + git add -A + git commit -m 'commit 1' + touch foo + git add foo + git commit -m 'commit 2' + touch bar + git add bar + git commit -m 'commit 3' +) touch output && cp output $output wtree_sub $repo $output diff --git a/tests/preproc/test_dirty/run.sh b/tests/preproc/test_dirty/run.sh index 8ba5b76..1516b76 100755 --- a/tests/preproc/test_dirty/run.sh +++ b/tests/preproc/test_dirty/run.sh @@ -8,11 +8,14 @@ output=`mktemp` prepare_input ../input $repo/input git init $repo -git -C $repo config user.email "clime@redhat.com" -git -C $repo config user.name "clime" -git -C $repo remote add origin https://pagure.io/clime/test.git -git -C $repo add -A -git -C $repo commit -a -m 'inital_commit' +( + cd "$repo" + git config user.email "clime@redhat.com" + git config user.name "clime" + git remote add origin https://pagure.io/clime/test.git + git add -A + git commit -a -m 'inital_commit' +) touch $repo/foo diff --git a/tests/preproc/test_inited/run.sh b/tests/preproc/test_inited/run.sh index c2d3a61..2986c41 100755 --- a/tests/preproc/test_inited/run.sh +++ b/tests/preproc/test_inited/run.sh @@ -7,8 +7,11 @@ output=`mktemp` prepare_input ../input $repo/input git init $repo -git -C $repo config user.email "clime@redhat.com" -git -C $repo config user.name "clime" +( + cd "$repo" + git config user.email "clime@redhat.com" + git config user.name "clime" +) touch output && cp output $output wtree_sub $repo $output diff --git a/tests/preproc/test_inited_origin_set/run.sh b/tests/preproc/test_inited_origin_set/run.sh index 23b3f71..aebe67a 100755 --- a/tests/preproc/test_inited_origin_set/run.sh +++ b/tests/preproc/test_inited_origin_set/run.sh @@ -8,9 +8,12 @@ output=`mktemp` prepare_input ../input $repo/input git init $repo -git -C $repo config user.email "clime@redhat.com" -git -C $repo config user.name "clime" -git -C $repo remote add origin https://pagure.io/clime/test.git +( + cd "$repo" + git config user.email "clime@redhat.com" + git config user.name "clime" + git remote add origin https://pagure.io/clime/test.git +) touch output && cp output $output wtree_sub $repo $output diff --git a/tests/preproc/test_sources/run.sh b/tests/preproc/test_sources/run.sh index b06c9dd..546d631 100755 --- a/tests/preproc/test_sources/run.sh +++ b/tests/preproc/test_sources/run.sh @@ -7,8 +7,11 @@ output=`mktemp` prepare_input input $repo/input git init $repo -git -C $repo config user.email "clime@redhat.com" -git -C $repo config user.name "clime" +( + cd "$repo" + git config user.email "clime@redhat.com" + git config user.name "clime" +) touch output && cp output $output diff --git a/tests/preproc/test_sources_committed/run.sh b/tests/preproc/test_sources_committed/run.sh index 0d7758a..ad61710 100755 --- a/tests/preproc/test_sources_committed/run.sh +++ b/tests/preproc/test_sources_committed/run.sh @@ -9,10 +9,13 @@ prepare_input input $repo/input echo 1 > $repo/cookie git init $repo -git -C $repo config user.email "clime@redhat.com" -git -C $repo config user.name "clime" -git -C $repo add -A -git -C $repo commit -m 'commit 1' +( + cd "$repo" + git config user.email "clime@redhat.com" + git config user.name "clime" + git add -A + git commit -m 'commit 1' +) touch output && cp output $output diff --git a/tests/preproc/test_sources_subdir/run.sh b/tests/preproc/test_sources_subdir/run.sh index 5e964cb..a80f403 100755 --- a/tests/preproc/test_sources_subdir/run.sh +++ b/tests/preproc/test_sources_subdir/run.sh @@ -12,15 +12,18 @@ echo 2 > $repo/subdir3/cookie echo 3 > $repo/subdir2/cookie git init $repo -git -C $repo config user.email "clime@redhat.com" -git -C $repo config user.name "clime" -git -C $repo remote add origin https://pagure.io/clime/test.git -git -C $repo add -A -git -C $repo commit -m 'commit 1' -git -C $repo tag -a -m 'tag message' test-0.4-1 -git -C $repo tag -a -m 'tag message' test-subdir1-0.4-1 -git -C $repo tag -a -m 'tag message' test-subdir2-0.4-1 -git -C $repo tag -a -m 'tag message' test-subdir3-0.4-1 +( + cd "$repo" + git config user.email "clime@redhat.com" + git config user.name "clime" + git remote add origin https://pagure.io/clime/test.git + git add -A + git commit -m 'commit 1' + git tag -a -m 'tag message' test-0.4-1 + git tag -a -m 'tag message' test-subdir1-0.4-1 + git tag -a -m 'tag message' test-subdir2-0.4-1 + git tag -a -m 'tag message' test-subdir3-0.4-1 +) touch output && cp output $output diff --git a/tests/preproc/test_subdir/run.sh b/tests/preproc/test_subdir/run.sh index 179bc1e..340eb8b 100755 --- a/tests/preproc/test_subdir/run.sh +++ b/tests/preproc/test_subdir/run.sh @@ -9,9 +9,13 @@ mkdir $repo/subdir1 $repo/subdir2 prepare_input ../input $repo/subdir2/input git init $repo -git -C $repo config user.email "clime@redhat.com" -git -C $repo config user.name "clime" -git -C $repo remote add origin https://pagure.io/clime/test.git + +( + cd "$repo" + git config user.email "clime@redhat.com" + git config user.name "clime" + git remote add origin https://pagure.io/clime/test.git +) touch output && cp output $output wtree_sub $repo $output diff --git a/tests/preproc/test_tagged/run.sh b/tests/preproc/test_tagged/run.sh index b73995f..3eaf3cc 100755 --- a/tests/preproc/test_tagged/run.sh +++ b/tests/preproc/test_tagged/run.sh @@ -8,16 +8,19 @@ output=`mktemp` prepare_input ../input $repo/input git init $repo -git -C $repo config user.email "clime@redhat.com" -git -C $repo config user.name "clime" -git -C $repo remote add origin https://pagure.io/clime/test.git -git -C $repo add -A -git -C $repo commit -a -m 'inital_commit' -git -C $repo tag -a -m 'subject' -m '- message' foo-1.1-1 -git -C $repo tag -a -m 'subject' -m '- message' foo-1.2-1 -git -C $repo tag -a -m 'subject' -m '- message that should be %very long because we need to test git changelog family of macros and changelong body wrapping.' foo-1.3-1 -git -C $repo tag -a -m 'subject' -m '- message' foo-1.4-1 -git -C $repo tag -a -m 'subject' -m '- message' foo-1.5-1 +( + cd "$repo" + git config user.email "clime@redhat.com" + git config user.name "clime" + git remote add origin https://pagure.io/clime/test.git + git add -A + git commit -a -m 'inital_commit' + git tag -a -m 'subject' -m '- message' foo-1.1-1 + git tag -a -m 'subject' -m '- message' foo-1.2-1 + git tag -a -m 'subject' -m '- message that should be %very long because we need to test git changelog family of macros and changelong body wrapping.' foo-1.3-1 + git tag -a -m 'subject' -m '- message' foo-1.4-1 + git tag -a -m 'subject' -m '- message' foo-1.5-1 +) touch output && cp output $output wtree_sub $repo $output diff --git a/tests/preproc/test_tagged_committed/run.sh b/tests/preproc/test_tagged_committed/run.sh index d9b4174..79f195d 100755 --- a/tests/preproc/test_tagged_committed/run.sh +++ b/tests/preproc/test_tagged_committed/run.sh @@ -8,15 +8,18 @@ output=`mktemp` prepare_input ../input $repo/input git init $repo -git -C $repo config user.email "clime@redhat.com" -git -C $repo config user.name "clime" -git -C $repo remote add origin https://pagure.io/clime/test.git -git -C $repo add -A -git -C $repo commit -a -m 'inital_commit' -git -C $repo tag -a -m 'subject' -m '- message.' foo-0.1-1 -touch $repo/foo -git -C $repo add foo -git -C $repo commit -m 'commit after tag' +( + cd "$repo" + git config user.email "clime@redhat.com" + git config user.name "clime" + git remote add origin https://pagure.io/clime/test.git + git add -A + git commit -a -m 'inital_commit' + git tag -a -m 'subject' -m '- message.' foo-0.1-1 + touch foo + git add foo + git commit -m 'commit after tag' +) touch output && cp output $output wtree_sub $repo $output diff --git a/tests/test_cli.py b/tests/test_cli.py index e1e3d39..5def3fe 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -11,8 +11,7 @@ from rpkglib.exceptions import NotUnpackedException from .spec_templates import SPEC_TEMPLATE -from unittest import mock -from unittest.mock import MagicMock +import mock from . import base diff --git a/tests/test_cmd.py b/tests/test_cmd.py index 516e253..b6d154c 100644 --- a/tests/test_cmd.py +++ b/tests/test_cmd.py @@ -13,9 +13,12 @@ from .spec_templates import SPEC_TEMPLATE, SPEC_WITH_PATCH_TEMPLATE,\ from pyrpkg.errors import rpkgError -from unittest import mock -from unittest.mock import MagicMock -from io import StringIO +import mock +from mock import MagicMock +try: + from StringIO import StringIO +except: + from io import StringIO from . import base diff --git a/tests/test_utils.py b/tests/test_utils.py index dfb83ad..c8a00bd 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -2,8 +2,7 @@ import unittest from rpkglib import utils -from unittest import mock -from unittest.mock import MagicMock +import mock from . import base From 844c1048b187ccb79b2b9d9efb31c3fc36a20329 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Jun 01 2018 16:36:31 +0000 Subject: [PATCH 2/2] accept utf-8 lookaside files On EL7, pycurl doesn't accept unicode URL; but at the same time, unicode characters can be part of file name nowadays (theoretically), so url-encode not-only spaces in the file name. --- diff --git a/rpkglib/lookaside.py b/rpkglib/lookaside.py index cd012c0..b5ad455 100644 --- a/rpkglib/lookaside.py +++ b/rpkglib/lookaside.py @@ -3,6 +3,7 @@ import pyrpkg.lookaside import pycurl import os import sys +from six.moves.urllib.parse import quote from pyrpkg.errors import DownloadError @@ -14,7 +15,7 @@ class CGILookasideCache(pyrpkg.lookaside.CGILookasideCache): hashtype = self.hashtype self.log.info("Downloading %s", filename) - urled_file = filename.replace(' ', '%20') + urled_file = quote(filename) subs = {'module': module, 'filename': urled_file, 'hash': hash, 'hashtype': hashtype} @@ -49,7 +50,7 @@ class CGILookasideCache(pyrpkg.lookaside.CGILookasideCache): with open(outfile, 'wb') as f: c = pycurl.Curl() - c.setopt(pycurl.URL, download_url) + c.setopt(pycurl.URL, str(download_url)) c.setopt(pycurl.HTTPHEADER, ['Pragma:']) c.setopt(pycurl.NOPROGRESS, False) c.setopt(pycurl.PROGRESSFUNCTION, self.print_progress)