From c65b44327bd962fb664f2b3a095c054399cc9545 Mon Sep 17 00:00:00 2001 From: clime Date: Mar 02 2018 00:25:35 +0000 Subject: added env, added latest function call caching, finished basics of git_ functions, no "artifacts" generated when not needed, renamed distgit config section to dist-git --- diff --git a/rpkg.conf b/rpkg.conf index f656c88..c599700 100644 --- a/rpkg.conf +++ b/rpkg.conf @@ -3,7 +3,7 @@ preprocess_spec = True # auto-packing is deprecated: auto_pack = True -[distgit] +[dist-git] lookaside = https://src.fedoraproject.org/repo/pkgs/%(ns1)s/%(pkg)s/%(filename)s/%(hashtype)s/%(hash)s/%(filename)s lookaside_cgi = https://src.fedoraproject.org/repo/pkgs/upload.cgi gitbaseurl = ssh://%(user)s@pkgs.fedoraproject.org/%(module)s diff --git a/rpkglib/cli.py b/rpkglib/cli.py index 31b2c53..703c083 100644 --- a/rpkglib/cli.py +++ b/rpkglib/cli.py @@ -94,7 +94,7 @@ class rpkgClient(cliClient): """This sets up the cmd object""" # load items from the config file - items = dict(self.config.items('distgit', raw=True)) + items = dict(self.config.items('dist-git', raw=True)) # Read comma separated list of kerberos realms realms = [realm diff --git a/rpkglib/preproc.py b/rpkglib/preproc.py index 1ecb2fd..3575fe6 100644 --- a/rpkglib/preproc.py +++ b/rpkglib/preproc.py @@ -7,17 +7,33 @@ from pyparsing import nestedExpr preproc_path = os.path.join( os.path.dirname(__file__), "preproc", "preproc.sh") +STORED_ENV = "" def invoke_wrapper(outdir, log): def invoke(toks): + global STORED_ENV + subcmd = list(toks[0]) debug_log_file = tempfile.NamedTemporaryFile() info_log_file = tempfile.NamedTemporaryFile() + write_env_file = tempfile.NamedTemporaryFile() + + env_store_file = tempfile.NamedTemporaryFile(delete=False) + env_store_file.write(STORED_ENV) + env_store_file.close() - env = {'OUTDIR': outdir, 'DEBUGLOG': debug_log_file.name, 'INFOLOG': info_log_file.name} + env = { + 'OUTDIR': outdir, + 'DEBUGLOG': debug_log_file.name, + 'INFOLOG': info_log_file.name, + 'ENVSTORE': env_store_file.name, + } p = subprocess.Popen([preproc_path]+subcmd, env=env, stdout=subprocess.PIPE) (stdout, stderr) = p.communicate() + env_store_file = open(env_store_file.name, 'r') + STORED_ENV = env_store_file.read() + info_log = info_log_file.read() debug_log = debug_log_file.read() @@ -30,18 +46,26 @@ def invoke_wrapper(outdir, log): info_log_file.close() debug_log_file.close() + env_store_file.close() + os.unlink(env_store_file.name) return stdout return invoke -def preprocess(in_spec_path, out_spec_path, log): +def preprocess(in_spec_path, out_spec_path, log, dump_spec_only=False): + if dump_spec_only: + outdir = "" + else: + outdir = os.path.dirname(out_spec_path) + with open(in_spec_path, 'r') as f: in_spec_data = f.read() expr = nestedExpr('{{{', '}}}') + expr.setParseAction( - invoke_wrapper(os.path.dirname(out_spec_path), log) - ) + invoke_wrapper(outdir, log)) out_spec_data = expr.transformString(in_spec_data) + outf = open(out_spec_path, 'w') outf.write(out_spec_data) outf.close() diff --git a/rpkglib/preproc/lib.sh b/rpkglib/preproc/lib.sh index 3a97f8c..3d5a295 100644 --- a/rpkglib/preproc/lib.sh +++ b/rpkglib/preproc/lib.sh @@ -1,26 +1,60 @@ SCRIPTDIR="$( builtin cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +function cached { + if [ -n "${__cached[$1]}" ]; then + echo -n "${__cached[$1]}"; + return + fi + "$@" +} + ############## REPO FUNCTIONS ############## function git_pack { - declare name=$(git_name) version=$(git_version) "$@" + declare name=$(cached git_name) version=$(cached git_version) source_name=$(cached git_source_name) "$@" + + if [ -z "$OUTDIR" ]; then + echo "git_pack: OUTDIR is not set. No action taken." > $DEBUGLOG + echo -n "$source_name" + return + fi - dir_name=$name-$version - source_name=$(git_source_name name=$name version=$version) - $SCRIPTDIR/scripts/pack_sources.sh $dir_name $OUTDIR/$source_name > $DEBUGLOG - if [ $? -eq 0 ]; then echo "Wrote: $OUTDIR/$source_name" > $INFOLOG; fi - echo -n $source_name + $SCRIPTDIR/scripts/pack_sources.sh "$name-$version" "$OUTDIR/$source_name" > $DEBUGLOG + + if [ $? -eq 0 ]; then + echo "git_pack: Wrote: $OUTDIR/$source_name" + else + echo "git_pack: Error during source creation." + fi > $INFOLOG + + echo -n "$source_name" } function git_archive { - echo "foo" + declare name=$(cached git_name) version=$(cached git_version) source_name=$(cached git_source_name) "$@" + + if [ -z "$OUTDIR" ]; then + echo "git_archive: OUTDIR is not set. No action taken." > $DEBUGLOG + echo -n "$source_name" + return + fi + + git archive --prefix="$name-$version" -o "$OUTDIR/$source_name" HEAD: > $DEBUGLOG + + if [ $? -eq 0 ]; then + echo "git_archive: Wrote: $OUTDIR/$source_name" + else + echo "git_archive: Error during source creation." + fi > $INFOLOG + + echo -n "$source_name" } function git_name { url=$(git config --get remote.origin.url) if [ -z "$url" ]; then - echo "Start by setting origin URL." > $ERRORLOG + echo "git_name: Start by setting origin URL." > $ERRORLOG return 1 fi @@ -29,7 +63,7 @@ function git_name { } function git_version { - declare name=$(git_name) lead=0 follow= "$@" + declare name=$(cached git_name) lead=0 follow= "$@" if [ -z "$name" ]; then echo "git_version: name cannot be empty." > $ERRORLOG @@ -37,7 +71,7 @@ function git_version { fi if echo $lead.$follow | grep -q '-'; then - echo "git_version: lead and follow cannot contains dashes." > $ERRORLOG + echo "git_version: lead and follow cannot contain dashes." > $ERRORLOG return 1 fi @@ -71,19 +105,26 @@ function git_version { } function git_source_name { - declare name=$(git_name) version=$(git_version) "$@" - echo -n "$name-$version.tar.gz" + declare name=$(cached git_name) version=$(cached git_version) format=tar.gz "$@" + echo -n "$name-$version.$format" } function git_changelog { - declare name=$(git_name) since_tag= locale=POSIX "$@" + declare name=$(cached git_name) since_tag= until_tag= locale=POSIX "$@" mapfile -t tags < <(git tag --list --sort=taggerdate:unix "$name-*" --merged) changelog= + until_tag_hit= for tag in "${tags[@]}"; do + if [ -n "$until_tag" ] && [ -z "$until_tag_hit" ] && [ "$until_tag" != "$tag" ]; then + continue + fi + until_tag_hit="1" + data=$(git tag -l $tag --format='%(body)') if [ -z "$data" ]; then + echo "Skipping $tag with empty body." > $DEBUGLOG continue fi @@ -98,6 +139,11 @@ function git_changelog { echo -n "$changelog" } +function git_setup_macro { + declare name=$(cached git_name) version=$(cached git_version) "$@" + echo -n "%setup -q -n $name-$version" +} + ############## DIR FUNCTIONS ############## function git_dir_pack { diff --git a/rpkglib/preproc/preproc.sh b/rpkglib/preproc/preproc.sh index 4d12448..61aa5b3 100755 --- a/rpkglib/preproc/preproc.sh +++ b/rpkglib/preproc/preproc.sh @@ -1,11 +1,15 @@ #!/bin/bash +declare -Ax __cached +source $ENVSTORE -SCRIPTDIR="$( builtin cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - +SCRIPTDIR="$(builtin cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)" source $SCRIPTDIR/lib.sh if [ -f ./.rpkg.sh ]; then source ./.rpkg.sh fi -"$@" +__cached[$1]=$("$@") +echo -n "${__cached[$1]}" + +declare -x > $ENVSTORE diff --git a/rpkglib/preproc/scripts/pack_sources.sh b/rpkglib/preproc/scripts/pack_sources.sh index fbb44ec..217825f 100755 --- a/rpkglib/preproc/scripts/pack_sources.sh +++ b/rpkglib/preproc/scripts/pack_sources.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # creates a gzipped tarball out of the CWD content # to be used as a Source in a spec file. @@ -9,8 +9,10 @@ Usage: $0 [--include-vcs] [--include-vcs-ignores] dir_name source_name Creates a compressed tarball out of the CWD content - to be used as a Source in a spec file. Uses tar - to do the job. + to be used as a Source0 in a spec file. Uses tar + to do the job. By default, omits any VCS-specific files + and dirs as well as files mentioned in a VCS-ignore + file. Options: -h, --help Print help @@ -58,12 +60,12 @@ if [ -z "$SOURCE_NAME" ] || [ -z "$DIR_NAME" ]; then exit -1 fi -if [ -f $SOURCE_NAME ]; then +if [ -f "$SOURCE_NAME" ]; then echo "Source file already exists." exit 0 fi ORIG_DIR_NAME=`basename $(pwd)` -cd .. +builtin cd .. tar caf $SOURCE_NAME $EXCLUDE_VCS $EXCLUDE_VCS_IGNORES --transform "s/^$ORIG_DIR_NAME/$DIR_NAME/" $ORIG_DIR_NAME diff --git a/tests/test_cli.py b/tests/test_cli.py index 7eb0703..e8a5615 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -25,7 +25,7 @@ RPKG_CONFIG = """ preprocess_spec = True auto_pack = True -[distgit] +[dist-git] lookaside = http://localhost/repo/pkgs/%(ns1)s/%(pkg)s/%(filename)s/%(hashtype)s/%(hash)s/%(filename)s lookaside_cgi = https://localhost/repo/pkgs/upload.cgi gitbaseurl = ssh://%(user)s@localhost/%(module)s