From: Andrew Ruthven <andrew@etc.gen.nz>
Date: Wed, 28 Nov 2007 03:34:41 +0000 (+1300)
Subject: Add support for reading XML from a file.
X-Git-Tag: 0.6.0~38
X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4bce177b736db4c90b063c8900593933e09a2ba1;p=mythtv-status.git

Add support for reading XML from a file.
---

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("", <IN>);
+
+    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 <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.