Skip to content

Commit

Permalink
Merge pull request #97 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 2.11.0
  • Loading branch information
andyone authored Sep 22, 2021
2 parents 9bd1105 + 0428c5a commit b7d5bdc
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 44 deletions.
10 changes: 4 additions & 6 deletions SOURCES/libexec/build-local.shx
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,9 @@ localBuildProcess() {

show ""

local bld_time grc_time package packages package_name package_file
local grc_time package packages package_name package_file

build_end=$(now)
bld_time=$(( build_end - build_start ))
grc_time=$(getGraceDuration "$bld_time")
grc_time=$(getGraceDuration "$build_start")

show "Build complete! The build took $grc_time." $GREEN

Expand Down Expand Up @@ -350,13 +348,13 @@ checkLocalBuildAvailability() {
show ""
fi

showt "\r${CL_GREEN}Executing:${CL_NORM} ${CL_YELLOW}waiting in queue${CL_NORM}"
showt "${CL_GREEN}Executing:${CL_NORM} ${CL_YELLOW}waiting in queue${CL_NORM}"

while : ; do
sleep $CHECK_LOCAL_QUEUE_DELAY

if ! hasLocalLock ; then
showt "\r${CL_GREEN}Executing:${CL_NORM} ${CL_YELLOW}~${CL_NORM}"
showt "${CL_GREEN}Executing:${CL_NORM} ${CL_YELLOW}~${CL_NORM}"
break
fi
done
Expand Down
45 changes: 30 additions & 15 deletions SOURCES/libexec/build-remote.shx
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,12 @@ remoteBuildProcess() {

show ""

local has_errors bld_time grc_time packages package_name package_file
local has_errors dl_start grc_time packages package_name package_file

has_errors=$(tail -1 "$tmp_output" | grep -v "exit 0")

if [[ -z "$has_errors" ]] ; then
build_end=$(now)
bld_time=$(( build_end - build_start ))
grc_time=$(getGraceDuration "$bld_time")
grc_time=$(getGraceDuration "$build_start")

show "Build complete! The build took $grc_time." $GREEN

Expand All @@ -347,17 +345,25 @@ remoteBuildProcess() {
remoteSign "$package"
fi

dl_start=$(now)

showt "${CL_BLNK_YELLOW}${CL_NORM} ${package_name}"

if [[ -n "$dest_dir" ]] ; then
downloadFromRemoteHost "$package" "$dest_dir"
else
downloadFromRemoteHost "$package"
fi

grc_time=$(getGraceDurationShort "$dl_start")

if [[ $? -eq 0 ]] ; then
show "${CL_GREY}+${CL_NORM} ${CL_CYAN}$package_name${CL_NORM}"
showt "${CL_GREEN}${CL_NORM} ${package_name} ${CL_DARK}${grc_time}${CL_NORM}"
else
show "${CL_GREY}+${CL_NORM} ${CL_CYAN}$package_name${CL_NORM} ${CL_DARK}(ALREADY EXIST)${CL_NORM}"
showt "${CL_GREEN}${CL_NORM} ${package_name} ${CL_DARK}${grc_time} (ALREADY EXIST)${CL_NORM}"
fi

show ""
done

showSeparator "PACKAGE VALIDATION"
Expand Down Expand Up @@ -438,22 +444,29 @@ remoteBuildProcess() {
uploadSourcesToRemoteHost() {
local spec="$1"

local source_file source_files rmpbuild_dir
local source_file source_file_name source_files rmpbuild_dir
local copy_start grc_time

rmpbuild_dir=$(getRPMBuildDir)
source_files=$(find "$tmp_dir" -maxdepth 1 -type f)

for source_file in $source_files ; do
source_file_name=$(basename "$source_file")
copy_start=$(now)

showt "${CL_CYAN}${source_file_name}${CL_NORM}" 4
showt "${CL_BLNK_YELLOW}${CL_NORM} ${source_file_name}"

scpCommand "$source_file" "$user@$host:$rmpbuild_dir/SOURCES/" &> $verb_output

show "DONE" $GREEN
grc_time=$(getGraceDurationShort "$copy_start")

showt "${CL_GREEN}${CL_NORM} ${source_file_name} ${CL_DARK}${grc_time}${CL_NORM}"
show ""
done

showt "${CL_CYAN}${spec}${CL_NORM}" 4
copy_start=$(now)

showt "${CL_BLNK_YELLOW}${CL_NORM} ${spec}"

if [[ -n "$bump" ]] ; then
cp "$spec" "$tmp"
Expand All @@ -466,7 +479,9 @@ uploadSourcesToRemoteHost() {
scpCommand "$spec" "$user@$host:$rmpbuild_dir/SPECS/" &> $verb_output
fi

show "DONE" $GREEN
grc_time=$(getGraceDurationShort "$copy_start")
showt "${CL_GREEN}${CL_NORM} ${spec} ${CL_DARK}${grc_time}${CL_NORM}"
show ""
}

# Download packages from remote build host
Expand Down Expand Up @@ -509,20 +524,20 @@ checkRemoteAvailability() {
remote_available=$(sshCommand "$user@$host" "stat $BUILD_LOCK &> /dev/null || echo 1")

if [[ -z "$remote_available" ]] ; then
showt "\r${CL_GREEN}Executing:${CL_NORM} ${CL_YELLOW}waiting in queue${CL_NORM}"
showt "${CL_GREEN}Executing:${CL_NORM} ${CL_YELLOW}waiting in queue${CL_NORM}"

while : ; do
sleep $CHECK_REMOTE_QUEUE_DELAY

showt "\r${CL_GREEN}Executing:${CL_NORM} ${CL_CYAN}checking queue${CL_NORM}"
showt "${CL_GREEN}Executing:${CL_NORM} ${CL_CYAN}checking queue${CL_NORM}"

remote_available=$(sshCommand "$user@$host" "stat $BUILD_LOCK &> /dev/null || echo 1")

if [[ -n "$remote_available" ]] ; then
showt "\r${CL_GREEN}Executing:${CL_NORM} ${CL_YELLOW}~${CL_NORM}"
showt "${CL_GREEN}Executing:${CL_NORM} ${CL_YELLOW}~${CL_NORM}"
break
else
showt "\r${CL_GREEN}Executing:${CL_NORM} ${CL_YELLOW}waiting in queue${CL_NORM}"
showt "${CL_GREEN}Executing:${CL_NORM} ${CL_YELLOW}waiting in queue${CL_NORM}"
fi
done
fi
Expand Down
22 changes: 13 additions & 9 deletions SOURCES/libexec/build.shx
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,14 @@ processSpec() {
found_source=$(findSource "$file_name")

if [[ -n "$found_source" ]] ; then
show "File ${CL_CYAN}$file_name${CL_NORM} listed in spec and will be used for the build"
cp "$found_source" "$tmp_dir"
show "${CL_GREY}+${CL_NORM} $file_name ${CL_DARK}($(getGraceFileSize "$tmp_dir/$file_name"))${CL_NORM}"
elif [[ -f "$tmp_dir/$file_name" ]] ; then
show "File ${CL_CYAN}$file_name${CL_NORM} listed in spec and will be used for the build"
show "${CL_GREY}+${CL_NORM} $file_name ${CL_DARK}($(getGraceFileSize "$tmp_dir/$file_name"))${CL_NORM}"
elif [[ -n "$dlcache" ]] ; then
if [[ -f "$dlcache/$file_name" ]] ; then
show "File ${CL_CYAN}$file_name${CL_NORM} listed in spec and will be used for the build"
cp "$dlcache/$file_name" "$tmp_dir"
show "${CL_GREY}+${CL_NORM} $file_name ${CL_DARK}($(getGraceFileSize "$tmp_dir/$file_name"))${CL_NORM}"
else
show "Downloading source file ${CL_CYAN}${source_file}${CL_NORM}"

Expand All @@ -151,6 +151,8 @@ processSpec() {
fi

cp "$dlcache/$file_name" "$tmp_dir"

show "${CL_GREY}+${CL_NORM} ${file_name} ${CL_DARK}($(getGraceFileSize "$tmp_dir/$file_name"))${CL_NORM}"
fi
else
show "Downloading source file ${CL_CYAN}${source_file}${CL_NORM}"
Expand All @@ -161,11 +163,14 @@ processSpec() {
error "Error! Can't download file ${CL_BL_RED}${source_file}${CL_RED}."
doExit $ERROR_SOURCE
fi

show "${CL_GREY}+${CL_NORM} ${file_name} ${CL_DARK}($(getGraceFileSize "$tmp_dir/$file_name"))${CL_NORM}"
fi
else
if [[ -f "$tmp_dir/$source_file" ]] ; then
show "File ${CL_CYAN}${source_file}${CL_NORM} listed in spec and will be used for the build"
source_num=$(( source_num + 1 )) && continue
show "${CL_GREY}+${CL_NORM} ${source_file} ${CL_DARK}($(getGraceFileSize "$tmp_dir/$source_file"))${CL_NORM}"
source_num=$(( source_num + 1 ))
continue
fi

local source_ext source_name found_dir found_source
Expand All @@ -181,16 +186,15 @@ processSpec() {
fi

if [[ -n "$source_ext" && -n "$found_dir" ]] ; then
show "File ${CL_CYAN}${source_file}${CL_NORM} listed in spec and will be created from sources directory"

packDir "$found_dir/$source_name" "$source_ext"
mv "$found_dir/$source_file" "$tmp_dir"

show "${CL_GREY}+${CL_NORM} ${source_file} ${CL_DARK}($(getGraceFileSize "$tmp_dir/$source_file"))${CL_NORM}"

source_num=$(( source_num + 1 )) && continue
elif [[ -n "$found_source" ]] ; then
show "File ${CL_CYAN}${source_file}${CL_NORM} listed in spec and will be used for build"

cp "$found_source" "$tmp_dir"
show "${CL_GREY}+${CL_NORM} ${source_file} ${CL_DARK}($(getGraceFileSize "$tmp_dir/$source_file"))${CL_NORM}"

source_num=$(( source_num + 1 )) && continue
else
Expand Down
8 changes: 4 additions & 4 deletions SOURCES/libexec/observer.shx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
startStatusObserver() {
[[ -n "$verbose" ]] && return 0

showt "\r${CL_GREEN}Executing:${CL_NORM} ${CL_CYAN}~${CL_NORM}"
showt "${CL_GREEN}Executing:${CL_NORM} ${CL_CYAN}~${CL_NORM}"

statusObserver &
observer_pid=$!
Expand All @@ -26,7 +26,7 @@ stopStatusObserver() {
kill "$observer_pid" &> /dev/null
wait "$observer_pid" &> /dev/null

showm "\r${CL_GREEN}Executing:${CL_NORM} ${CL_CYAN}clean${CL_NORM} "
showm "${CL_GREEN}Executing:${CL_NORM} ${CL_CYAN}clean${CL_NORM} "
show ""

unset observer_pid
Expand All @@ -52,8 +52,8 @@ statusObserver() {
fi

if [[ "$status" != "$prev_status+$bld_time" ]] ; then
grc_time=$(getGraceDuration "$bld_time")
showt "\r${CL_GREEN}Executing:${CL_NORM} ${CL_CYAN}$status${CL_NORM} ${CL_DARK}($grc_time)${CL_NORM}"
grc_time=$(getGraceDuration "$build_start" "$cur_time")
showt "${CL_GREEN}Executing:${CL_NORM} ${CL_CYAN}$status${CL_NORM} ${CL_DARK}($grc_time)${CL_NORM}"
prev_status="$status+$bld_time"
fi

Expand Down
54 changes: 50 additions & 4 deletions SOURCES/libexec/utils.shx
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,18 @@ getLogDate() {

# Prints duration in pretty format
#
# 1: Duration in seconds (Number)
# 1: Action start timestamp (Number)
# 2: Action end timestamp (Number)
#
# Code: No
# Echo: Duration (String)
getGraceDuration() {
local dur="$1"
local sec min
local action_start="$1"
local action_end="${2:-$(now)}"

local sec min dur

dur=$(( action_end - action_start ))

if [[ -z "$dur" || "$dur" == "0" ]] ; then
echo "< 1 sec"
Expand All @@ -72,6 +77,39 @@ getGraceDuration() {
fi
}


# Prints duration in pretty, short format
#
# 1: Action start timestamp (Number)
# 2: Action end timestamp (Number)
#
# Code: No
# Echo: Duration (String)
getGraceDurationShort() {
local action_start="$1"
local action_end="${2:-$(now)}"

local sec min dur

dur=$(( action_end - action_start ))

if [[ -z "$dur" || "$dur" == "0" ]] ; then
echo "[0:01]"
return 0
fi

sec=$(( dur % 60 ))
min=$(( ( dur - sec ) / 60 ))

sec=$(printf "%02d" $sec)

if [[ $min -eq 0 ]] ; then
echo "[0:$sec]"
else
echo "[$min:$sec]"
fi
}

# Prints grace file size
#
# 1: Path to file (String)
Expand All @@ -83,8 +121,16 @@ getGraceFileSize() {
return
fi

local size

# shellcheck disable=SC2012
ls -lah "$1" | awk -F " " '{print $5}'
size=$(ls -lah "$1" | awk -F " " '{print $5}')

if [[ $size =~ ^[0-9]+$ ]] ; then
echo "${size}B"
else
echo "$size"
fi
}

# Shows separator
Expand Down
10 changes: 5 additions & 5 deletions SOURCES/rpmbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fi
APP="RPMBuilder"

# Utility version (String)
VER="2.10.0"
VER="2.11.0"

################################################################################

Expand Down Expand Up @@ -47,6 +47,7 @@ CL_BL_BLUE="\e[1;${BLUE};49m"
CL_BL_MAG="\e[1;${MAG};49m"
CL_BL_CYAN="\e[1;${CYAN};49m"
CL_BL_GREY="\e[1;${GREY};49m"
CL_BLNK_YELLOW="\e[5;${YELLOW};49m"

ERROR_UNKNOWN=1
ERROR_ARGS=2
Expand Down Expand Up @@ -299,15 +300,14 @@ showm() {
# Code: No
# Echo: No
showt() {
local message offset spaces adds
local message spaces adds

message=$(echo "$1" | sed -r "s/\\\e\[([0-9;]{1,12}m)//g")
offset="${2-0}"
spaces=" "

adds=$((${#SEPARATOR} - ${#message} - offset))
adds=$((${#SEPARATOR} - ${#message}))

echo -e -n "${1}${spaces:0:$adds}"
echo -e -n "\r${1}${spaces:0:$adds}"
}

# Print option usage info
Expand Down
6 changes: 5 additions & 1 deletion rpmbuilder.spec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Summary: RPM package build helper
Name: rpmbuilder
Version: 2.10.0
Version: 2.11.0
Release: 0%{?dist}
License: Apache License, Version 2.0
Group: Development/Tools
Expand Down Expand Up @@ -55,6 +55,10 @@ rm -rf %{buildroot}
################################################################################

%changelog
* Thu Sep 09 2021 Anton Novojilov <andy@essentialkaos.com> - 2.11.0-0
- Improved UI
- Code refactoring

* Thu Aug 26 2021 Anton Novojilov <andy@essentialkaos.com> - 2.10.0-0
- Improved fetching data from remote sources
- Code refactoring
Expand Down

0 comments on commit b7d5bdc

Please sign in to comment.