WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: How to find which extension provides a file  (Read 313 times)

Online patrikg

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 710
Re: How to find which extension provides a file
« Reply #15 on: Today at 11:00:08 AM »
Sorry for not getting the performance working with sqlite3 :( ---
Tried to get it working so the command line should report the performance.

I can't getting it working with the ".timer on" with the command line version of sqlite3.
The ".timer on" doesn't report the speed sadly when executing from the command line.

But if you get into the interactive mode of sqlite3 it just works so you get a report how many seconds the question took.

It says in "man" you could supply the -cmd ".timer on" but it doesn't work for me, but some another commands like -cmd ".help" works out of the box.

And if "you" choose sqlite3 you could also store some more metadata like version, date and so on.

Maybe also store ldd output of the executable, so you can easily see the dependency's.

« Last Edit: Today at 11:08:08 AM by patrikg »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11591
Re: How to find which extension provides a file
« Reply #16 on: Today at 12:20:56 PM »
Hi nick65go
... OR, if the speed is not the main goal (but nice for multi-CPU core) then maybe the user confort for seach parameters (GUI options will be nice also). But of course, the pro[fessionals] already know the use of "" and back-quotes, etc.
I think backwards compatibility and user friendly search parameters
should be the primary goals.

I did a rewrite of provides.sh as follows:
1. The default search mode is unchanged.
2. No backslashes to enter. The script adds them if needed.
3. No quoting of search term.
4. End of search term can be marked with an anchor ($).
5. Added a brief usage message.
6. This works for both the command line and the GUI.

Examples:
Search for plain file name:
Code: [Select]
tc@E310:~/Scripting/Provides$ ./provides.sh grep | wc -l
51
tc@E310:~/Scripting/Provides$

Search for file name with leading slash:
Code: [Select]
tc@E310:~/Scripting/Provides$ ./provides.sh /grep
boost-1.65-dev.tcz
boost-dev.tcz
emacs.cedet.tcz
emacs.doc.tcz
emacs.minimal.tcz
emacs.prog.tcz
fpc-src.tcz
fpc.tcz
grep.tcz
kompozer.tcz
libreoffice.tcz
mariadb-test.tcz
python3.6.tcz
tc@E310:~/Scripting/Provides$

Search for file name with partial path:
Code: [Select]
tc@E310:~/Scripting/Provides$ ./provides.sh bin/grep
emacs.minimal.tcz
fpc.tcz
grep.tcz
tc@E310:~/Scripting/Provides$

Search for file name with partial path and trailing anchor:
Code: [Select]
tc@E310:~/Scripting/Provides$ ./provides.sh bin/grep$
grep.tcz
tc@E310:~/Scripting/Provides$

Added help message:
Code: [Select]
tc@E310:~/Scripting/Provides$ ./provides.sh --help

Finds extension(s) that provide a filename.
Filenames in list being searched include full paths, for example:
        usr/local/bin/grep

Usage:
        provides.sh FileName

Examples:
        This also finds all extensions that include local in their pathes.
        provides.sh cal

        This finds *bin/cal*. Including sbin/cal, bin/calibrate, etc.
        provides.sh bin/cal

        This finds *bin/cal. Including sbin/cal, usr/bin/cal, etc.
        provides.sh bin/cal$

The more specific the search, the fewer the results returned.


tc@E310:~/Scripting/Provides$

And the script itself:
Code: [Select]
#!/bin/busybox ash
. /etc/init.d/tc-functions
useBusybox

# --------------------------------------------------------------------------- #
Usage()
{
        echo "
Finds extension(s) that provide a filename.
Filenames in list being searched include full paths, for example:
usr/local/bin/grep

Usage:
        ${0##*/} FileName

Examples:
This also finds all extensions that include local in their pathes.
        ${0##*/} cal

This finds *bin/cal*. Including sbin/cal, bin/calibrate, etc.
        ${0##*/} bin/cal

This finds *bin/cal. Including sbin/cal, usr/bin/cal, etc.
        ${0##*/} bin/cal$

The more specific the search, the fewer the results returned.

"
        exit
}
# --------------------------------------------------------------------------- #



# See if user needs help.
case "$1" in
        -h) Usage;;
        -help) Usage;;
        --help) Usage;;
        "") exit 1;;
esac

# Flag to indicate whether we want an exact match. 0=No  1=Yes.
Exact=0

TARGET="$1"

TCEDIR="/etc/sysconfig/tcedir"
DB="provides.db"

getMirror
cd "$TCEDIR"
if zsync -i "$TCEDIR"/"$DB" -q "$MIRROR"/"$DB".zsync
then
rm -f "$DB".zs-old
else
if [ ! -f "$TCEDIR"/"$DB" ]
then
  wget -O "$TCEDIR"/"$DB".gz "$MIRROR"/"$DB".gz
  gunzip "$TCEDIR"/"$DB".gz
fi
fi
chmod g+rw "$TCEDIR"/"$DB"
cd - > /dev/null

# Save string length of TARGET.
Length=${#TARGET}

# Remove trailing $ (exact match request) if present.
TARGET="${TARGET%$}"

# If TARGET is now shorter, exact match was requested.
[ ${#TARGET} -lt $Length ] && Exact=1

# Replace all instances of / with \/.
TARGET="${TARGET//\//\\\/}"

if [ $Exact -eq 0 ]
then
awk 'BEGIN {FS="\n";RS=""} /'${TARGET}'/{print $1}' "$TCEDIR"/"$DB"
else
awk 'BEGIN {FS="\n";RS=""} /'${TARGET}'\n/||/'${TARGET}'$/{print $1}' "$TCEDIR"/"$DB"
fi

A copy of the script is attached. If you want to try it with the Apps GUI
after downloading it:
Code: [Select]
sudo cp provides.sh /usr/bin
« Last Edit: Today at 12:51:43 PM by Rich »