Skip to content
This repository has been archived by the owner on Jun 9, 2018. It is now read-only.

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
dagon666 committed Sep 11, 2014
2 parents b8c262d + a39e307 commit aa79d11
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 8 deletions.
34 changes: 32 additions & 2 deletions napi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,21 @@ normalize_language() {

#################################### ENV #######################################

cleanup_tmp_files() {
_debug $LINENO "usuwam pliki tymczasowe (jesli istnieja)"
$g_cmd_unlink napisy.7z.*
$g_cmd_unlink napi.*
$g_cmd_unlink ipc.*
$g_cmd_unlink stats.*
}


trap_control_c() {
_msg $LINENO "przechwycono CTRL+C, koncze wykonywanie...";
cleanup_tmp_files
exit $?
}

#
# @brief configure external commands
#
Expand Down Expand Up @@ -335,9 +350,11 @@ configure_cmds() {
# @brief verify system settings and gather info about commands
#
verify_system() {
local cores=1
_debug $LINENO "weryfikuje system"
cores=$(get_cores ${g_system[0]})
g_system[0]="$(get_system)"
g_system[1]=$(( $(get_cores) * 2 ))
g_system[1]=$(( cores * 2 ))
}


Expand Down Expand Up @@ -1267,6 +1284,15 @@ extract_subs_xml() {
# extract the subs data
local xml_subs=$(extract_xml_tag 'subtitles' "$xml_path")

# check if the subtitles tag exist in the output
# it's possible that the downloaded xml contains only
# the cover and metadata
if [ -z "$xml_subs" ]; then
_debug $LINENO "plik xml nie zawiera taga subtitles"
_info $LINENO "napisy niedostepne"
return $RET_UNAV
fi

# extract content
local subs_content=$(echo "$xml_subs" | extract_xml_tag 'content')

Expand Down Expand Up @@ -2360,7 +2386,8 @@ process_files() {
done

# dump statistics to fd #8 (if it has been opened before)
[ -e "/proc/self/fd/8" ] && echo "${g_stats[*]}" >&8
[ -e "/proc/self/fd/8" ] || [ -e "/dev/fd/8" ] &&
echo "${g_stats[*]}" >&8
return $RET_OK
}

Expand Down Expand Up @@ -2657,6 +2684,9 @@ main() {
prepare_file_list $g_min_size "${g_paths[@]}"
_msg "znaleziono ${#g_files[@]} plikow..."

# install traps
trap trap_control_c SIGINT

# do the job
spawn_forks

Expand Down
22 changes: 17 additions & 5 deletions napi_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,17 @@ modify_value() {
# determines number of available cpu's in the system
#
get_cores() {
grep -i processor /proc/cpuinfo | count_lines
local os="${1:-linux}"

if [ "$os" = "darwin" ]; then
sysctl hw.ncpu | cut -d ' ' - f 1
else
grep -i processor /proc/cpuinfo | wc -l
fi
}



#
# @brief detects running system type
#
Expand All @@ -246,7 +253,8 @@ get_system() {
# @brief extracts http status from the http headers
#
get_http_status() {
grep -o "HTTP/[\.0-9]* [0-9]*"
# grep -o "HTTP/[\.0-9]* [0-9]*"
awk '{ m = match($0, /HTTP\/[\.0-9]* [0-9]*/); if (m) print substr($0, m, RLENGTH) }'
}

################################## STDOUT ######################################
Expand Down Expand Up @@ -344,9 +352,13 @@ to_stderr() {
# @brief redirect stdout to logfile
#
redirect_to_logfile() {
[ -n "${g_output[$___LOG]}" ] &&
[ "${g_output[$___LOG]}" != "none" ] &&
exec 3>&1 4>&2 1> "${g_output[$___LOG]}" 2>&1
if [ -n "${g_output[$___LOG]}" ] && [ "${g_output[$___LOG]}" != "none" ]; then
# truncate
cat /dev/null > "${g_output[$___LOG]}"

# append instead of ">" to assure that children won't mangle the output
exec 3>&1 4>&2 1>> "${g_output[$___LOG]}" 2>&1
fi
}


Expand Down
2 changes: 1 addition & 1 deletion tests/t/007-subotage.t
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ foreach my $format (@formats) {

is ($rv, 0, "return value for $format -> $dst_format conversion");
is ( -e $dst_file, 1, "checking $dst_file existence" );
ok ( (count_lines $dst_file) > $minimum, "the number of lines $dst_file" );
ok ( (count_lines $dst_file) >= $minimum, "the number of lines $dst_file" );

# check format detection
is ( (split ' ', qx/subotage.sh -gi -i $dst_file | grep IN_FORMAT/)[3],
Expand Down

0 comments on commit aa79d11

Please sign in to comment.