From: Mark Wells Date: Wed, 1 Jul 2015 23:52:16 +0000 (-0700) Subject: another useful debugging tool X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=d1cdae31052a590b270145b34e57aa0156e73ea2 another useful debugging tool --- diff --git a/bin/fetch_pages b/bin/fetch_pages new file mode 100755 index 000000000..5aeca56b3 --- /dev/null +++ b/bin/fetch_pages @@ -0,0 +1,80 @@ +#!/usr/bin/perl + +use strict; +use WWW::Mechanize; +use Getopt::Std; +use File::chdir; +use URI; +use File::Slurp qw(write_file); + +my %opt; +getopts('d:h:u:p:', \%opt); +die usage() unless ($opt{d} and $opt{u} and $opt{p}); +my $host = $opt{h} || 'http://localhost/freeside'; + +my $mech = WWW::Mechanize->new( autocheck => 0 ); +$mech->get("$host/index.html"); +$mech->submit_form( + with_fields => { + credential_0 => $opt{u}, + credential_1 => $opt{p} + } +); + +my @tests = <>; + +mkdir($opt{d}) unless -d $opt{d}; +push @CWD, $opt{d}; + +while (my $path = shift @tests) { + if ($path =~ /^#(.*)/) { + print "$1 - skipped\n"; + next; + } + my $uri = URI->new("$host/$path"); + print $uri->path; + my $response = $mech->get($uri); + print " - " . $response->code . "\n"; + if ($response->is_success) { + local $CWD; + my @dirs = $uri->path_segments; + my $file = pop @dirs; + foreach my $dir (@dirs) { + mkdir $dir unless -d $dir; + push @CWD, $dir; + } + write_file($file, {binmode => ':utf8'}, $response->decoded_content); + } +} + +sub usage { + "Usage: fetch_pages -d directory -u username -p password [ -h hostname ]\n\n"; +} + +=head1 NAME + +fetch_pages - a testing tool for UI changes + +=head1 USAGE + +fetch_pages -d before_change -u myuser -p mypass list_of_tests +git checkout newbranch +make install; apache2ctl restart +fetch_pages -d after_change -u myuser -p mypass list_of_tests +diff -ur before_change/ after_change/ |diffstat + +=head1 ARGUMENTS + +-d: the directory to put the files in. Required. + +-u: the username to use with the Freeside web interface. Required. + +-p: the password. Required. + +-h: the URL prefix for the Freeside server. Defaults to +"http://localhost/freeside". + +The list of tests can be in a file specified after all arguments, or passed +to stdin. + +=cut