13 Jul 2007

Xaraya - identify modules

For the past 1-2 years I have been pretty much absent from Xaraya development, although still keeping half an eye on it.

Currently I am working with Xaraya again. I am pleased to see, that the 1.1.x versions have gained much stability.

While getting into it again, I have been fiddeling wirh module initializations and creating a skeleton for a new module. During this task, it would have been helpful to have a tool to find certain modules by id (I had dependecy errors pointing to module ids).

Scripts mentioned below require sh, grep, sed. Tested in a GNU Environment.

The following script can be used to identify xaraya modules by id (returns the module's name):

#!/bin/sh
modid="";
path="modules/";

usage() {
echo "modname [path]";
}

# check for module directory
if [[ $# -lt 2 ]]; then
usage;
exit 1;
fi
modid="$1";

if [[ ! -z "$2" ]]; then
path="$2";
fi

if [[ ! -d "$path" ]]; then
echo "Directory '$path' not found."
echo ""
usage;
exit 2;
fi

res=`grep -H "'id'" $path*/xarversion.php | grep $modid`;

echo "$res" | sed -e 's/\/xarversion.*$//; s/.*\///' -

exit 0;


And if you want to identify a module by name (get id) use this:
#!/bin/sh
modname="";
path="modules/";

usage() {
echo "modid [path]";
}

# check for module directory
if [[ $# -lt 2 ]]; then
usage;
exit 1;
fi
modname="$1";

if [[ ! -z "$2" ]]; then
path="$2";
fi

if [[ ! -d "$path" ]]; then
echo "Directory '$path' not found."
echo ""
usage;
exit 2;
fi

cat $path/$modname/xarversion.php | grep "'id'" | sed -e 's/^[^0-9]*\([0-9]\+\)[^0-9]*/\1/'

exit 0;

No comments: