Skip to content

Instantly share code, notes, and snippets.

@msg7086
Last active August 29, 2015 13:56
Show Gist options
  • Save msg7086/9338834 to your computer and use it in GitHub Desktop.
Save msg7086/9338834 to your computer and use it in GitHub Desktop.
To parse python files in ROS project and see how many publishers and subscribers.
#!/bin/bash
IFS='
'
DIR=ros_catkin_ws/src/
SUB=0
PUB=0
SVC=0
SVP=0
ACC=0
ACS=0
shopt -s nocasematch
regex="([0-9a-z/_]+)/([0-9a-z_]+\.py):([0-9]+)"
reg2="\.(Subscriber|Publisher|ServiceProxy|Service|ActionClient|ActionServer)\(([^,]*), *([^)]*)"
lines=$(grep '\.\(Subscriber(\|Publisher(\|ServiceProxy(\|Service(\|ActionClient(\|ActionServer(\)' -nr $DIR --include='*.py' -I)
for line in $lines; do
echo $line
[[ $line =~ $regex ]]
echo "${BASH_REMATCH[1]}"
echo "${BASH_REMATCH[2]}"
echo "${BASH_REMATCH[3]}"
[[ $line =~ $reg2 ]]
echo "${BASH_REMATCH[1]}"
echo "${BASH_REMATCH[2]}"
echo "${BASH_REMATCH[3]}"
if [[ x"${BASH_REMATCH[1]}" == xSubscriber ]]; then
let SUB=SUB+1
fi
if [[ x"${BASH_REMATCH[1]}" == xPublisher ]]; then
let PUB=PUB+1
fi
if [[ x"${BASH_REMATCH[1]}" == xServiceProxy ]]; then
let SVP=SVP+1
fi
if [[ x"${BASH_REMATCH[1]}" == xService ]]; then
let SVC=SVC+1
fi
if [[ x"${BASH_REMATCH[1]}" == xActionClient ]]; then
let ACC=ACC+1
fi
if [[ x"${BASH_REMATCH[1]}" == xActionServer ]]; then
let ACS=ACS+1
fi
done
echo -----
echo Publisher: $PUB
echo Subscriber: $SUB
echo Service: $SVC
echo ServiceProxy: $SVP
echo ActionClient: $ACC
echo ActionServer: $ACS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment