mirror of
https://github.com/mavlink/mavlink.git
synced 2026-06-19 07:35:34 +00:00
Add xmllint check to travis.
This commit is contained in:
Executable
+45
@@ -0,0 +1,45 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# A POSIX variable
|
||||
OPTIND=1 # Reset in case getopts has been used previously in the shell.
|
||||
|
||||
# Initialize variables
|
||||
mode="format"
|
||||
|
||||
while getopts "h?c" opt; do
|
||||
case "$opt" in
|
||||
h|\?)
|
||||
show_help
|
||||
exit 0
|
||||
;;
|
||||
c) mode="check"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
xml_files=`find . -name *.xml`
|
||||
ret=0
|
||||
for f in $xml_files
|
||||
do
|
||||
xmllint -format ${f} > ${f}.new
|
||||
case "$mode" in
|
||||
format)
|
||||
if ! cmp ${f} ${f}.new >/dev/null 2>&1
|
||||
then
|
||||
echo "formatting $f"
|
||||
cp ${f}.new ${f}
|
||||
fi
|
||||
;;
|
||||
check)
|
||||
if ! cmp ${f} ${f}.new >/dev/null 2>&1
|
||||
then
|
||||
echo "$f needs formatting"
|
||||
ret=1
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
rm ${f}.new
|
||||
done
|
||||
|
||||
exit $ret
|
||||
Executable
+76
@@ -0,0 +1,76 @@
|
||||
set -e
|
||||
|
||||
SRC_DIR=`pwd`
|
||||
|
||||
git submodule update --init --recursive
|
||||
|
||||
# NOTE: we must do all testing on the installed python package, not
|
||||
# on the build tree. Otherwise the testing is invalid and may not
|
||||
# indicate the code actually works
|
||||
|
||||
# check format
|
||||
sep="##############################################"
|
||||
echo $sep
|
||||
echo "FORMAT TEST"
|
||||
echo $sep
|
||||
cd $SRC_DIR
|
||||
./scripts/format_xml.sh -c
|
||||
echo PASS
|
||||
|
||||
# install
|
||||
echo $sep
|
||||
echo "PYMAVLINK INSTALL"
|
||||
echo $sep
|
||||
cd $SRC_DIR
|
||||
|
||||
user_arg="--user"
|
||||
if [ "$TRAVIS" == true ]
|
||||
then
|
||||
user_arg=""
|
||||
fi
|
||||
pip install $user_arg -r pymavlink/requirements.txt
|
||||
cd $SRC_DIR/pymavlink
|
||||
python setup.py build install $user_arg
|
||||
|
||||
msg_def="message_definitions/v1.0/common.xml"
|
||||
|
||||
cd $SRC_DIR
|
||||
for wire_protocol in 1.0 2.0
|
||||
do
|
||||
for lang in Python C CS WLua Java
|
||||
do
|
||||
echo $sep
|
||||
echo "GENERATING MAVLINK " \
|
||||
"protocol:${wire_protocol} language:${lang}"
|
||||
echo $sep
|
||||
outdir="/tmp/mavlink_${wire_protocol}_${lang}"
|
||||
mavgen.py --lang=${lang} \
|
||||
--wire-protocol ${wire_protocol} \
|
||||
--output=${outdir} ${msg_def}
|
||||
echo PASS
|
||||
done
|
||||
done
|
||||
|
||||
# Avoid `spurious errors` caused by ~/.npm permission issues
|
||||
# ref: https://github.com/travis-ci/travis-ci/issues/2244
|
||||
# ref: https://github.com/npm/npm/issues/4815
|
||||
# Does it already exist? Who owns? What permissions?
|
||||
ls -lah ~/.npm || mkdir ~/.npm
|
||||
# Make sure we own it
|
||||
# $USER references the current user in Travis env
|
||||
chown -R $USER ~/.npm
|
||||
if [ -f /usr/bin/nodejs ]
|
||||
then
|
||||
mkdir -p ~/bin
|
||||
ln -sf /usr/bin/nodejs ~/bin/node
|
||||
. ~/.bashrc
|
||||
fi
|
||||
cd $SRC_DIR/pymavlink/generator/javascript && npm test
|
||||
|
||||
# Test quaternions
|
||||
echo $sep
|
||||
echo "QUATERNION TEST"
|
||||
echo $sep
|
||||
cd $SRC_DIR
|
||||
pymavlink/tools/quaterniontest.py
|
||||
echo PASS
|
||||
@@ -1,88 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
import xml.dom.minidom as minidom
|
||||
from sys import exit, argv, stderr, stdout
|
||||
import re
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser(description="Format XML")
|
||||
parser.add_argument('infile', nargs=1)
|
||||
parser.add_argument('outfile', nargs='?')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
f = open(args.infile[0],'r')
|
||||
text = f.read()
|
||||
f.close()
|
||||
|
||||
dom = minidom.parseString(text)
|
||||
|
||||
def contains_only_text(node):
|
||||
childNodes = node.childNodes[:]
|
||||
for child in childNodes:
|
||||
if child.nodeType != child.TEXT_NODE:
|
||||
return False
|
||||
return True
|
||||
|
||||
def foreach_tree(doc, root, func, level=0):
|
||||
func(doc, root, level)
|
||||
|
||||
childNodes = root.childNodes[:]
|
||||
for node in childNodes:
|
||||
foreach_tree(doc, node, func, level+1)
|
||||
|
||||
def strip_indent(doc, node, level):
|
||||
if node.nodeType == node.TEXT_NODE and re.match(r"^\s+$", node.nodeValue):
|
||||
node.parentNode.removeChild(node)
|
||||
node.unlink()
|
||||
|
||||
def strip_comment_whitespace(doc, node, level):
|
||||
if node.nodeType == node.COMMENT_NODE:
|
||||
node.nodeValue = re.sub(r"\s+", " ", node.nodeValue)
|
||||
|
||||
def strip_comments_completely(doc, node, level):
|
||||
if node.nodeType == node.COMMENT_NODE:
|
||||
node.parentNode.removeChild(node)
|
||||
node.unlink()
|
||||
|
||||
def strip_text_whitespace(doc, node, level):
|
||||
if node.nodeType == node.TEXT_NODE:
|
||||
node.nodeValue = re.sub(r"\s+", " ", node.nodeValue).strip()
|
||||
|
||||
def strip_text_completely(doc, node, level):
|
||||
if node.nodeType == node.TEXT_NODE:
|
||||
node.parentNode.removeChild(node)
|
||||
node.unlink()
|
||||
|
||||
def auto_indent(doc, node, level):
|
||||
if level > 0 and not contains_only_text(node.parentNode):
|
||||
node.parentNode.insertBefore(doc.createTextNode("\n%s" % (" "*4*level)), node)
|
||||
if node.nextSibling is None:
|
||||
node.parentNode.appendChild(doc.createTextNode("\n%s" % (" "*4*(level-1))))
|
||||
|
||||
def next_non_text_sibling(node):
|
||||
ret = node.nextSibling
|
||||
while ret is not None and ret.nodeType == node.TEXT_NODE:
|
||||
ret = ret.nextSibling
|
||||
return ret
|
||||
|
||||
def auto_space(doc, node, level):
|
||||
if level > 0 and node.childNodes is not None and len(node.childNodes) > 1 and next_non_text_sibling(node) is not None:
|
||||
node.parentNode.insertBefore(doc.createTextNode("\n"), node.nextSibling)
|
||||
|
||||
foreach_tree(dom, dom.documentElement, strip_indent)
|
||||
foreach_tree(dom, dom.documentElement, strip_comment_whitespace)
|
||||
foreach_tree(dom, dom.documentElement, strip_text_whitespace)
|
||||
foreach_tree(dom, dom.documentElement, auto_indent)
|
||||
foreach_tree(dom, dom.documentElement, auto_space)
|
||||
|
||||
if args.outfile is not None:
|
||||
f = open(args.outfile, 'w')
|
||||
f.truncate()
|
||||
else:
|
||||
f = stdout
|
||||
|
||||
f.write("<?xml version='1.0'?>\n")
|
||||
f.write(dom.documentElement.toxml())
|
||||
f.write("\n")
|
||||
|
||||
f.close()
|
||||
Reference in New Issue
Block a user