From 4bce177b736db4c90b063c8900593933e09a2ba1 Mon Sep 17 00:00:00 2001 From: Andrew Ruthven Date: Wed, 28 Nov 2007 16:34:41 +1300 Subject: [PATCH] Add support for reading XML from a file. --- ChangeLog | 1 + bin/mythtv-status | 29 ++++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7b8d52e..b63413d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ 2007-11-28 Andrew Ruthven Be more wary about processing what the backend has sent us. + Add support for reading XML from a file. 2007-11-23 Andrew Ruthven Don't set the background when changing the colour. diff --git a/bin/mythtv-status b/bin/mythtv-status index a679eae..c9e1552 100755 --- a/bin/mythtv-status +++ b/bin/mythtv-status @@ -27,6 +27,7 @@ my %display; my @email; my $email_only_on_conflict = 0; my $help = undef; +my $xml_file = undef; my $VERSION = '0.5.1'; @@ -46,6 +47,8 @@ GetOptions( 'schedule-conflicts!' => \$display{'Schedule Conflicts'}, 'next-recording!' => \$display{'Time till next recording'}, + 'file=s' => \$xml_file, + 'help|?' => \$help, ) || pod2usage("\nUse --help for help.\n"); @@ -274,18 +277,29 @@ exit 0; # Fetch the XML status from the backend. sub load_xml { - my $url = "http://$host:$port/xml"; - my $status = get($url); + my $status = ""; + + if (defined $xml_file) { + open (IN, "< $xml_file") + || die "Failed to open $xml_file for reading: $!\n"; - die "Sorry, failed to fetch $url.\n" - unless defined $status; + $status = join("", ); + + close IN; + } else { + my $url = "http://$host:$port/xml"; + $status = get($url); + + die "Sorry, failed to fetch $url.\n" + unless defined $status; + } # Parse the XML my $parser = XML::LibXML->new(); my $xml = eval { $parser->parse_string( $status ) }; if ($@) { - die "Failed to parse XML from $url: $@\n"; + die "Failed to parse XML: $@\n"; } return $xml; @@ -465,6 +479,11 @@ Only send an email out (if --email is present) if there is a schedule conflict. Display help. +=item B<< --file >> + +Load XML from the file specified instead of querying a MythTV backend. +Handy for debugging things. + =item B<-h HOST, --host=HOST> The host to check, defaults to localhost. -- 2.30.2