Camera2: Update generate scripts check for dependencies and to support MacPorts
Change-Id: Ice9b658f8e6f87a1a490c367bff2f9a685ddee44
diff --git a/camera/docs/README.md b/camera/docs/README.md
index b3cf0ce..3cdae4d 100644
--- a/camera/docs/README.md
+++ b/camera/docs/README.md
@@ -6,8 +6,21 @@
Many files can be generated from XML, such as the documentation (html/pdf),
C code, Java code, and even XML itself (as a sanity check).
-## Dependencies:
-sudo apt-get install python-mako # mako templates. needed to do file generation
-sudo apt-get install python-bs4 # beautiful soup. needed to parse the xml
-sudo apt-get install tidy # tidy, used to clean up xml/html
-sudo apt-get install xmllint # xmllint, used to validate XML against XSD
+## Dependencies
+* Python 2.7.x+
+* Beautiful Soup 4+ - HTML/XML parser, used to parse metadata_properties.xml
+* Mako 0.7+ - Template engine, needed to do file generation
+* Tidy - Cleans up the XML/HTML files.
+* XML Lint - Validates XML against XSD schema
+
+## Quick Setup (Ubuntu Precise):
+sudo apt-get install python-mako
+sudo apt-get install python-bs4
+sudo apt-get install tidy
+sudo apt-get install libxml2-utils #xmllint
+
+## Quick Setup (MacPorts)
+sudo port install py27-beautifulsoup4
+sudo port install py27-mako
+sudo port install tidy
+sudo port install libxml2 #xmllint
diff --git a/camera/docs/metadata-check-dependencies b/camera/docs/metadata-check-dependencies
new file mode 100755
index 0000000..d4f768a
--- /dev/null
+++ b/camera/docs/metadata-check-dependencies
@@ -0,0 +1,114 @@
+#!/bin/bash
+
+#
+# Copyright (C) 2012 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+packager=""
+retcode=0
+if [[ "$OSTYPE" == "darwin"* ]]
+then
+ packager="macports"
+
+ if ! which port >& /dev/null
+ then
+ echo "Missing port binary, please install from http://www.macports.org/" >& 2
+ fi
+elif [[ "$OSTYPE" == "linux-gnu" ]] && which apt-get >& /dev/null
+then
+ packager="apt-get"
+fi
+
+function packager_install
+{
+ if [[ $packager == "macports" ]]
+ then
+ echo "sudo port install $1"
+ elif [[ $packager == "apt-get" ]]
+ then
+ echo "sudo apt-get install $1"
+ else
+ echo "<your package manager> install $1"
+ fi
+}
+
+function binary_check()
+{
+ local bin=$1
+ local macports=$2
+ local aptget=$3
+
+ local pkg=""
+
+ if type -f "$bin" >& /dev/null
+ then
+ return 0
+ fi
+
+ if [[ $packager == "macports" ]]
+ then
+ pkg="$macports"
+ elif [[ $packager == "apt-get" ]]
+ then
+ pkg="$aptget"
+ fi
+
+ if [[ -n $pkg ]]
+ then
+ echo "Missing $bin binary please install with '$(packager_install $pkg)'"
+ fi
+
+ retcode=1
+ return 1
+}
+
+function python_check()
+{
+ local mod=$1
+ local macports=$2
+ local aptget=$3
+
+ local pkg=""
+
+ if python -c "import $mod" >& /dev/null
+ then
+ return 0
+ fi
+
+ if [[ $packager == "macports" ]]
+ then
+ pkg="$macports"
+ elif [[ $packager == "apt-get" ]]
+ then
+ pkg="$aptget"
+ fi
+
+ if [[ -n $pkg ]]
+ then
+ echo "Missing python module $mod, please install with '$(packager_install $pkg)'"
+ fi
+
+ retcode=1
+ return 1
+}
+
+binary_check xmllint libxml2 libxml2-utils
+binary_check tidy tidy tidy
+binary_check python python27 python2.7
+python_check bs4 py27-beautifulsoup4 python-bs4
+python_check mako py27-mako python-mako
+
+exit $retcode
+
diff --git a/camera/docs/metadata-generate b/camera/docs/metadata-generate
index bf3e3ee..a9e53d8 100755
--- a/camera/docs/metadata-generate
+++ b/camera/docs/metadata-generate
@@ -29,10 +29,11 @@
local in=$thisdir/$1
local out=$thisdir/$2
- $thisdir/metadata_parser_xml.py $thisdir/metadata_properties.xml $in > $out
+ python $thisdir/metadata_parser_xml.py $thisdir/metadata_properties.xml $in > $out
return $?
}
+$thisdir/metadata-check-dependencies || exit 1
$thisdir/metadata-parser-sanity-check || exit 1
gen_file html.mako docs.html || exit 1
gen_file camera_metadata_tag_info.mako ../src/camera_metadata_tag_info.c || exit 1
diff --git a/camera/docs/metadata-parser-sanity-check b/camera/docs/metadata-parser-sanity-check
index 940300c..a7ff41e 100755
--- a/camera/docs/metadata-parser-sanity-check
+++ b/camera/docs/metadata-parser-sanity-check
@@ -21,20 +21,15 @@
# as the original parsed data.
#
-tidy=$(which tidy)
-if [[ $? -ne 0 ]]
-then
- echo "Missing tidy binary, please install with 'sudo apt-get install tidy'" 1>&2
- exit 1
-fi
-
thisdir=$(dirname $(readlink -f $0))
+$thisdir/metadata-check-dependencies || exit 1
+
tmp_out=$(mktemp)
tmp_tidy1=$(mktemp)
tmp_tidy2=$(mktemp)
-$thisdir/metadata_parser_xml.py $thisdir/metadata_properties.xml $thisdir/metadata_template.mako > $tmp_out || exit 1
+python $thisdir/metadata_parser_xml.py $thisdir/metadata_properties.xml $thisdir/metadata_template.mako > $tmp_out || exit 1
tidy -indent -xml -quiet $thisdir/metadata_properties.xml > $tmp_tidy1
tidy -indent -xml -quiet $tmp_out > $tmp_tidy2
diff --git a/camera/docs/metadata-validate b/camera/docs/metadata-validate
index fe0266b..20ad9e6 100755
--- a/camera/docs/metadata-validate
+++ b/camera/docs/metadata-validate
@@ -16,12 +16,8 @@
# limitations under the License.
#
-xmllint=$(which xmllint)
-if [[ $? -ne 0 ]]
-then
- echo "Missing xmllint binary, please install with 'sudo apt-get install libxml2-utils'" 1>&2
- exit 1
-fi
+thisdir=$(dirname $(readlink -f $0))
+$thisdir/metadata-check-dependencies || exit 1
if [[ $# -lt 1 ]]
then
@@ -29,11 +25,9 @@
exit
fi
-thisdir=$(dirname $(readlink -f $0))
-
schema=$thisdir/metadata_properties.xsd
doc=$1
xmllint --noout --schema $schema $out $doc || exit 1
-$thisdir/metadata_validate.py $doc || exit 1
+python $thisdir/metadata_validate.py $doc || exit 1