<commit_before>#!/bin/bash
#
# jenkins-publish-rpm.sh - A script to publish rpms built by jenkins to a local rpm repo
#
# This script will perform the following tasks:
#  - Copy an rpm into a directory configured to host rpms
#  - Refresh the metadata of the yum repository into which a new rpm has been added
#  - Optionally, it will also optionally truncate the number of versions a single rpm kept in the repo

USAGE_ERROR_STR="Usage: jenkins-publish-rpm.sh REPO_DIR RPM_NAME [MAX_VERSIONS]"
RPM_REPO_DIR_ERROR_STR="Could not locate or access rpm repo directory argument"
MAX_RPM_VERSION_ERROR_STR="The max number of rpm versions to keep argument must be a positive integer"
ERROR_STR=

# A special value used for the RPM name that will allow for testing and not actually publish
TEST_RUN="THIS_IS_ONLY_A_TEST"

RPM_REPO_DIR="$1"
RPM_NAME="$2"
MAX_RPM_VERSIONS=$3
NUM_ARGUMENTS=$#

# This is the main purpose of this script
publishRpm() {

    # Copy the file to the right place
    cp -f $RPM_NAME $RPM_REPO_DIR

    # If the optional max versions argument was passed
    if ( isPositiveIntegerValue "$MAX_RPM_VERSIONS" ) ; then
        truncateNumVersions $RPM_REPO_DIR $RPM_NAME $MAX_RPM_VERSIONS
    fi

    # Update the RPM repo (use sqlite db and only update changes if possible)
    createrepo --database --update $RPM_REPO_DIR
}

# truncateNumVersions PATH, RPM_NAME, NUM_VERSIONS_TO_KEEP
#   Used to get rid of older versions of the same RPM
truncateNumVersions() {
    # Sanity check the arguments a bit
    if [ -d $1 ] && isPositiveIntegerValue $3 ; then
        # List in time sequence with newest on top, use tail to figure out how many
        # of the oldest files we want to chop from the bottom of the list and pipe
        # to the remove command
        ls -t $1/$2 | xargs -n1 basename | tail -n +$(($3+1)) | xargs rm -f
    fi
}

isPositiveIntegerValue() {
    # Is it a numeric integer
    if [[ "$1" =~ ^[0-9]+$ ]] ; then
        # Is it greater than or equal to 1<commit_msg>A second attempt at gettting just the parts of the filename I need<commit_after>#!/bin/bash
#
# jenkins-publish-rpm.sh - A script to publish rpms built by jenkins to a local rpm repo
#
# This script will perform the following tasks:
#  - Copy an rpm into a directory configured to host rpms
#  - Refresh the metadata of the yum repository into which a new rpm has been added
#  - Optionally, it will also optionally truncate the number of versions a single rpm kept in the repo

USAGE_ERROR_STR="Usage: jenkins-publish-rpm.sh REPO_DIR RPM_NAME [MAX_VERSIONS]"
RPM_REPO_DIR_ERROR_STR="Could not locate or access rpm repo directory argument"
MAX_RPM_VERSION_ERROR_STR="The max number of rpm versions to keep argument must be a positive integer"
ERROR_STR=

# A special value used for the RPM name that will allow for testing and not actually publish
TEST_RUN="THIS_IS_ONLY_A_TEST"

RPM_REPO_DIR="$1"
RPM_NAME="$2"
MAX_RPM_VERSIONS=$3
NUM_ARGUMENTS=$#

# This is the main purpose of this script
publishRpm() {

    # Copy the file to the right place
    cp -f $RPM_NAME $RPM_REPO_DIR

    # If the optional max versions argument was passed
    if ( isPositiveIntegerValue "$MAX_RPM_VERSIONS" ) ; then
        truncateNumVersions $RPM_REPO_DIR $RPM_NAME $MAX_RPM_VERSIONS
    fi

    # Update the RPM repo (use sqlite db and only update changes if possible)
    createrepo --database --update $RPM_REPO_DIR
}

# truncateNumVersions PATH, RPM_NAME, NUM_VERSIONS_TO_KEEP
#   Used to get rid of older versions of the same RPM
truncateNumVersions() {
    # Sanity check the arguments a bit
    if [ -d $1 ] && isPositiveIntegerValue $3 ; then
        # List in time sequence with newest on top, use tail to figure out how many
        # of the oldest files we want to chop from the bottom of the list and pipe
        # to the remove command
        ls -t $1/$(basename "$2") | tail -n +$(($3+1)) | xargs rm -f
    fi
}

isPositiveIntegerValue() {
    # Is it a numeric integer
    if [[ "$1" =~ ^[0-9]+$ ]] ; then
        # Is it greater than or equal to 1
{'fraction_non_alphanumeric': 0.07132280355380059, 'fraction_numerical': 0.006663376110562685, 'mean_word_length': 3.5693348365276214, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1693095', 'n_tokens_mistral': 1326, 'n_tokens_neox': 1271, 'n_words': 535}