Index: branches/blackosx/package/Resources.source/ConvertResourcesTextFile.pl =================================================================== --- branches/blackosx/package/Resources.source/ConvertResourcesTextFile.pl (revision 1833) +++ branches/blackosx/package/Resources.source/ConvertResourcesTextFile.pl (revision 1834) @@ -7,19 +7,23 @@ # # The human readable file is hosted on Google Docs at: # www....... -# The file should be saved from Google Docs by using: -# File -> Download As -> Text (current sheet) +# The spreadsheet is a published file and will be +# automatically downloaded as a UTF-8, tabbed delimited +# text file which will be savedd in the same folder as +# this script. # -# This saves a UTF-8, tabbed delimited text file which -# should be placed in the same folder as this script. +# Call this script with: +# ./ConvertResourcesTextFile.pl ResourcesSourceFile.txt # +# use LWP::Simple; -if ($#ARGV < 0) { - print stderr "A destination file is needed\n"; +if ($#ARGV < 1) { + print stderr "A destination path and filename is needed\n"; } else { - $destination_file=$ARGV[0]; + $destination_dir=$ARGV[0]; + $destination_file=$ARGV[1]; } sub set_indent { @@ -59,11 +63,11 @@ #-------------------------------------------------------------------------- $googlePublishedDoc = 'https://docs.google.com/spreadsheet/pub?key=0Aj0jJ2rdmK_sdFdNbm45NlpNYU1PcjRmOHVXX0FNa3c&single=true&gid=0&output=txt'; $sourceFileToRead="PackageInstallerResourceText.tsv"; -getstore ($googlePublishedDoc, $sourceFileToRead) or die "Couldn't get master file"; +getstore ($googlePublishedDoc, $destination_dir."/".$sourceFileToRead) or die "Couldn't get master file"; #-------------------------------------------------------------------------- -open (FILE, "$sourceFileToRead"); -open (OUTFILE, ">$destination_file"); +open (FILE, "$destination_dir"."/"."$sourceFileToRead"); +open (OUTFILE, ">$destination_dir"."/"."$destination_file"); print OUTFILE "\n"; # Output blank line. # This is needed so after converting to rtf using textutil in later bash script @@ -71,11 +75,13 @@ while () { $indent = " "; chomp; + s/&/and/g; # Handle '&' for now by converting to 'and'. + s/&/and/g; # Handle '&' for now by converting to 'and'. @fieldsReadIn = split("\t"); - $startFirstField=substr($fieldsReadIn[0],0,1); # First charatcer of first field - $startSecondField=substr($fieldsReadIn[1],0,1); # First charatcer of second field + $startFirstField=substr($fieldsReadIn[0],0,1); # First character of first field. + $startSecondField=substr($fieldsReadIn[1],0,1); # First character of second field. - if ($startFirstField ne "#" ) { # Ignore lines beginning with a hash + if ($startFirstField ne "#" ) { # Ignore lines beginning with a hash. if ($startFirstField ne "") { # Check first field for language identifier. print OUTFILE "language: $fieldsReadIn[0]\n"; # Output first field - LANGUAGE. } @@ -97,7 +103,7 @@ $headedFieldCount++; $indent=calculateIndent; print OUTFILE $indent."$fieldsWithoutLanguage[$loop]: $fieldsReadIn[$loop]\n"; - $fieldsWithHeadersSet[$headedFieldCount]=1; # Set value in this array to mark that we've written to it. + $fieldsWithHeadersSet[$headedFieldCount]=1; # Set value in this array to mark that we've written to it. } } } @@ -105,4 +111,5 @@ } close (FILE); close (OUTFILE); +unlink("$destination_dir"."/"."$sourceFileToRead"); # Remove downloaded Google Doc file. exit; \ No newline at end of file Index: branches/blackosx/package/buildpkg.sh =================================================================== --- branches/blackosx/package/buildpkg.sh (revision 1833) +++ branches/blackosx/package/buildpkg.sh (revision 1834) @@ -975,13 +975,12 @@ buildresources() { ResourcesSourceFolder="${PKGROOT}/Resources.source" ResourcesSourceFile="ResourcesSourceFile.txt" - - ResourcesLanguageFile="${ResourcesSourceFolder}/${ResourcesSourceFile}" + # Check for ResourcesSourceFile.txt. - # If it doesn't exist then run perl script to make another one from - # the UTF-8 .tsv file saved from the master Google docs spreadsheet. - if [ -f "${ResourcesLanguageFile}" ]; then - "${ResourcesSourceFolder}/ConvertResourcesTextFile.pl" "${ResourcesLanguageFile}" + # It now won't exist, so call perl script to download the published + # Google docs spreadsheet as UTF-8 .tsv file and make another one. + if [ ! -f "${PKG_BUILD_DIR}/${ResourcesSourceFile}" ]; then + "${ResourcesSourceFolder}/ConvertResourcesTextFile.pl" "${PKG_BUILD_DIR}" "${ResourcesSourceFile}" fi #Initialise Variables @@ -989,87 +988,93 @@ resetVars # begin - while read -r line - do - case "${line%%:*}" in + if [ -f "${PKG_BUILD_DIR}/${ResourcesSourceFile}" ]; then + while read -r line + do + case "${line%%:*}" in - "language" ) - foundLanguage="${line#*: }" - if [ ! -d "${PKG_BUILD_DIR}/${packagename}/Resources/$foundLanguage" ]; then - echo -e "\tCreating Language Resource Folder: $foundLanguage" - mkdir -p "${PKG_BUILD_DIR}/${packagename}/Resources/$foundLanguage" - fi + "language" ) + foundLanguage="${line#*: }" + if [ ! -d "${PKG_BUILD_DIR}/${packagename}/Resources/$foundLanguage" ]; then + echo -e "\tCreating Language Resource Folder: $foundLanguage" + mkdir -p "${PKG_BUILD_DIR}/${packagename}/Resources/$foundLanguage" + fi - ## Add License.rtf file to Language folder - if [ ! -f "${PKG_BUILD_DIR}/${packagename}/Resources/$foundLanguage/License.rtf" ]; then - echo -e "\t\tAdding License.rtf file" - ditto --noextattr --noqtn "${ResourcesSourceFolder}/License.rtf" "${PKG_BUILD_DIR}/${packagename}/Resources/$foundLanguage" - fi + ## Add License.rtf file to Language folder + if [ ! -f "${PKG_BUILD_DIR}/${packagename}/Resources/$foundLanguage/License.rtf" ]; then + echo -e "\t\tAdding License.rtf file" + ditto --noextattr --noqtn "${ResourcesSourceFolder}/License.rtf" "${PKG_BUILD_DIR}/${packagename}/Resources/$foundLanguage" + fi - resetVars - ;; + resetVars + ;; - "file" ) - # Have we already built an array of codes for the Welcome, Conclusion or Description Resource files? - if [ ${#buildCodes[@]} -ne 0 ]; then - for (( n=0; n<${#buildCodes[@]}; n++ )) - do - templateStrings[${#templateStrings[*]}]="--subst=${buildCodes[$n]}" - done - # Send the pre-built arrays to addTemplateResources() for completing template. - addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${packagename}/Resources/$foundLanguage" \ - "${templateStrings[@]}" \ - --type="" \ - "$resourceToUse" - fi + "file" ) + # Have we already built an array of codes for the Welcome, Conclusion or Description Resource files? + if [ ${#buildCodes[@]} -ne 0 ]; then + for (( n=0; n<${#buildCodes[@]}; n++ )) + do + templateStrings[${#templateStrings[*]}]="--subst=${buildCodes[$n]}" + done + # Send the pre-built arrays to addTemplateResources() for completing template. + addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${packagename}/Resources/$foundLanguage" \ + "${templateStrings[@]}" \ + --type="" \ + "$resourceToUse" + fi - resourceToUse="${line#*: }" - echo -e "\t\tComposing $resourceToUse File" - ;; + resourceToUse="${line#*: }" + echo -e "\t\tComposing $resourceToUse File" + ;; - "codeID" ) foundCode="${line#*: }" ;; - "messageName" ) foundMessageName="${line#*: }" ;; - "objectName" ) foundObjectName="${line#*: }"; foundObjectName="${foundObjectName%%_title*}" ;; - "objectTitle" ) foundObjectTitle="${line#*: }" ;; - "description" ) foundDescription="${line#*: }" ;; - esac + "codeID" ) foundCode="${line#*: }" ;; + "messageName" ) foundMessageName="${line#*: }" ;; + "objectName" ) foundObjectName="${line#*: }"; foundObjectName="${foundObjectName%%_title*}" ;; + "objectTitle" ) foundObjectTitle="${line#*: }" ;; + "description" ) foundDescription="${line#*: }" ;; + esac - if [[ "$foundLanguage" != "" ]]; then - # Build an array for each the Welcome, Conclusion and Description Resource files per language. - if [[ "$foundCode" != "" ]] && [[ "$foundDescription" != "" ]]; then - if [[ "$resourceToUse" == "Welcome" ]] || [[ "$resourceToUse" == "Conclusion" ]]; then - # Convert description from UFT8 to raw unicode markup - convertedFoundDescription=$( echo $foundDescription | textutil -convert rtf -encoding UTF-8 -stdin -stdout ) - # Strip away unicode text up to and including '\f0\fs24 \cf0' - take what's after. - strippedConvertedFoundDescription="${convertedFoundDescription#*\\f0\\fs24 \\cf0 }" - # Remove last character from string and replace all backslashes with a double backslash. - fixStrippedConvertedFoundDescription=$( echo "${strippedConvertedFoundDescription%?}" | sed -e 's/\\/\\\\/g' ) - #echo "$fixStrippedConvertedFoundDescription" - buildCodes[${#buildCodes[*]}]="$foundCode=$fixStrippedConvertedFoundDescription" + if [[ "$foundLanguage" != "" ]]; then + # Build an array for each the Welcome, Conclusion and Description Resource files per language. + if [[ "$foundCode" != "" ]] && [[ "$foundDescription" != "" ]]; then + if [[ "$resourceToUse" == "Welcome" ]] || [[ "$resourceToUse" == "Conclusion" ]]; then + # Convert description from UFT8 to raw unicode markup + convertedFoundDescription=$( echo $foundDescription | textutil -convert rtf -encoding UTF-8 -stdin -stdout ) + # Strip away unicode text up to and including '\f0\fs24 \cf0' - take what's after. + strippedConvertedFoundDescription="${convertedFoundDescription#*\\f0\\fs24 \\cf0 }" + # Remove last character from string and replace all backslashes with a double backslash. + fixStrippedConvertedFoundDescription=$( echo "${strippedConvertedFoundDescription%?}" | sed -e 's/\\/\\\\/g' ) + #echo "$fixStrippedConvertedFoundDescription" + buildCodes[${#buildCodes[*]}]="$foundCode=$fixStrippedConvertedFoundDescription" + fi + if [[ "$resourceToUse" == "Description" ]]; then + # No need to convert the text for the Description file as it's not RTF. + buildCodes[${#buildCodes[*]}]="$foundCode=$foundDescription" + fi + foundCode=""; foundDescription="" fi - if [[ "$resourceToUse" == "Description" ]]; then - # No need to convert the text for the Description file as it's not RTF. - buildCodes[${#buildCodes[*]}]="$foundCode=$foundDescription" - fi - foundCode=""; foundDescription="" - fi - # No need for an array for Localizable.strings. These can be written straight to file. - if [[ "$resourceToUse" == "LocalizableStrings" ]]; then - if [[ "$foundMessageName" != "" ]] && [[ "$foundDescription" != "" ]]; then - echo "\"${foundMessageName}\" = \"${foundDescription}\";" >> "${PKG_BUILD_DIR}/${packagename}/Resources/$foundLanguage/Localizable.strings" - echo "" >> "${PKG_BUILD_DIR}/${packagename}/Resources/$foundLanguage/Localizable.strings" - foundMessageName=""; foundDescription="" + # No need for an array for Localizable.strings. These can be written straight to file. + if [[ "$resourceToUse" == "LocalizableStrings" ]]; then + if [[ "$foundMessageName" != "" ]] && [[ "$foundDescription" != "" ]]; then + echo "\"${foundMessageName}\" = \"${foundDescription}\";" >> "${PKG_BUILD_DIR}/${packagename}/Resources/$foundLanguage/Localizable.strings" + echo "" >> "${PKG_BUILD_DIR}/${packagename}/Resources/$foundLanguage/Localizable.strings" + foundMessageName=""; foundDescription="" + fi + if [[ "$foundObjectName" != "" ]] && [[ "$foundObjectTitle" != "" ]] && [[ "$foundDescription" != "" ]]; then + echo "\"${foundObjectName}_title\" = \"${foundObjectTitle}\";" >> "${PKG_BUILD_DIR}/${packagename}/Resources/$foundLanguage/Localizable.strings" + echo "\"${foundObjectName}_description\" = \"${foundDescription}\";" >> "${PKG_BUILD_DIR}/${packagename}/Resources/$foundLanguage/Localizable.strings" + echo "" >> "${PKG_BUILD_DIR}/${packagename}/Resources/$foundLanguage/Localizable.strings" + foundObjectName=""; foundObjectTitle=""; foundDescription="" + fi fi - if [[ "$foundObjectName" != "" ]] && [[ "$foundObjectTitle" != "" ]] && [[ "$foundDescription" != "" ]]; then - echo "\"${foundObjectName}_title\" = \"${foundObjectTitle}\";" >> "${PKG_BUILD_DIR}/${packagename}/Resources/$foundLanguage/Localizable.strings" - echo "\"${foundObjectName}_description\" = \"${foundDescription}\";" >> "${PKG_BUILD_DIR}/${packagename}/Resources/$foundLanguage/Localizable.strings" - echo "" >> "${PKG_BUILD_DIR}/${packagename}/Resources/$foundLanguage/Localizable.strings" - foundObjectName=""; foundObjectTitle=""; foundDescription="" - fi fi - fi - done < $ResourcesLanguageFile + done < "${PKG_BUILD_DIR}/${ResourcesSourceFile}" + rm "${PKG_BUILD_DIR}/${ResourcesSourceFile}" + else + echo -e "\tError. ${ResourcesLanguageFile} not created." + exit 1 + fi echo -e "\tAdding background.tiff file" ditto --noextattr --noqtn "${ResourcesSourceFolder}/background.tiff" "${PKG_BUILD_DIR}/${packagename}/Resources"