- Re-enable ROM listing,

- Fix statistics,
- Improve job control: only fork job which required extract/compress processing.
This commit is contained in:
agibert 2009-03-26 09:16:35 +00:00
parent 386c71c071
commit dcc023872f

408
nds2rm
View File

@ -5,9 +5,9 @@
# (C) 2009 Arnaud G. Gibert
#-----------------------------------------------------------------------------------------------------------------------------------
# $RCSfile: nds2rm,v $
# $Revision: 1.6 $
# $Revision: 1.7 $
# $Name: $
# $Date: 2009/03/25 08:46:41 $
# $Date: 2009/03/26 09:16:35 $
# $Author: agibert $
#-----------------------------------------------------------------------------------------------------------------------------------
@ -173,8 +173,6 @@ function dat_load()
dat_fp[${idx}]="????"
dat_status[${idx}]="?"
dat_dup[${idx}]="0"
dat_filename[${idx}]=""
dat_pid[${idx}]="0"
loaded_cnt=$((${loaded_cnt} + 1))
fi
@ -198,6 +196,7 @@ function job_init()
job_dir[${job_id}]="${TMP_DIR}/nds2rom-$$-${job_id}"
mkdir "${job_dir[${job_id}]}"
> "${job_dir[${job_id}]}/${STATS_FILE}"
job_id=$((${job_id} + 1))
done
@ -278,7 +277,7 @@ function crc_lookup()
# Dump Rom List
# Verbose Print
#-----------------------------------------------------------------------------------------------------------------------------------
function print_verbose()
@ -472,11 +471,6 @@ function arc_build()
print_verbose "zipping ${rom} into ${file_name}"
# zip -m9 "${file_name}" "${rom}" >/dev/null 2>&1 &
# job_pid[${job_id}]=$!
# dat_pid[${idx}]=$!
zip -m9 "${NDS_ROMS_OUT}/${file_name}" "${rom}" >/dev/null 2>&1
else
print_verbose "removing ${rom}"
@ -502,8 +496,8 @@ function arc_rename()
if [[ "${mode}" == "correct" ]]
then
if [[ ${action} != "keep_status" ]]
then
# if [[ ${action} != "keep_status" ]]
# then
if [[ ${in_place} == "yes" ]]
then
print_verbose "moving ${file} to ${file_name}"
@ -514,7 +508,7 @@ function arc_rename()
cp "${NDS_ROMS_IN}/${file}" "${NDS_ROMS_OUT}/${file_name}"
fi
fi
# fi
fi
}
@ -615,13 +609,50 @@ function tmp_mv()
# Test and Correct Mode
# Identify Arc
#-----------------------------------------------------------------------------------------------------------------------------------
function arc_test_correct()
function arc_ident()
{
arc_type_ptr=${1}
extract_ptr=${2}
file=${3}
# Type of archive ?
if [[ ${file} =~ ${RNFH_REGEX} ]]
then
eval ${arc_type_ptr}="rx3"
else
eval ${arc_type_ptr}="unknown"
fi
# Extract ROM if needed
if [[ ( "${arc_type}" != "rx3" ) || ( "${rebuild}" == "yes" ) ]]
then
eval ${extract_ptr}="yes"
else
eval ${extract_ptr}="no"
fi
}
# Proceed Arc
#-----------------------------------------------------------------------------------------------------------------------------------
function arc_proceed()
{
file=${1}
found_cnt=${2}
arc_type=${2}
extract=${3}
found_cnt=${4}
set ${file:0:4}
@ -636,19 +667,10 @@ function arc_test_correct()
lang=${dat_lang[${idx}]}
crc=${dat_crc[${idx}]}
# Type of archive ?
if [[ ${file} =~ ${RNFH_REGEX} ]]
then
arc_type="rx3"
else
arc_type="unknown"
fi
# Extract ROM if needed
if [[ ( "${arc_type}" != "rx3" ) || ( "${rebuild}" == "yes" ) ]]
if [[ "${extract}" == "yes" ]]
then
rom="${id} - ${title} (${reg}:${lang}).nds"
@ -740,22 +762,20 @@ function arc_test_correct()
status=${status2}
fi
renum_cnt=$((${renum_cnt} + 1))
renumed="yes"
fi
else
fi
# Rename ROM if needed
if [[ ( "${arc_type}" != "rx3" ) || ( "${rebuild}" == "yes" ) ]]
then
rom2="${id} - ${title} (${reg}:${lang}) [${status}].nds"
if [[ ( "${renumed}" != "yes") && ( ( "${arc_type}" != "rx3" ) || ( "${rebuild}" == "yes" ) ) ]]
then
rom2="${id} - ${title} (${reg}:${lang}) [${status}].nds"
print_verbose "moving ${rom} to ${rom2}"
print_verbose "moving ${rom} to ${rom2}"
mv "${rom}" "${rom2}"
rom=${rom2}
fi
mv "${rom}" "${rom2}"
rom=${rom2}
fi
@ -779,10 +799,147 @@ function arc_test_correct()
# Updates Stats
echo "${renumed}" "${action}" "${status}" >"${STATS_FILE}"
echo "${renumed}" "${action}" "${status}" >>"${STATS_FILE}"
}
#stats_update "${action}" "${mode}"
# Manage Archives
#-----------------------------------------------------------------------------------------------------------------------------------
function arc_mng()
{
# Initialize Job Control
job_init
echo "processing rom repository..."
IFS=' '
found_cnt=0
tmp_file=$(mktemp)
ls ${NDS_ROMS_IN} > ${tmp_file}
while read file
do
arc_ident "arc_type" "extract" "${file}"
if [[ "${extract}" == "no" ]]
then
arc_proceed "${file}" "${arc_type}" "${extract}" "${found_cnt}"
else
job_switch "${job_id}"
arc_proceed "${file}" "${arc_type}" "${extract}" "${found_cnt}" &
job_pid[${job_id}]=$!
fi
# Update stats
found_cnt=$((${found_cnt} + 1))
printf "found: %4d" ${found_cnt}
if [[ "${verbose}" == "yes" ]]
then
echo
else
printf "\r"
fi
done < ${tmp_file}
\rm -f ${tmp_file}
# Wait all Jobs
wait
# Collect Stats"
cd "${TMP_DIR}"
cat *"/${STATS_FILE}" >> "${STATS_FILE}"
# DeInitialize Job Control
job_deinit
}
# Manage Arc Suffix
#-----------------------------------------------------------------------------------------------------------------------------------
function suffix_mng()
{
echo "managing duplicate archives..."
IFS=' '
found_cnt=0
ok_cnt=0
ko_cnt=0
dup_cnt=0
idx_old=0
tmp_file=$(mktemp)
ls ${NDS_ROMS_OUT} > ${tmp_file}
while read file
do
set ${file:0:4}
id=$1
idx=${id/*(0)/}
status=${file/* \[/}; status=${status/\] \{*/}
crc=${file/*\] \{/}; crc=${crc/\} \<*/}
fp=${file/*\} \</}; fp=${fp/\>-*/}
dat_dup[${idx}]="${dup_id}"
if [[ ${idx} != ${idx_old} ]]
then
idx_old=${idx}
dup_id=0
file_name="${file/) \[*/}) [${status}] {${crc}} <${fp}>.zip"
dat_fp[${idx}]="${fp}"
dat_status[${idx}]="${status}"
if [[ "${status}" == "OK" ]]
then
ok_cnt=$((${ok_cnt} + 1))
else
ko_cnt=$((${ko_cnt} + 1))
fi
else
dup_id=$((${dup_id} + 1))
file_name="${file/) \[*/}) [${status}] {${crc}} <${fp}>-${dup_id}.zip"
dup_cnt=$((${dup_cnt} + 1))
fi
print_verbose "moving ${file} to ${file_name}"
arc_mv "${NDS_ROMS_OUT}/${file_name}" "${NDS_ROMS_OUT}/${file}" "${mode}"
found_cnt=$((${found_cnt} + 1))
printf "found: %4d" ${found_cnt}
if [[ "${verbose}" == "yes" ]]
then
echo
else
printf "\r"
fi
done < ${tmp_file}
\rm -f ${tmp_file}
}
@ -800,6 +957,11 @@ function stats_update()
mode=${4}
if [[ "${renumed}" == "yes" ]]
then
renum_cnt=$((${renum_cnt} + 1))
fi
case ${action} in
("set_status")
if [[ ${status} == "OK" ]]
@ -877,6 +1039,8 @@ function stats_proceed()
function stats_print()
{
echo " "
echo
printf "%4d roms set to OK\n" ${ss_ok_cnt}
printf "%4d roms changed to OK\n" ${cs_ok_cnt}
printf "%4d roms kept to OK\n" ${ks_ok_cnt}
@ -897,147 +1061,6 @@ function stats_print()
# Manage Archives
#-----------------------------------------------------------------------------------------------------------------------------------
function arc_mng()
{
# Initialize Job Control
job_init
echo "processing rom repository..."
IFS=' '
found_cnt=0
tmp_file=$(mktemp)
ls ${NDS_ROMS_IN} > ${tmp_file}
while read file
do
job_switch "${job_id}"
arc_test_correct "${file}" "${found_cnt}" &
job_pid[${job_id}]=$!
# Update stats
# stats_update "${action}" "${mode}"
found_cnt=$((${found_cnt} + 1))
# printf "found: %4d OK: %4d KO: %4d renumbered: %4d duplicated: %4d missing: %4d" ${found_cnt} ${ok_cnt} ${ko_cnt} ${renum_cnt} ${dup_cnt} ${missing_cnt}
printf "found: %4d" ${found_cnt}
if [[ "${verbose}" == "yes" ]]
then
echo
else
printf "\r"
fi
done < ${tmp_file}
\rm -f ${tmp_file}
wait
if [[ "${verbose}" != "yes" ]]
then
echo " "
fi
echo
# Collect Stats"
cd "${TMP_DIR}"
cat *"/${STATS_FILE}" > "${STATS_FILE}"
# DeInitialize Job Control
job_deinit
}
# Manage Arc Suffix
#-----------------------------------------------------------------------------------------------------------------------------------
function suffix_mng()
{
echo "managing duplicate archives..."
IFS=' '
found_cnt=0
ok_cnt=0
ko_cnt=0
dup_cnt=0
idx_old=0
tmp_file=$(mktemp)
ls ${NDS_ROMS_OUT} > ${tmp_file}
while read file
do
set ${file:0:4}
id=$1
idx=${id/*(0)/}
status=${file/* \[/}; status=${status/\] \{*/}
crc_fp=${file/*\] \{/{}; crc_fp=${crc_fp/-*/}
if [[ ${idx} != ${idx_old} ]]
then
idx_old=${idx}
dup_id=0
file_name="${file/) \[*/}) [${status}] ${crc_fp}.zip"
if [[ "${status}" == "OK" ]]
then
ok_cnt=$((${ok_cnt} + 1))
else
ko_cnt=$((${ko_cnt} + 1))
fi
else
dup_id=$((${dup_id} + 1))
file_name="${file/) \[*/}) [${status}] ${crc_fp}-${dup_id}.zip"
dup_cnt=$((${dup_cnt} + 1))
fi
print_verbose "moving ${file} to ${file_name}"
arc_mv "${NDS_ROMS_OUT}/${file_name}" "${NDS_ROMS_OUT}/${file}" "${mode}"
found_cnt=$((${found_cnt} + 1))
printf "found: %4d" ${found_cnt}
if [[ "${verbose}" == "yes" ]]
then
echo
else
printf "\r"
fi
done < ${tmp_file}
\rm -f ${tmp_file}
}
# DSROM Mode
#-----------------------------------------------------------------------------------------------------------------------------------
@ -1111,20 +1134,21 @@ function test_correct_mode()
# Dump ROMs List
#-----------------------------------------------------------------------------------------------------------------------------------
# if [[ ${lok} == "yes" ]]
# then
# ok_dump
# fi
#
# if [[ ${lko} == "yes" ]]
# then
# ko_dump
# fi
#
# if [[ ${lmiss} == "yes" ]]
# then
# missing_dump
# fi
if [[ ${lok} == "yes" ]]
then
ok_dump
fi
if [[ ${lko} == "yes" ]]
then
ko_dump
fi
if [[ ${lmiss} == "yes" ]]
then
missing_dump
fi
# Collect and Proceed Stats