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 Wed 16 Apr 2014, 20:32
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
progress bar use in copying a file <SOLVED!!!>
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [15 Posts]  
Author Message
8-bit


Joined: 03 Apr 2007
Posts: 3276
Location: Oregon

PostPosted: Fri 30 Sep 2011, 03:31    Post subject:  progress bar use in copying a file <SOLVED!!!>
Subject description: No example shows how to sync it to actual time.
 

I want to have a progress bar in a gtkdialog script show the progress of copying a file of unknown size.
The size could be anything from 256 megs to 3 gigs.
But with a progress bar, the user gets some indication of the file copy progress.
None of the gtkdialog progressbar examples show an example that syncs to a process such as copy or some other action you want to show the progress of.
They all seem to just set some number with steps and a delay between them.
That really does not tell me a lot about syncing it to an action.
So, anyone got an example that I can try.

I already tried to use while [action];do progressbar;done and I had to force shutdown of the PC to recover from a copy command that never ended. It would start again after copying the file.

I really do not want to go through that again as shutting down while a file is being copied is dangerous to the hard drive.

Again, anyone good a good example of how to code this?

Last edited by 8-bit on Sat 01 Oct 2011, 03:43; edited 1 time in total
Back to top
View user's profile Send private message 
8-bit


Joined: 03 Apr 2007
Posts: 3276
Location: Oregon

PostPosted: Fri 30 Sep 2011, 07:52    Post subject:  

One thing I did notice is that in all the progressbar examples I did not see one that shows the progressbar implemented to show the progress of a procedure.
Such examples would be like a progress bar for copy, or read-in of a big file, or creation of a large file.

It seems that the only thing it shows is a progressbar that is generated by creating a set of numbers that increment in steps with a sleep command in between the increment steps.

I am currently trying to get a progress bar working for a file copy in a gtkdialog script and already have run into problems.

It seems that a line "org_size=$(stat -c %s $sf);echo $org_size" with "$sf" being a file with path, that works fine in a terminal will not work in a gtkdialog script and gives me the filename with path followed by a Permission Denied message.
One way I can see to get around this is to create a bash script that writes the value to a temp file and then reading back in that value.

In trying to get things set up, I even made a programming mistake that caused a file copy to go into an endless loop.
I had to chance a forced reboot to recover from that one.

And just so you know, this is for a script I am writing that is copying a large file to a different directory on a different partition with a new file name.
But rather than just a "Please wait! Copying file." message, I would like to have a progress bar synced to the copy status.
I found two examples for bash and they work, but trying to use the code in my gtkdialog script is leaving me at a loss.
Back to top
View user's profile Send private message 
puppyluvr


Joined: 06 Jan 2008
Posts: 3141
Location: Chickasha Oklahoma

PostPosted: Fri 30 Sep 2011, 08:25    Post subject:  

Very Happy Hello,
Have had a similar issue..
Tried to create a loop to read the size of the file to copy, divide by 10, and use that to control the progress bar, but as of yet to no avail...
Could you post the bash examples you spoke of??

_________________
Close the Windows, and open your eyes, to a whole new world
http://puppylinuxstuff.meownplanet.net/puppyluvr/
Puppy Linux Users Group on Facebook

Puppy since 2.15CE...
Back to top
View user's profile Send private message Visit poster's website 
Flash
Official Dog Handler


Joined: 04 May 2005
Posts: 10655
Location: Arizona USA

PostPosted: Fri 30 Sep 2011, 09:01    Post subject:  

Is it hard to periodically find the size of a file that's building, as it's building? Would that interfere with the copy process? ROX seems to do it when I rip a track from a CD and also when I download a Puppy iso. I don't know how accurate it is though. If it's possible to periodically measure the size of a file as it grows to its (known) final size, even I can see how that could be used to build a progress bar. Laughing
Back to top
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 2473
Location: Burghaslach, Germany somewhere also known as "Hosla"

PostPosted: Fri 30 Sep 2011, 09:32    Post subject: progress bar use in copying a file
Subject description: ls
 

8-bit wrote:
...
It seems that a line "org_size=$(stat -c %s $sf);echo $org_size" with "$sf" being a file with path, that works fine in a terminal will not work in a gtkdialog script and gives me the filename with path followed by a Permission Denied message
...

Why not try a simple
Code:
ls --size $sf

Smile
Back to top
View user's profile Send private message 
8-bit


Joined: 03 Apr 2007
Posts: 3276
Location: Oregon

PostPosted: Fri 30 Sep 2011, 12:42    Post subject:  

puppyluvr wrote:
Very Happy Hello,
Have had a similar issue..
Tried to create a loop to read the size of the file to copy, divide by 10, and use that to control the progress bar, but as of yet to no avail...
Could you post the bash examples you spoke of??


I actually have two examples one can run from the command line.
I was trying to use parts of one to use a progressbar in gtkdialog.
But for some reason, it wants to try to execute the file I am trying to copy when used in gtkdialog.
the two I called fcopy1 and fcopy2 and they work fine from a terminal.

fcopy1
Code:

#!/bin/bash
# Example: ./test original_file destination_file
usage()
{
   echo "Usage: $0 original_file destination_file"
   exit 1;
}

test $# == 2 || usage
orig_size=$(stat -c %s $1)

>$2
dest_size=0
cp -f $1 $2 &

while [ $orig_size -gt $dest_size ] ; do
   dest_size=$(stat -c %s $2)
   pct=$((( 69 * $dest_size ) / $orig_size ))

    echo -en "\r["
    for j in `seq 1 $pct`; do
        echo -n "="
    done
    echo -n ">"
    for j in `seq $pct 68`; do
        echo -n "."
    done
    echo -n "] "
    echo -n $((( 100 * $pct ) / 69 ))
    echo -n "%"
done
echo


fcopy2
Code:

#!/bin/bash
# File copy with progress indicators
# Example: ./test original_file destination_file

usage()
{
   echo "Usage: $0 original_file destination_file"
   exit 1;
}

test $# == 2 || usage

echo Preparing to copy
orig_size=$(stat -c %s $1)

>$2
dest_size=0
cp -f $1 $2 &

while [ $orig_size -gt $dest_size ] ; do
   dest_size=$(stat -c %s $2)
   pct=$((( 100 * $dest_size ) / $orig_size ))

if [ $pct -lt 10 ] ; then
   echo -en "#  $pct%\b\b\b\b"
else
   echo -en "#  $pct%\b\b\b\b\b"
fi
sleep 1
done
echo
Back to top
View user's profile Send private message 
8-bit


Joined: 03 Apr 2007
Posts: 3276
Location: Oregon

PostPosted: Fri 30 Sep 2011, 12:50    Post subject:  

L18L,
I tried the line you suggest and it needs further work on the string returned to just get the file size in bytes without the file name.
Also, when the line is used in gtkdialog, I get the same problem of my source file trying to execute.
If I use the file name and not a variable, it works. But if I try to use a variable containing the filename, it tries to execute the file name supplied.
Back to top
View user's profile Send private message 
puppyluvr


Joined: 06 Jan 2008
Posts: 3141
Location: Chickasha Oklahoma

PostPosted: Fri 30 Sep 2011, 12:54    Post subject:  

Very Happy Hello,
Interesting...
I was trying to use "du"..

_________________
Close the Windows, and open your eyes, to a whole new world
http://puppylinuxstuff.meownplanet.net/puppyluvr/
Puppy Linux Users Group on Facebook

Puppy since 2.15CE...
Back to top
View user's profile Send private message Visit poster's website 
8-bit


Joined: 03 Apr 2007
Posts: 3276
Location: Oregon

PostPosted: Fri 30 Sep 2011, 13:32    Post subject:  

I think my problem is with the use of "stat" in gtkdialog.
I assume gtkdialog cannot find the "stat" command and rather than kick out an error there, tries in turn to execute each item in return resulting in the error of file name cannot be executed.
I can run the bash scripts with supplied source and destination, but the progress is echoed to a terminal and not my gtkdialog script even if I try to get it there.

It is the little things you expect to work that can be the worst to debug when they fail.

Other applications we use in Puppy work fine at displaying progress of a file transfer, it is just a matter of figuring out how they do it.
And if and when I do, I will have made progress on my script which by the way is a pupsave restore script for Pupsave-backup files.

But, it also works for copying a file from one directory to another.

I know, dumb, dumb me. But it does give a challenge.
Back to top
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 2473
Location: Burghaslach, Germany somewhere also known as "Hosla"

PostPosted: Fri 30 Sep 2011, 16:25    Post subject:  

8-bit wrote:
L18L,
I tried the line you suggest and it needs further work on the string returned to just get the file size in bytes without the file name.
Also, when the line is used in gtkdialog, I get the same problem of my source file trying to execute.
If I use the file name and not a variable, it works. But if I try to use a variable containing the filename, it tries to execute the file name supplied.

cut d ' ' -f 1
or one of "speeding up scripts"

sorry for gtkdialog, I am sticking with yad

edited
is the variable double quoted?
Back to top
View user's profile Send private message 
seaside

Joined: 11 Apr 2007
Posts: 878

PostPosted: Fri 30 Sep 2011, 18:13    Post subject:  

8-bit,

You might find this useful -
Quote:

pv - Shell pipeline element to meter data passing through

pv (Pipe Viewer) can be inserted into any normal pipeline between two processes to give a visual indication of how quickly data is passing through, how long it has taken, how near to completion it is, and an estimate of how long it will be until completion.

To use it, insert it in a pipeline between two processes, with the appropriate options. Its standard input will be passed through to its standard output and progress will be shown on standard error.


Here's a deb package to try - don't think it's missing any dependencies. (I had to call it a pet to attach, so rename .deb before clicking on it to install)

Regards,
s
pv_1.1.4-1_i386.pet
Description  Pipe viewer (rename to .deb before clicking to install)
pet

 Download 
Filename  pv_1.1.4-1_i386.pet 
Filesize  27.52 KB 
Downloaded  152 Time(s) 
Back to top
View user's profile Send private message 
8-bit


Joined: 03 Apr 2007
Posts: 3276
Location: Oregon

PostPosted: Fri 30 Sep 2011, 23:05    Post subject:  

To all, I have tried double quoting my file name variable and that made no difference. The line that works in bash, but not gtkdialog is "org_size=$(stat -c %s "'$sf'")"
It is supposed to return the file size in bytes and does in bash, but not gtkdialog.
Since I am getting a message of not being able to execute the file contained in the string variable, I know that is being passed. Just not the way it should.
Also a few lines down in the script the same slightly modified line is used to get the size of the destination file and I get another message that stat is missing an operand.
So since it seems to recognize both the command and the variable, why is it trying to execute the variable?

Also, thank you seaside for the deb. I will check it out although I am wanting to make this available to those that are not running a version of Puppy that supports deb files.

I also have passed my preliminary script to 2byte for possible modification and inclusion in Pupsave-backup that is the file in Hot-Backup for frugal install Pups.
Back to top
View user's profile Send private message 
GatorDog


Joined: 12 Sep 2006
Posts: 136

PostPosted: Sat 01 Oct 2011, 00:43    Post subject:  

8-bit, here's an alternative command to get byte count.
I tried a few quick test of "wc" on text and non-text files and seems to work on both.
Code:
org_size=$(wc -c $sf | cut -d" " -f1)
It may work where stat does not.

When I used quoting like your example, "'$sf'" , I got this error-
Quote:
wc: 'filename.ext': No such file or directory

I removed the single quotes, it worked. And also worked without any quotes.
Does gtkDialog need the variable quoting?

Looking at examples of command substitution, $(....), some examples quoted a variable
and some did not.

YMMV,
GatorDog
Back to top
View user's profile Send private message 
8-bit


Joined: 03 Apr 2007
Posts: 3276
Location: Oregon

PostPosted: Sat 01 Oct 2011, 03:41    Post subject:  

It was all a matter of syntax in coding.
I now have the application completed and it includes a progress bar to show the progress of the file copy to another path/name.
If you want to check it out, it is in Additional Software - Uitlities: http://www.murga-linux.com/puppy/viewtopic.php?t=72153.
It is called Restore pupsave file hotbkup saved files in the header and the program once extracted is PupsaveRestore.sh

So my scripting problem is fixed without use of external temporary files too.
It was a real challenge!
And how do I feel. Very Happy Very Happy
Back to top
View user's profile Send private message 
seaside

Joined: 11 Apr 2007
Posts: 878

PostPosted: Sat 01 Oct 2011, 17:25    Post subject:  

8-bit wrote:


Also, thank you seaside for the deb. I will check it out although I am wanting to make this available to those that are not running a version of Puppy that supports deb files.


No support of deb files needed, as "pv" is a single binary and ran ok in pup431- it's just "contained" in a deb file.

Regards,
s
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [15 Posts]  
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.0872s ][ Queries: 13 (0.0060s) ][ GZIP on ]