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 Tue 21 Nov 2017, 10:07
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
How to put a progress bar in dir2sfs? (Solved)
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 3 [33 Posts]   Goto page: 1, 2, 3 Next
Author Message
rg66


Joined: 23 Jul 2012
Posts: 1127
Location: Vancouver, BC Canada / Entebbe, Uganda Africa!?!

PostPosted: Fri 29 Sep 2017, 23:30    Post subject:  How to put a progress bar in dir2sfs? (Solved)
Subject description: For late-model Puppies.
 

Hi all,

I'm trying to get dir2sfs to have a working progress bar. I think it was Jemimah who originally added some code to the script but that doesn't seem to work too well with current puppies, it only captures % a few times. Any help would be much appreciated.

Old code:
Code:
mksquashfs "$t" "$z.sfs" |while read -n 50 LINE ; do
echo $LINE |egrep '[0-9]\%'| cut -f1 -d% |awk '{print $NF}'|grep -v '\.' ;done | \
Xdialog --title "Building Squashfile " --gauge "Building Squashfile. Please Wait..." 0 0
Back to top
View user's profile Send private message 
sc0ttman


Joined: 16 Sep 2009
Posts: 2548
Location: UK

PostPosted: Sat 30 Sep 2017, 13:38    Post subject:  

Hi mate, sorry I can't be more helpful than this, but IIRC (it was about 4 years ago), one of the Woofy versions I did (not latest) had SFS progress bars, but it actually slowed down the speed of making the SFS, so I removed it..

But it should be in *one* of the woofy versions I did...

Sorry - I know that i more a chore/errand than actual help...

_________________
Akita Linux, VLC-GTK, Pup Search, Pup File Search
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 2588
Location: holland

PostPosted: Sat 30 Sep 2017, 14:07    Post subject:  

Hi rg66

When I do e.g:
Code:
mksquashfs "squashfs-root" "new.sfs" > file

Or:
Code:
mksquashfs "squashfs-root" "new.sfs" | tee file

There are only a few (progress) lines in "file"
I think that explains why you get so little change of % from Xdialog
So I'm afraid it's just not possible to capture mksquashfs output in % by % precisely. Hope I'm wrong, though, I'd like Xdialog progress to work also.

Fred

Last edited by fredx181 on Sun 01 Oct 2017, 06:18; edited 1 time in total
Back to top
View user's profile Send private message 
musher0


Joined: 04 Jan 2009
Posts: 11167
Location: Gatineau (Qc), Canada

PostPosted: Sat 30 Sep 2017, 21:00    Post subject:  

Guys?

mksquasfs has a progress bar by default.
Please see attached.

BFN.
mksquashfs-progress-bar.jpg
 Description   By default
 Filesize   27.05 KB
 Viewed   300 Time(s)

mksquashfs-progress-bar.jpg


_________________
musher0
~~~~~~~~~~
"Logical entities must not be multiplied beyond necessity." | |
« Il ne faut pas multiplier les entités logiques sans nécessité. » (Ockham)
Back to top
View user's profile Send private message 
rufwoof

Joined: 24 Feb 2014
Posts: 2163

PostPosted: Sat 30 Sep 2017, 22:30    Post subject:  

Remember that mksquashfs will use multiple cores if available/specified so its buffering is 'unusual'. By running it through script (a old command so commonly available) and line buffering grep will help, something like ....
Code:
#!/bin/bash
script -q -c "mksquashfs /home /tmp/test.sfs -info -progress -noappend \
-processors 4" | \
grep --line-buffered '\[' | \
grep --line-buffered '\]' | \
grep --line-buffered '\%' | \
sed -u 's/.*\(....\)/\1/'

For large sized mksquashfs however, it will stick on 0% for quite a while and will tend to jump quickly towards the end, perhaps going from 49% to 99% in a quick jump despite having taken a while to get from 0% to 1%. That's all part of compression (takes a while to deduce the codebits that will be used to represent character sequences, but once those codebits are in place can encode quickly).

PS that last sed command just prints out the last 4 (count the dots) characters of a line (again using no buffering (-u parameter)).
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 2588
Location: holland

PostPosted: Sun 01 Oct 2017, 06:15    Post subject:  

Thanks rufwoof,

Using the 'script' command makes it work nicely, so modified code from first post:
Code:
script -q -c "mksquashfs "$t" "$z.sfs"" |while read -n 99 LINE ; do
echo $LINE |egrep '[0-9]\%'| cut -f1 -d% |awk '{print $NF}'|grep -v '\.' ;done | \
Xdialog --title "Building Squashfile " --gauge "Building Squashfile. Please Wait..." 0 0

@musher0
Quote:
mksquasfs has a progress bar by default.

Yes, but only from terminal, it's nice to be able to use Xdialog gui progress bar also.

Fred
Back to top
View user's profile Send private message 
rg66


Joined: 23 Jul 2012
Posts: 1127
Location: Vancouver, BC Canada / Entebbe, Uganda Africa!?!

PostPosted: Sun 01 Oct 2017, 07:40    Post subject:  

fredx181 wrote:
Thanks rufwoof,

Using the 'script' command makes it work nicely, so modified code from first post:
Code:
script -q -c "mksquashfs "$t" "$z.sfs"" |while read -n 99 LINE ; do
echo $LINE |egrep '[0-9]\%'| cut -f1 -d% |awk '{print $NF}'|grep -v '\.' ;done | \
Xdialog --title "Building Squashfile " --gauge "Building Squashfile. Please Wait..." 0 0

@musher0
Quote:
mksquasfs has a progress bar by default.

Yes, but only from terminal, it's nice to be able to use Xdialog gui progress bar also.

Fred


Cheers rufwoof and Fred, exactly what I was after.

_________________
X-slacko-5b1 - X-tahr-2.0 - X-precise-2.4
X-series repo
Back to top
View user's profile Send private message 
rg66


Joined: 23 Jul 2012
Posts: 1127
Location: Vancouver, BC Canada / Entebbe, Uganda Africa!?!

PostPosted: Sun 01 Oct 2017, 08:40    Post subject:  

Hmmmmm, it only seems to work when run from terminal. Dropping a dir on the script or running from thunar custom action shows no progress.
_________________
X-slacko-5b1 - X-tahr-2.0 - X-precise-2.4
X-series repo
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 2588
Location: holland

PostPosted: Sun 01 Oct 2017, 15:33    Post subject:  

rg66 wrote:
Hmmmmm, it only seems to work when run from terminal. Dropping a dir on the script or running from thunar custom action shows no progress.


Yes indeed, I see also now, pity !

EDIT:
This works for me by dropping a dir on the script or running from thunar custom action:
Code:
t=$1
script -q -c "stty rows 40 cols 100; mksquashfs "$t" "new.sfs"" |while read -n 99 LINE ; do
echo $LINE |egrep '[0-9]\%'| cut -f1 -d% |awk '{print $NF}'|grep -v '\.' ;done | \
Xdialog --title "Building Squashfile " --gauge "Building Squashfile. Please Wait..." 0 0


Fred
Back to top
View user's profile Send private message 
rg66


Joined: 23 Jul 2012
Posts: 1127
Location: Vancouver, BC Canada / Entebbe, Uganda Africa!?!

PostPosted: Mon 02 Oct 2017, 01:22    Post subject:  

Works for me too, thanks Fred. Here's my dir2sfs which has compression options.

Code:
#!/bin/bash -x

t=`echo "$1" | sed "s/\/$//"`
z=`echo "$1" | sed "s/\/$//"`

if [ ! -d "$t" ];then

  echo "error: no valid folder specified!"
  exit 0

fi

### if no _versionnummer in the end, get it from system
check=`echo $t | sed "s/\(.*\)_[0-9][0-9][0-9]$/\1/"`

#echo --- $check


#echo $t - $z


if [ -f "$z.sfs" ];then

yad --window-icon="application-x-squashfs-image" --title="sfs exists" --text="$z.sfs already exists, refusing to overwrite it!" --button="gtk-ok" \
--borders="10" --buttons-layout="center"
  exit 0

fi

yad --window-icon="application-x-squashfs-image" --title "Choose Compression Type" --text "Choose which algorthim to compress the sfs with.
Choosing XZ will give you a smaller iso but may
be slower than GZIP on very lowspec machines.
XZ-HC is a higher compression xz squashfile." --text-align="center" --borders="5" --buttons-layout="center" --button="GZIP:0" --button="XZ:1" --button="XZ-HC:2"
case $? in
0) COMP="-comp gzip" ;;
1) COMP="-comp xz" ;;
2) COMP="-comp xz -b 1024k -Xbcj x86" ;;
*) exit ;;
esac

script -q -c "stty rows 40 cols 100; mksquashfs "$t" "$z.sfs" $COMP" | while read -n 99 LINE ; do
echo $LINE | egrep '[0-9]\%'| cut -f1 -d% | awk '{print $NF}'| grep -v '\.' ;done | \
Xdialog --title "Building Squashfile " --gauge "Building Squashfile. Please Wait..." 0 0
md5sum "$z.sfs" > "$z.sfs-md5.txt"
rm -f typescript
sync


echo
echo
s=`du -m "$z.sfs" | sed "s/\s.*//"`
echo "created: $z.sfs ( $s MB )"
echo "created: $z.sfs-md5.txt"
echo
echo "...byebye..."
echo

_________________
X-slacko-5b1 - X-tahr-2.0 - X-precise-2.4
X-series repo
Back to top
View user's profile Send private message 
phat7

Joined: 05 Jun 2015
Posts: 89

PostPosted: Mon 02 Oct 2017, 01:46    Post subject:  

rg66 wrote:
Works for me too, thanks Fred. Here's my dir2sfs which has compression options.

Code:
#!/bin/bash -x

t=`echo "$1" | sed "s/\/$//"`
z=`echo "$1" | sed "s/\/$//"`

if [ ! -d "$t" ];then

  echo "error: no valid folder specified!"
  exit 0

fi

### if no _versionnummer in the end, get it from system
check=`echo $t | sed "s/\(.*\)_[0-9][0-9][0-9]$/\1/"`

#echo --- $check


#echo $t - $z


if [ -f "$z.sfs" ];then

yad --window-icon="application-x-squashfs-image" --title="sfs exists" --text="$z.sfs already exists, refusing to overwrite it!" --button="gtk-ok" \
--borders="10" --buttons-layout="center"
  exit 0

fi

yad --window-icon="application-x-squashfs-image" --title "Choose Compression Type" --text "Choose which algorthim to compress the sfs with.
Choosing XZ will give you a smaller iso but may
be slower than GZIP on very lowspec machines.
XZ-HC is a higher compression xz squashfile." --text-align="center" --borders="5" --buttons-layout="center" --button="GZIP:0" --button="XZ:1" --button="XZ-HC:2"
case $? in
0) COMP="-comp gzip" ;;
1) COMP="-comp xz" ;;
2) COMP="-comp xz -b 1024k -Xbcj x86" ;;
*) exit ;;
esac

script -q -c "stty rows 40 cols 100; mksquashfs "$t" "$z.sfs" $COMP" | while read -n 99 LINE ; do
echo $LINE | egrep '[0-9]\%'| cut -f1 -d% | awk '{print $NF}'| grep -v '\.' ;done | \
Xdialog --title "Building Squashfile " --gauge "Building Squashfile. Please Wait..." 0 0
md5sum "$z.sfs" > "$z.sfs-md5.txt"
rm -f typescript
sync


echo
echo
s=`du -m "$z.sfs" | sed "s/\s.*//"`
echo "created: $z.sfs ( $s MB )"
echo "created: $z.sfs-md5.txt"
echo
echo "...byebye..."
echo

Some elements now GUI only, some CLI only Shocked
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 2588
Location: holland

PostPosted: Mon 02 Oct 2017, 05:47    Post subject:  

rg66 wrote:
Works for me too, thanks Fred. Here's my dir2sfs which has compression options.


Thanks, I made for myself small change, to be able to cancel the mksquashfs process by closing the progressbar window:

Code:
(
script -q -c "stty rows 40 cols 100; mksquashfs "$t" "$z.sfs" $COMP" |while read -n 99 LINE ; do
echo $LINE |egrep '[0-9]\%'| cut -f1 -d% |awk '{print $NF}'|grep -v '\.' ;done &
) | Xdialog --title "Building Squashfile " --gauge "Building Squashfile. Please Wait... \n To cancel: Close this window" 7 70 0

if [ $? -ne 0 ]; then    # progressbar closed by user, so kill mksquashfs process
SQUASHPID=$(ps -eo pid,cmd | grep -v grep | grep "mksquashfs $t $z.sfs" | awk '{ print $1 }')
kill $SQUASHPID
yad --center --borders=10 --title="SFS creation canceled" --window-icon="application-x-squashfs-image" --width=300 --text="  SFS creation canceled " --timeout=5 --button="gtk-close:0" &
exit
fi
md5sum "$z.sfs" > "$z.sfs-md5.txt"
rm -f typescript
sync


Fred
Back to top
View user's profile Send private message 
rg66


Joined: 23 Jul 2012
Posts: 1127
Location: Vancouver, BC Canada / Entebbe, Uganda Africa!?!

PostPosted: Mon 02 Oct 2017, 05:49    Post subject:  

phat7 wrote:
Some elements now GUI only, some CLI only Shocked


There is no interaction with the command line. All the echo lines were there originally and I don't really see a need to remove them.

_________________
X-slacko-5b1 - X-tahr-2.0 - X-precise-2.4
X-series repo
Back to top
View user's profile Send private message 
rg66


Joined: 23 Jul 2012
Posts: 1127
Location: Vancouver, BC Canada / Entebbe, Uganda Africa!?!

PostPosted: Mon 02 Oct 2017, 06:59    Post subject:  

fredx181 wrote:
Thanks, I made for myself small change, to be able to cancel the mksquashfs process by closing the progressbar window:


Nice, very handy. Here's one using only yad
(I've noticed that both yad and Xdialog reach %100 before the sfs is actually finished using xz compression)

Code:
#!/bin/bash

t=`echo "$1" | sed "s/\/$//"`
z=`echo "$1" | sed "s/\/$//"`

if [ ! -d "$t" ];then
  echo "error: no valid folder specified!"
  exit 0
fi

### if no _versionnummer in the end, get it from system
check=`echo $t | sed "s/\(.*\)_[0-9][0-9][0-9]$/\1/"`

if [ -f "$z.sfs" ];then
  yad --window-icon="application-x-squashfs-image" --title="sfs exists" --text="<b>$z.sfs already exists, refusing to overwrite it!</b>" --button="gtk-ok" \
  --text-align="center" --borders="10" --buttons-layout="center"
  exit 0
fi

yad --window-icon="application-x-squashfs-image" --title "Choose Compression Type" --text "Choose which algorthim to compress the sfs with.
Choosing XZ will give you a smaller iso but may
be slower than GZIP on very lowspec machines.
XZ-HC is a higher compression xz squashfile." --text-align="center" --borders="5" --buttons-layout="center" \
--button="GZIP:0" --button="XZ:1" --button="XZ-HC:2"
case $? in
  0) COMP="-comp gzip" ;;
  1) COMP="-comp xz" ;;
  2) COMP="-comp xz -b 1024k -Xbcj x86" ;;
  *) exit ;;
esac

script -q -c "stty rows 40 cols 100; mksquashfs "$t" "$z.sfs" $COMP" | while read -n 99 LINE ; do
PROG=`echo $LINE | egrep '[0-9]\%' | cut -f1 -d% | awk '{print $NF}'| grep -v '\.'`
echo "#$PROG%"
echo $PROG
done | yad --window-icon="application-x-squashfs-image" --progress --borders="10" --skip-taskbar --text="<b>Building $t.sfs</b>\n" \
--text-align="center" --width="250" --button="Stop!gtk-stop!Stop operation:1" --buttons-layout="center" --auto-close 
case $? in
0) while [ "`pidof mksquashfs`" ]; do
   sleep .2
   done ;;
*) killall mksquashfs
   rm -f typescript
   exit ;; 
esac

md5sum "$z.sfs" > "$z.sfs-md5.txt"
rm -f typescript
sync


I've even removed all the CLI echo lines Wink

_________________
X-slacko-5b1 - X-tahr-2.0 - X-precise-2.4
X-series repo
Back to top
View user's profile Send private message 
phat7

Joined: 05 Jun 2015
Posts: 89

PostPosted: Mon 02 Oct 2017, 07:10    Post subject:  

rg66 wrote:
I've even removed all the CLI echo lines Wink

Almost all
Code:
if [ ! -d "$t" ];then
   echo "error: no valid folder specified!"
   exit 0
 fi
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 3 [33 Posts]   Goto page: 1, 2, 3 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
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.0641s ][ Queries: 12 (0.0039s) ][ GZIP on ]