Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Fri 18 Apr 2014, 21:48
All times are UTC - 4
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Desktop
ROX-Desktop drive icons: show free space in tooltips
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 2 [16 Posts]   Goto page: 1, 2 Next
Author Message
SFR


Joined: 26 Oct 2011
Posts: 879

PostPosted: Sat 02 Feb 2013, 18:05    Post subject:  ROX-Desktop drive icons: show free space in tooltips  

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:
#!/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!
screenshot.png
 Description   
 Filesize   25.64 KB
 Viewed   904 Time(s)

screenshot.png


_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.

Last edited by SFR on Wed 20 Nov 2013, 18:30; edited 3 times in total
Back to top
View user's profile Send private message 
vovchik


Joined: 23 Oct 2006
Posts: 1285
Location: Ukraine

PostPosted: Sat 02 Feb 2013, 18:40    Post subject:  

Dear SFR,

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

Thanks.

With kind regards,
vovchik
Back to top
View user's profile Send private message 
rhadon


Joined: 27 Mar 2008
Posts: 1291
Location: Germany

PostPosted: Sun 03 Feb 2013, 05:02    Post subject:  

Hi SFR,

tried your program, but no success Crying or Very sad . I also use Slacko 5.4, with and without save file.
I allways get:
Code:
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:
# ./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

_________________
Ich verwende "frugal", und das ist gut so. Wink
Raspberry Pi without Puppy? No, thanks.
Back to top
View user's profile Send private message 
SFR


Joined: 26 Oct 2011
Posts: 879

PostPosted: Sun 03 Feb 2013, 06:09    Post subject:  

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!

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send private message 
rhadon


Joined: 27 Mar 2008
Posts: 1291
Location: Germany

PostPosted: Sun 03 Feb 2013, 06:42    Post subject:  

Great! It works fine now. Very Happy
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. Rolling Eyes

_________________
Ich verwende "frugal", und das ist gut so. Wink
Raspberry Pi without Puppy? No, thanks.
Back to top
View user's profile Send private message 
carenrose

Joined: 10 Dec 2012
Posts: 28

PostPosted: Wed 20 Nov 2013, 17:08    Post subject:  

This is really cool! Thank you Very Happy

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.
Back to top
View user's profile Send private message 
SFR


Joined: 26 Oct 2011
Posts: 879

PostPosted: Wed 20 Nov 2013, 18:31    Post subject:  

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!

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send private message 
Karl Godt


Joined: 20 Jun 2010
Posts: 3860
Location: Kiel,Germany

PostPosted: Wed 20 Nov 2013, 19:41    Post subject:  

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 !
Back to top
View user's profile Send private message Visit poster's website 
SFR


Joined: 26 Oct 2011
Posts: 879

PostPosted: Thu 21 Nov 2013, 07:20    Post subject:  

Hey Karl
Quote:
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. Confused
Code:
# 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
#

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

Just TrueCrypt:
Code:
## 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:
#!/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!

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send private message 
01micko


Joined: 11 Oct 2008
Posts: 7547
Location: qld

PostPosted: Thu 21 Nov 2013, 07:35    Post subject:  

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 Smile

_________________
Woof Mailing List | keep the faith Cool |
Back to top
View user's profile Send private message Visit poster's website 
mikeb


Joined: 23 Nov 2006
Posts: 7179

PostPosted: Thu 21 Nov 2013, 09:20    Post subject:  

gtk tooltips come in handy...one short df did the trick here.
http://www.murga-linux.com/puppy/viewtopic.php?p=729381#729381
Those binary icons
http://www.murga-linux.com/puppy/viewtopic.php?t=78881
just lack such info... one to play with.

mike
Back to top
View user's profile Send private message 
SFR


Joined: 26 Oct 2011
Posts: 879

PostPosted: Thu 21 Nov 2013, 13:09    Post subject:  

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 Smile

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. Sad
mikeb wrote:
gtk tooltips come in handy...one short df did the trick here.
http://www.murga-linux.com/puppy/viewtopic.php?p=729381#729381

Looks pretty cool!
___________

In the meantime, a little more optimized version (2 lines + 2 pipes + 1 cat less):
Code:
#!/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!

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.

Last edited by SFR on Thu 21 Nov 2013, 14:50; edited 1 time in total
Back to top
View user's profile Send private message 
amigo

Joined: 02 Apr 2007
Posts: 2167

PostPosted: Thu 21 Nov 2013, 14:41    Post subject:  

#!/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.
Back to top
View user's profile Send private message 
SFR


Joined: 26 Oct 2011
Posts: 879

PostPosted: Thu 21 Nov 2013, 15:03    Post subject:  

Hey Amigo

I've never played with cron, but it seems that min. interval is 1 minute:
http://askubuntu.com/questions/800/how-to-run-scripts-every-5-seconds-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!

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 4981
Location: Arizona, U.S.A.

PostPosted: Sat 07 Dec 2013, 17:30    Post subject:  

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.
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 2 [16 Posts]   Goto page: 1, 2 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Desktop
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0898s ][ Queries: 12 (0.0052s) ][ GZIP on ]