Page 1 of 1

ROX-Desktop drive icons: show free space in tooltips

Posted: Sat 02 Feb 2013, 22:05
by SFR
Ok, so today I definitively got tired of necessity to launch Pmount (or go to /mnt, terminal or wherever) every time I want to check free space on my drives.
Anyone tired either? :wink: Here's the "cure":

Code: Select all

#!/bin/bash

INFO_PATH=/root/.pup_event

while true; do
  df -h | grep -vE "/dev/loop|tmpfs|unionfs|shmfs|truecrypt" | grep "/mnt" | sed 's|/dev/|drive_|g' | awk '{print $1"| Size: "$2" Free: "$4}' | \
  while read i; do
    NAME="${i%%|*}"
    SIZE="${i##*|}"
    LINE=`grep "<Summary>" "$INFO_PATH/$NAME/AppInfo.xml" 2>/dev/null`
    NEW_LINE="`echo ${LINE%%Size: *}`$SIZE</Summary>"
    if [ "$LINE" != "$NEW_LINE" ] && [ ! "$(pidof snapmergepuppy)" ]; then
      #sed -i 's|'"$LINE"'|'"$NEW_LINE"'|' "$INFO_PATH/$NAME/AppInfo.xml"   
      cat "$INFO_PATH/$NAME/AppInfo.xml" | sed -e 's|'"$LINE"'|'"$NEW_LINE"'|' > /tmp/roxdrvfreespace_temp
      mv -f /tmp/roxdrvfreespace_temp "$INFO_PATH/$NAME/AppInfo.xml"
    fi
  done
  sleep 5
done
This short script updates periodically (5 sec.) tooltips for ROX drive icons, by adding current amount of available space.
I used 'dh -h' which rounds up the size, but it's sufficient to get overall insight.
That's it. Barely tested (only in Slacko-5.4), but so far works fine with internal and external (USB) drives. YMMV, of course.

BTW, if a drive will be unmounted, the tooltip won't be updated anymore (until mounted again) and its recent "Free: ..." value remains there.
This may be considered as a downside, but I don't mind that it's that way (and the code is much more simple).

If one try it and think "nah, I don't like it":
1. Kill the script
2. Delete everything from /root/.pup_event/ dir
3. Restart X

_________

WARNING: I have noticed that if I copy/paste the code using Opera browser, it (Opera) has unpleasant habit of adding leading and trailing spaces to pasted text.
So if it will happen, make sure that this line:
df -h | grep -vE "/dev/loop|tmpfs|unionfs|shmfs" | grep "/mnt" | sed 's|/dev/|drive_|g' | awk '{print $1"| Size: "$2" Free: "$4}' | \
doesn't contain any extra space after \ or else script won't work.

Enjoy & Greetings!

Posted: Sat 02 Feb 2013, 22:40
by vovchik
Dear SFR,

What a nice, useful and simple idea. It workes nicely under Lucid, too.

Thanks.

With kind regards,
vovchik

Posted: Sun 03 Feb 2013, 09:02
by rhadon
Hi SFR,

tried your program, but no success :cry: . I also use Slacko 5.4, with and without save file.
I allways get:

Code: Select all

sed: -e expression #1, char 54: unknown option to `s'
added echo's to see the variables, so I think, it's the last sed command:

Code: Select all

# ./freespace
NAME=drive_sda5
SIZE= Size: 14G Free: 583M
LINE= <Summary>Filesystem: ext3 Size: 13,9GB</Summary>
NEW_LINE=<Summary>Filesystem: ext3 Size: 14G Free: 583M</Summary>
sed: -e expression #1, char 54: unknown option to `s'
Any idea?

Rolf

Posted: Sun 03 Feb 2013, 10:09
by SFR
Thanks for the info, Vovchik!

Rhadon, yes! I think I see what went wrong.
It's decimal comma separator in "13,9GB" and I also used comma as a separator in the second 'sed' (I have left my "Country Settings" default - English, i.e. dot as separator).

Ok, I corrected the code, how about now?

Thanks for spotting this, btw.
PS. Rolf, maybe this is also the reason why <spinbutton> doesn't work for you when floating point values are in use..?

Greetings!

Posted: Sun 03 Feb 2013, 10:42
by rhadon
Great! It works fine now. :D
And it's much more comfortable than using pmount or partview.

Thanks for sharing,

Rolf

Will test spinbuttons with english country settings soon :wink: .

Edit: Yes. Again, your'e right. Spinbutton and bdraw 1.6 are working fine with english country settings. :roll:

Posted: Wed 20 Nov 2013, 21:08
by carenrose
This is really cool! Thank you :D

I never really used the tooltips because I already know the overall size of whatever disk/drive I have, so it wasn't much useful to me before.

Posted: Wed 20 Nov 2013, 22:31
by SFR
Hey Carenrose

Thanks for reminding me about this lil' app - I was going to update it a bit.
Three changes:
1. 'truecrypt' added to items that are screened out from 'df -h' results.
2. Direct 'sed -i' replaced with 'cat ... | sed -e ...' + 'mv -f ...'
3. Updating is suspended during saving the session.

First post updated.

Greetings!

Posted: Wed 20 Nov 2013, 23:41
by Karl Godt
Cowardly refusing to sed -i ..
Missing [ $? = 0 ] && mv file file-new , then .

[/dev/|/mnt/TYPE] truecrypt where did you got that one ..?
Do you mean lvmcrypt ? Low-Level Virtual Machine (LLVM) v2, v3 ..

Otherwise was playing with it just to display it into console without sed 'ing any files .

Nice !

Posted: Thu 21 Nov 2013, 11:20
by SFR
Hey Karl
Missing [ $? = 0 ] && mv file file-new , then .
You mean after 'cat ... | sed ...' ?
Sounds good, unfortunately it seems that sed returns 0 even if there's no stuff to process. :?

Code: Select all

# cat blahblah; echo $?
cat: blahblah: No such file or directory
1
# 
# cat blahblah | sed 's|abc|def|'; echo $?
cat: blahblah: No such file or directory
0
#
[/dev/|/mnt/TYPE] truecrypt where did you got that one ..?
Do you mean lvmcrypt ? Low-Level Virtual Machine (LLVM) v2, v3 ..
Just TrueCrypt:

Code: Select all

## without the use of kernel cryptographic services it's a loop device:
# df -h | grep truecrypt
/dev/loop2      334G  319G   16G  96% /mnt/truecrypt1
# 
## but _with_ kernel services it's:
# df -h | grep truecrypt
/dev/mapper/truecrypt1  334G  319G   16G  96% /mnt/truecrypt1
#
Hmm, maybe I should exclude the whole /dev/mapper instead..? The new pup_event doesn't seem to handle it at all, anyway...
BTW, should I exclude some more items or the 'grep "/mnt"' is sufficient precaution..?

Anyway, a bit more polished version:

Code: Select all

#!/bin/bash

# ROX_DrivesFreeSpace v0.3

INFO_PATH=/root/.pup_event

while true; do
  df -h | grep -vE "^/dev/loop|^tmpfs|^unionfs|^shmfs|^/dev/mapper" | grep "/mnt" | awk 'sub("/dev/","drive_",$1) {print $1"| Size: "$2" Free: "$4}' | \
  while read i; do
    NAME="${i%%|*}"
    SIZE="${i##*|}"
    if [ -f "${INFO_PATH}/${NAME}/AppInfo.xml" ]; then
      OLD_LINE=`grep "<Summary>" "${INFO_PATH}/${NAME}/AppInfo.xml"`
      NEW_LINE="`echo ${OLD_LINE%%Size: *}`$SIZE</Summary>"
      if [ "$OLD_LINE" != "$NEW_LINE" ] && [ ! "`pidof snapmergepuppy`" ]; then
        #sed -i 's|'"$OLD_LINE"'|'"$NEW_LINE"'|' "${INFO_PATH}/${NAME}/AppInfo.xml"   
        cat "${INFO_PATH}/${NAME}/AppInfo.xml" | sed 's|'"$OLD_LINE"'|'"$NEW_LINE"'|' > /tmp/roxdrvfreespace_temp
        mv -f /tmp/roxdrvfreespace_temp "${INFO_PATH}/${NAME}/AppInfo.xml"
      fi
    fi
  done
  sleep 5
done
Thanks &
Greetings!

Posted: Thu 21 Nov 2013, 11:35
by 01micko
Looks like a nice option, but maybe not as default.

Scenario: Have the script lurking in /usr/bin (or wherever, even in $HOME) chmod -x then as an option to the right clicks for the drive icons "enable free space bubble" (or whatever), upon click we have chmod +x, then change the option to "disable bubble" in the right click menu then point that at chmod -x.

Just a random thought :)

Posted: Thu 21 Nov 2013, 13:20
by mikeb
gtk tooltips come in handy...one short df did the trick here.
http://www.murga-linux.com/puppy/viewto ... 381#729381
Those binary icons
http://www.murga-linux.com/puppy/viewtopic.php?t=78881
just lack such info... one to play with.

mike

Posted: Thu 21 Nov 2013, 17:09
by SFR
01micko wrote:Looks like a nice option, but maybe not as default.

Scenario: Have the script lurking in /usr/bin (or wherever, even in $HOME) chmod -x then as an option to the right clicks for the drive icons "enable free space bubble" (or whatever), upon click we have chmod +x, then change the option to "disable bubble" in the right click menu then point that at chmod -x.

Just a random thought :)
Yeah, that would be neat, but of course it'd involve some modifications of the pup_event scripts (/usr/local/pup_event/frontend_func & /usr/local/bin/drive_all, I guess).
BTW, I personally am still using the old, "all-in-one" pup_event_frontend_d, because the new version won't refresh desktop drives' icons after creating/deleting partitions in GParted. :(
mikeb wrote:gtk tooltips come in handy...one short df did the trick here.
http://www.murga-linux.com/puppy/viewto ... 381#729381
Looks pretty cool!
___________

In the meantime, a little more optimized version (2 lines + 2 pipes + 1 cat less):

Code: Select all

#!/bin/bash

# ROX_DrivesFreeSpace v0.4

INFO_PATH=/root/.pup_event

while true; do
  df -h | awk '!/^Filesystem|^\/dev\/loop|^\/dev\/mapper\/|^tmpfs|^shmfs|^unionfs/, sub("/dev/","drive_",$1) {print $1" Size: "$2" Free: "$4}' | while read NAME SIZE; do
    if [ -f "${INFO_PATH}/${NAME}/AppInfo.xml" ]; then
      OLD_LINE=`grep "<Summary>" "${INFO_PATH}/${NAME}/AppInfo.xml"`
      NEW_LINE="${OLD_LINE%Size: *}$SIZE</Summary>"
      if [ "$OLD_LINE" != "$NEW_LINE" ] && [ ! "`pidof snapmergepuppy`" ]; then
        #sed -i 's|'"$OLD_LINE"'|'"$NEW_LINE"'|' "${INFO_PATH}/${NAME}/AppInfo.xml"   
        sed 's|'"$OLD_LINE"'|'"$NEW_LINE"'|' "${INFO_PATH}/${NAME}/AppInfo.xml" > /tmp/roxdrvfreespace_temp
        [ $? -eq 0 ] && mv -f /tmp/roxdrvfreespace_temp "${INFO_PATH}/${NAME}/AppInfo.xml"
      fi
    fi
  done
  sleep 5
done
Oh, in case anyone's curious why I've resigned from using 'sed -i ...' - well, I had suspicions that on some very rare occasions the direct 'sed -i' may cause that one or more processes go into D state (uninterruptible sleep) for good.
So far no more D processes since I've changed that a couple of months ago, so probably that was it...


EDIT: I merged 'while read...' line with the previous line to prevent the script from failure if additional space has been added after \, what may happen during copy/paste operation.

Greetings!

Posted: Thu 21 Nov 2013, 18:41
by amigo
#!/bin/bash
....
sleep 5

The only problem is that this polling process is pretty expensive running all the time. There are much cleaner ways to accomplish this with traditional tools like cron or even from a udev rule.

Posted: Thu 21 Nov 2013, 19:03
by SFR
Hey Amigo

I've never played with cron, but it seems that min. interval is 1 minute:
http://askubuntu.com/questions/800/how- ... using-cron
As for udev (never played as well), how could such a rule look like?
I suppose it'd be possible to call the script on device mounting, but what when free space changes..?

Greetings!

Posted: Sat 07 Dec 2013, 21:30
by sunburnt
What`s the chances of this ( and sooo many other items...) getting into mainstream Puppy.?

So many improvements come and go here that it`s impossible to keep track of them all.

Also... amigo, I`ve suspected timed polling processes and thought there must be a better way.

Posted: Sun 08 Dec 2013, 07:18
by amigo
As far as getting free-space info into the tooltips for the icon, I don't think there is another way -unless one patched the filer itself to show such info for mount points.
Personally, I just use gtkdiskfree. It has a dynamic display, which means that it is also polling, but less expensively than a bash script would be.

The problem with using the tooltips is that the AppInfo.xml must be re-written every cycle and could be corrupted while doing so. I think a right-click action (to launch some indicator) would be a better solution.

Polling should be avoided like the plague.

i use gtkdiskfree too with my Toutou Wolx 2014

Posted: Sat 14 May 2016, 06:15
by Pelo
i use gtkdiskfree too with my Toutou Wolx 2014

Posted: Sat 14 May 2016, 06:53
by sunburnt
Amigo is correct as always. Avoid polling!
Sadly there is no common way to trigger other code like this.
Perhaps an inet type damon that polls /sys and /proc for triggers,
then reads a list of apps, etc. to activate or write to.

Posted: Sat 14 May 2016, 09:41
by musher0
If you're a bit of a masochist, would the info given by partview make you happy? :roll:

Posted: Sat 14 May 2016, 11:48
by LazY Puppy
In my T.O.P.L.E.S.S. LazY Puppy 5 Systems I had made patches of

- /usr/local/bin/drive_all
- /usr/local/pup_event/frontend_funcs

It is to enable/disable by the config files and has option to refresh/update manually by right-clicking the drive icon - besides some more options not yet in standard Puppy.

Works in all of my T.O.P.L.E.S.S. LazY Puppy Systems (tahr, unicorn, vivid, xenial, slacko - 32bit/64bit all WoofCE).

See attached images.