~siretart/sbuild/bug.940410

« back to all changes in this revision

Viewing changes to lib/Sbuild/Utility.pm

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-11-28 07:44:25 UTC
  • mfrom: (8.1.25) (50.1.1 raring-proposed)
  • Revision ID: package-import@ubuntu.com-20121128074425-w2vncf3x1f42r3aq
Tags: 0.63.2-1ubuntu1
* Merge from Debian unstable. Remaining changes:
  - debian/patches/do-not-install-debfoster-into-chroots.patch: do not
    install debfoster into the chroots because it is in universe and not
    needed for package building itself.
  - debian/patches/run-pre-build-hooks-as-root.patch: run pre-build hooks
    as root.
  - Convert package back to source format 3.0 (quilt) so the patches get
    applied.

Show diffs side-by-side

added added

removed removed

Lines of Context:
174
174
    # The parameters will be any URL and a location to save the file to.
175
175
    my($url, $file) = @_;
176
176
 
177
 
    # Print output from this subroutine to saved stdout stream of sbuild.
178
 
    my $stdout = $Sbuild::LogBase::saved_stdout;
179
 
 
180
177
    # If $url is a readable plain file on the local system, just return the
181
178
    # $url.
182
179
    return $url if (-f $url && -r $url);
203
200
    }
204
201
 
205
202
    # Download the file.
206
 
    print $stdout "Downloading $url to $file.\n";
 
203
    print "Downloading $url to $file.\n";
207
204
    my $expected_length; # Total size we expect of content
208
205
    my $bytes_received = 0; # Size of content as it is received
209
206
    my $percent; # The percentage downloaded
247
244
                if (($tick == 250) or ($percent == 100)) {
248
245
                    if ($tick == 1) {
249
246
                        # In case we reach 100% from tick 1.
250
 
                        printf $stdout "%8s", sprintf("%d",
 
247
                        printf "%8s", sprintf("%d",
251
248
                            $bytes_received / 1024) . "KB";
252
 
                        print $stdout " [.";
 
249
                        print " [.";
253
250
                    }
254
251
                    while ($tick != 250) {
255
252
                        # In case we reach 100% before reaching 250 ticks
256
 
                        print $stdout "." if ($tick % 5 == 0);
 
253
                        print "." if ($tick % 5 == 0);
257
254
                        $tick++;
258
255
                    }
259
 
                    print $stdout ".]";
260
 
                    printf $stdout "%5s", "$percent%";
261
 
                    printf $stdout "%12s", "$speed\n";
 
256
                    print ".]";
 
257
                    printf "%5s", "$percent%";
 
258
                    printf "%12s", "$speed\n";
262
259
                    $tick = 0;
263
260
                } elsif ($tick == 1) {
264
 
                    printf $stdout "%8s", sprintf("%d",
 
261
                    printf "%8s", sprintf("%d",
265
262
                        $bytes_received / 1024) . "KB";
266
 
                    print $stdout " [.";
 
263
                    print " [.";
267
264
                } elsif ($tick % 5 == 0) {
268
 
                    print $stdout ".";
 
265
                    print ".";
269
266
                }
270
267
            }
271
268
            # Write the contents of the download to our specified file
273
270
                print $fh $chunk; # Print content to file
274
271
            } else {
275
272
                # Print message upon failure during download
276
 
                print $stdout "\n" . $response->status_line . "\n";
 
273
                print "\n" . $response->status_line . "\n";
277
274
                return 0;
278
275
            }
279
 
            $stdout->flush();
280
276
        }
281
277
    ); # End of our content callback subroutine
282
278
    close $fh; # Close the destination file
289
285
 
290
286
    # Print out amount of content received before returning the path of the
291
287
    # file.
292
 
    print $stdout "Download of $url sucessful.\n";
293
 
    print $stdout "Size of content downloaded: ";
 
288
    print "Download of $url sucessful.\n";
 
289
    print "Size of content downloaded: ";
294
290
    if ($bytes_received >= 1024 * 1024) {
295
 
        print $stdout sprintf("%.4g MB",
 
291
        print sprintf("%.4g MB",
296
292
            $bytes_received / (1024.0 * 1024)) . "\n";
297
293
    } elsif ($bytes_received >= 1024) {
298
 
        print $stdout sprintf("%.4g KB", $bytes_received / 1024.0) . "\n";
 
294
        print sprintf("%.4g KB", $bytes_received / 1024.0) . "\n";
299
295
    } else {
300
 
        print $stdout sprintf("%.4g B", $bytes_received) . "\n";
 
296
        print sprintf("%.4g B", $bytes_received) . "\n";
301
297
    }
302
298
 
303
299
    return $file;