Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.13 KB | None | 0 0
  1. #!/bin/sh
  2. DOCDIR="./doc/"
  3. FILESTOTRANSLATE="doc/en_US.ISO8859-1"
  4. DATAFILE="./translation-status.csv"
  5. LANGPARAM="$1"
  6.  
  7. # commands
  8. AWK="/usr/bin/awk"
  9. BASENAME="/usr/bin/basename"
  10. CUT="/usr/bin/cut"
  11. FIND="/usr/bin/find"
  12. PRINTF="/usr/bin/printf"
  13. SVN="/usr/bin/svnlite"
  14. WC="/usr/bin/wc"
  15. SED="/usr/bin/sed"
  16. SORT="/usr/bin/sort"
  17. GREP="/usr/bin/grep"
  18.  
  19.  
  20. FIND_EN_DOC=`${FIND} ${DOCDIR} -name "??_*" -type d -depth 1 -print | ${SORT} | ${GREP} -v en_US`
  21.  
  22. check_docdir() {
  23. if [ ! -d "${DOCDIR}" ]; then
  24. DOCDIR="doc/"
  25. if [ ! -d "${DOCDIR}" ]; then
  26. echo "** document directory not found, please edit and set DOCDIR"
  27. echo "** value to document checkout directory, like ~/doc"
  28. exit 1
  29. fi
  30. fi
  31. }
  32.  
  33. check_lang_param() {
  34. if [ "${LANGPARAM}" ]; then
  35. # parameter was given, assume it is a single language directory
  36. case "${LANGPARAM}" in ??_??*) ;;
  37. # did not match the language code pattern
  38. *) echo "** parameter does not look like a language directory name,"
  39. echo "** expecting xx_YY*, like es_ES.ISO8859-1"
  40. exit 1 ;;
  41. esac
  42. LANGDIR=`${FIND} ${DOCDIR} -depth 1 -name "${LANGPARAM}".*`
  43. LANGS=`${BASENAME} ${LANGDIR}`
  44. else
  45. LANGS=${FIND_EN_DOC}
  46. fi
  47. }
  48.  
  49. create_datafile() {
  50. echo "writing CSV data to ${DATAFILE}"
  51. ${PRINTF} > "${DATAFILE}" "langcode,pubtype,docname,status,needs updating\r\n"
  52. }
  53.  
  54. print_title() {
  55. echo "FreeBSD document translations"
  56. echo
  57. }
  58.  
  59. print_header() {
  60. # title
  61. ${PRINTF} " %-29s %-12s %-12s\n" document status needs_updating
  62. ${PRINTF} " %-27s %-12s %-12s\n" "-------------------------" "--------------" "--------------------------"
  63. }
  64.  
  65. print_data() {
  66.  
  67. langcode="$1"
  68. pubtype="$2"
  69. name="$3"
  70. status="$4"
  71. updating="$5"
  72.  
  73. ${PRINTF} " %-29s %-12s %-12s\n" ${name} ${status} ${updating}
  74. ${PRINTF} >> "${DATAFILE}" "%s,%s,%s,%s,%s\r\n" ${langcode} ${pubtype} ${name} ${status} ${updating}
  75. }
  76.  
  77. # Obtains the last modified date for a given file.
  78. get_file_date(){
  79.  
  80. filename=$1
  81. filedate=""
  82.  
  83. if [ -e "${filename}" ]; then
  84. filestat=`${SVN} stat ${filename} 2>&1 | ${CUT} -w -f1`
  85. if [ "${filestat}" != "?" -a "${filename}" != "svn:" ]; then
  86. if [ "${filestat}" = "A" ]; then
  87. # file has been added but not yet committed, no dates available
  88. filedate="*"
  89. else
  90. filedate=`${SVN} log -l 1 ${filename} | ${AWK} 'NR==2 { print $5 }'| ${SED} 's/\-//g'`
  91. fi
  92. fi
  93. fi
  94.  
  95. }
  96.  
  97. # Get the status of a given publication.
  98. get_doc_status(){
  99.  
  100. pubtype=$1
  101. langcode=$2
  102. currdir=${PWD}
  103.  
  104.  
  105. cd ${FILESTOTRANSLATE}/${pubtype}/
  106.  
  107. echo
  108. echo "**************" ${pubtype}
  109. echo
  110.  
  111. doclist=`ls -d */ | sort`
  112. echo
  113.  
  114. cd ${currdir}
  115.  
  116. langdir=${DOCDIR}${langcode}
  117.  
  118. print_header
  119.  
  120. for doc in ${doclist}; do
  121.  
  122. documents_total=$((${documents_total}+1))
  123.  
  124. originalfile=${FILESTOTRANSLATE}/${pubtype}/${doc}
  125.  
  126. get_file_date ${originalfile}
  127.  
  128. originaldate=${filedate}
  129. translationdir=${langdir}/${pubtype}/${doc}
  130. dirbasename=`${BASENAME} "${translationdir}"`
  131.  
  132.  
  133. if [ -d "${translationdir}" ]; then
  134.  
  135. documents_translated=$((${documents_translated}+1))
  136.  
  137. status="translated"
  138. pofile="${translationdir}/${langcode}.po"
  139. altfile="${translationdir}/Makefile"
  140.  
  141. if [ -e "${pofile}" ]; then
  142. get_file_date ${pofile}
  143. else
  144. if [ -e "${altfile}" ]; then
  145. get_file_date ${altfile}
  146. fi
  147. fi
  148.  
  149. lastdate=${filedate}
  150.  
  151. if [ "${lastdate}" == "*" ]; then
  152. # The file has been added to SVN but it hasn't been commited.
  153. updating="N/A"
  154. status="NOT_IN_SVN"
  155. else
  156.  
  157. # The file is on SVN.
  158. if [ -d "${translationdir}" ]; then
  159. if [ ${originaldate} -gt ${lastdate} ]; then
  160. updating="YES"
  161. else
  162. updating="NO"
  163. fi
  164. fi
  165.  
  166. fi
  167.  
  168. else
  169. # The file has not been translated.
  170. status="untranslated"
  171. updating="N/A"
  172. fi
  173.  
  174. print_data ${langcode} ${pubtype} ${dirbasename} ${status} ${updating}
  175.  
  176. done
  177.  
  178. }
  179.  
  180.  
  181. main() {
  182.  
  183. documents_translated=0
  184. documents_total=0
  185.  
  186. print_title
  187.  
  188. check_docdir
  189. check_lang_param
  190. create_datafile
  191.  
  192. echo
  193.  
  194. for lang in ${LANGS}; do
  195.  
  196. langcode=`${BASENAME} ${lang}`
  197. langcode_header=`${PRINTF} "%-.5s" ${langcode}`
  198. echo "-----------------------------" ${langcode_header} "-----------------------------"
  199. echo
  200. echo
  201.  
  202.  
  203. get_doc_status articles ${langcode}
  204. get_doc_status books ${langcode}
  205. get_doc_status captions ${langcode}
  206. get_doc_status htdocs ${langcode}
  207. get_doc_status slides ${langcode}
  208.  
  209. echo
  210. echo "================================="
  211. echo "Statistics"
  212. echo
  213. echo
  214. echo " Total documents to translate: "${documents_total}
  215. echo " Documents translated: "${documents_translated}
  216. percentage=$(( 100* documents_translated/ documents_total ))
  217. echo " "${percentage}" % translated"
  218. echo "==================================="
  219.  
  220. documents_translated=0
  221. documents_total=0
  222.  
  223. done
  224.  
  225. }
  226.  
  227. main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement