From 2fc24e3699697bf406338eea7b9f8c475399e79b Mon Sep 17 00:00:00 2001 From: Britney Fransen Date: Sat, 1 Sep 2012 16:55:46 -0500 Subject: LinHES-system: Add scripts for misc status in MythWeb. closes #845. --- abs/core/LinHES-system/LinHES-system.install | 12 + abs/core/LinHES-system/PKGBUILD | 15 +- abs/core/LinHES-system/misc_recent_recordings.pl | 194 ++++++++++++ abs/core/LinHES-system/misc_status_config.py | 15 + abs/core/LinHES-system/misc_status_info.sh | 23 ++ abs/core/LinHES-system/misc_upcoming_recordings.pl | 328 +++++++++++++++++++++ abs/core/LinHES-system/misc_which_recorder.pl | 105 +++++++ 7 files changed, 690 insertions(+), 2 deletions(-) create mode 100644 abs/core/LinHES-system/LinHES-system.install create mode 100755 abs/core/LinHES-system/misc_recent_recordings.pl create mode 100755 abs/core/LinHES-system/misc_status_config.py create mode 100755 abs/core/LinHES-system/misc_status_info.sh create mode 100755 abs/core/LinHES-system/misc_upcoming_recordings.pl create mode 100755 abs/core/LinHES-system/misc_which_recorder.pl diff --git a/abs/core/LinHES-system/LinHES-system.install b/abs/core/LinHES-system/LinHES-system.install new file mode 100644 index 0000000..f2185cd --- /dev/null +++ b/abs/core/LinHES-system/LinHES-system.install @@ -0,0 +1,12 @@ +## arg 1: the new package version +post_install() { + /usr/LH/bin/misc_status_config.py +} + +## arg 1: the new package version +## arg 2: the old package version +post_upgrade() { + /usr/LH/bin/misc_status_config.py +} + +# vim:set ts=2 sw=2 et: diff --git a/abs/core/LinHES-system/PKGBUILD b/abs/core/LinHES-system/PKGBUILD index cf2d688..9a62ccf 100644 --- a/abs/core/LinHES-system/PKGBUILD +++ b/abs/core/LinHES-system/PKGBUILD @@ -1,6 +1,6 @@ pkgname=LinHES-system pkgver=2 -pkgrel=53 +pkgrel=54 arch=('i686') MVDIR=$startdir/pkg/usr/LH BINDIR=$startdir/pkg/usr/bin @@ -8,6 +8,7 @@ install=LinHES.install pkgdesc="scripts and things related to having an automated system" depends=(linhes-sounds xdotool fluxbox tilda keylaunch python_aosd 'linhes-scripts>=7-24' 'runit-scripts>=2.1.1-43' 'udisks' 'LinHES-config>=2.3-59') backup=(etc/modprobe.d/alsa-base) +install=LinHES-system.install binfiles="LinHES-start optimize_mythdb.py myth_mtc.py myth_mtc.sh LinHES-run firstboot.sh load-modules-mythvantage.sh @@ -21,7 +22,12 @@ binfiles="LinHES-start optimize_mythdb.py lh_system_all_host_update add_storage.py diskspace.sh - cacheclean lh_message.sh switch_web.sh" + cacheclean lh_message.sh switch_web.sh + misc_recent_recordings.pl + misc_status_config.py + misc_status_info.sh + misc_upcoming_recordings.pl + misc_which_recorder.pl" source=(LinHES-session LinHES-profile.sh $binfiles alsa-base myth_mtc.lr diskspace smolt.cron cacheclean.cron) @@ -78,6 +84,11 @@ md5sums=('d1a5963c5a440a608031c6d750232633' '9603b0ca6e090eff31e76482a3c335e7' 'b798ee0796d1b760a2998f90eb8ce9cc' '4a3cd8f9b33b2b86fdba47a8f1fa2859' + '06a628469051237943b7c874f2e29b8a' + '0512f859cd5ea1d9eb972840caef2f0e' + '45f46d1f9193c8dde18e56369ec29a1e' + 'a8edbe7bc37e9932e8749d9f5f89c16f' + '14cea9e87654441b766a97576233ba5a' 'eb879fee9603a05d5420d4ce8ed9e450' 'f1870a9522c79e6b248fcbf81dec3280' '84492954db16740f949d795b74383189' diff --git a/abs/core/LinHES-system/misc_recent_recordings.pl b/abs/core/LinHES-system/misc_recent_recordings.pl new file mode 100755 index 0000000..92dda8a --- /dev/null +++ b/abs/core/LinHES-system/misc_recent_recordings.pl @@ -0,0 +1,194 @@ +#!/usr/bin/perl -w +# +# Outputs information about the most-recently-recorded shows. +# +# Automatically detects database settings. +# + +# Includes + use DBI; + use Getopt::Long; + use MythTV; + +# Some variables we'll use here + our ($num_recordings, $live, $heading, $plain_text, $text_format, $usage); + our ($hours, $minutes, $seconds); + our ($dnum_recordings, $dheading, $dtext_format); + our ($dhours, $dminutes, $dseconds); + our ($status_text_format, $status_value_format); + our ($dstatus_text_format, $dstatus_value_format); + +# Default number of recent recordings to show + $dnum_recordings = 5; +# Default period in which to show recordings + $dhours = -1; + $dminutes = -1; + $dseconds = -1; +# Default status output heading + $dheading='Recent Recordings:\n'; +# Default format of plain-text output + $dtext_format='%n/%j, %g:%i %A - %cc\n%T - %S\n%R\n\n'; +# Default format of status output display text + $dstatus_text_format= '%n/%j %g:%i %A - %cc - %T - %S
'. + '%T %n/%j, %g:%i %A
'. + '%S

%R

'; +# Default format of status output value + $dstatus_value_format = '%n/%j, %g:%i %A - %T - %S'; + +# Provide default values for GetOptions + $num_recordings = $dnum_recordings; + $hours = $dhours; + $minutes = $dminutes; + $seconds = $dseconds; + $heading = $dheading; + $text_format = $dtext_format; + $status_text_format = $dstatus_text_format; + $status_value_format = $dstatus_value_format; + +# Load the cli options + GetOptions('num_recordings|recordings=s' => \$num_recordings, + 'hours|o=i' => \$hours, + 'minutes=i' => \$minutes, + 'seconds|e=i' => \$seconds, + 'live' => \$live, + 'heading=s' => \$heading, + 'plain_text' => \$plain_text, + 'text_format=s' => \$text_format, + 'status_text_format=s' => \$status_text_format, + 'status_value_format=s' => \$status_value_format, + 'usage|help' => \$usage + ); + +# Print usage + if ($usage) { + print < 0); + $start_after = $start_after - ($minutes * 60) if ($minutes > 0); + $start_after = $start_after - $seconds if ($seconds > 0); + $start_after = 0 if (!($start_after < $now)); + +# Fix the heading. + if (defined($plain_text)) { + $heading =~ s/\\r/\r/g; + $heading =~ s/\\n/\n/g; + } + else { + # Remove line break format specifiers from heading for status output + $heading =~ s/(\\r|\\n)//g; + } + +# Connect to mythbackend + my $Myth = new MythTV(); + +# Get the list of recordings + my $count = 0; + my %rows = $Myth->backend_rows('QUERY_RECORDINGS Delete'); + our $show; + foreach my $row (@{$rows{'rows'}}) { + last unless (($count < $num_recordings) || ($num_recordings < 0)); + $show = new MythTV::Program(@$row); + # Skip LiveTV recordings? + next unless (defined($live) || $show->{'recgroup'} ne 'LiveTV'); + # Within the period of interest? + last if (($start_after) && ($show->{'recstartts'} < $start_after)); + # Print the recording information in the desired format + if (defined($plain_text)) { + text_print($count); + } + else { + status_print($count); + } + $count++; + } + +# Print the output for use in the backend status page. + sub status_print { + my $count = shift; + my $text = $show->format_name($status_text_format, ' ', ' ', 1, 0 ,1); + my $value = $show->format_name($status_value_format, ' ', ' ', + 1, 0 ,1); + print("$heading
") if ($count == 0); + print("$text"); + print("
") if ($count == ($num_recordings - 1)); + print("[]:[]recording$count"); + print("[]:[]$value\n"); + } + +# Print the output in plain text format + sub text_print { + my $count = shift; + my $text = $show->format_name($text_format, ' ', ' ', 1, 0 ,1); + $text =~ s/\\r/\r/g; + $text =~ s/\\n/\n/g; + print("$heading") if ($count == 0); + print("$text"); + } diff --git a/abs/core/LinHES-system/misc_status_config.py b/abs/core/LinHES-system/misc_status_config.py new file mode 100755 index 0000000..0a0ba6c --- /dev/null +++ b/abs/core/LinHES-system/misc_status_config.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python2 + +# This script will configure the myth db to use the misc_status_info scripts + +from socket import gethostname +from MythTV import MythDB +mythdb = MythDB() +localhostname = gethostname() + +# mythtv-setup +if mythdb.settings[localhostname].MiscStatusScript == u'': + mythdb.settings[localhostname].MiscStatusScript = u'/usr/LH/bin/misc_status_info.sh' + print 'The MythTV database setting MiscStatusScript was updated to /usr/LH/bin/misc_status_info.sh.' +else: + print 'The MythTV database setting MiscStatusScript is already set and will not be updated.' diff --git a/abs/core/LinHES-system/misc_status_info.sh b/abs/core/LinHES-system/misc_status_info.sh new file mode 100755 index 0000000..14a972c --- /dev/null +++ b/abs/core/LinHES-system/misc_status_info.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# Show all upcoming conflicts +/usr/LH/bin/misc_upcoming_recordings.pl --recordings -1 \ + --no_show_scheduled \ + --heading '

Recording Conflicts

' \ + --no_conflicts_message '

No Recording Conflicts

' + +# Show all the shows recorded today +/usr/LH/bin/misc_recent_recordings.pl --recordings=-1 --hours=24 \ + --heading '

Shows Recorded In The Last 24 Hours

' + +# Get Encoder that was used for recordings from the backend log +firstrun=1 +loglist=`find /var/log/ -name *_mythbackend.*.log*` +for i in `ls -t $loglist` +do + if [ $firstrun -eq 1 ]; then + echo "

Encoder Information

'. + '%T %n/%j, %g:%i %A
'. + '%S

%R

'; +# Default format of status output value + $dstatus_value_format = '%n/%j %g:%i %A - %T - %S'; + +# Provide default values for GetOptions + $num_recordings = $dnum_recordings; + $hours = $dhours; + $minutes = $dminutes; + $seconds = $dseconds; + $scheduled = $dscheduled; + $duplicates = $dduplicates; + $deactivated = $ddeactivated; + $conflicts = $dconflicts; + $heading = $dheading; + $text_format = $dtext_format; + $no_conflicts_message = $dno_conflicts_message; + $status_text_format = $dstatus_text_format; + $status_value_format = $dstatus_value_format; + +# Load the cli options + GetOptions('num_recordings|recordings=s' => \$num_recordings, + 'hours|o=i' => \$hours, + 'minutes=i' => \$minutes, + 'seconds|s=i' => \$seconds, + 'show_scheduled|_show_scheduled|scheduled|_scheduled|e!' + => \$scheduled, + 'show_duplicates|_show_duplicates|duplicates|_duplicates|p!' + => \$duplicates, + 'show_deactivated|_show_deactivated|deactivated|_deactivated|v!' + => \$deactivated, + 'show_conflicts|_show_conflicts|conflicts|_conflicts!' + => \$conflicts, + 'heading=s' => \$heading, + 'plain_text' => \$plain_text, + 'text_format=s' => \$text_format, + 'no_conflicts_message=s' => \$no_conflicts_message, + 'status_text_format=s' => \$status_text_format, + 'status_value_format=s' => \$status_value_format, + 'usage|help' => \$usage + ); + +# Print usage + if ($usage) { + # Make default "--show_*" options readable + $dscheduled = ($dscheduled ? '--show_scheduled' : + '--no_show_scheduled'); + $dduplicates = ($dduplicates ? '--show_duplicates' : + '--no_show_duplicates'); + $ddeactivated = ($ddeactivated ? '--show_deactivated' : + '--no_show_deactivated'); + $dconflicts = ($dconflicts ? '--show_conflicts' : + '--no_show_conflicts'); + print < 0); + $start_before = $start_before + ($minutes * 60) if ($minutes > 0); + $start_before = $start_before + $seconds if ($seconds > 0); + $start_before = 0 if (!($start_before > $now)); + +# Fix the heading. + if (defined($plain_text)) { + $heading =~ s/\\r/\r/g; + $heading =~ s/\\n/\n/g; + } + else { + # Remove line break format specifiers from heading for status output + $heading =~ s/(\\r|\\n)//g; + } + +# Connect to mythbackend + my $Myth = new MythTV(); + +# Get the list of recordings + my $count = 0; + my %rows = $Myth->backend_rows('QUERY_GETALLPENDING', 2); + my $has_conflicts = $rows{'offset'}[0]; + if ((!$has_conflicts) && + (($conflicts) && + (!(($scheduled) || ($duplicates) || ($deactivated))))) { + $no_conflicts_message =~ s/\\r/\r/g; + $no_conflicts_message =~ s/\\n/\n/g; + print "$no_conflicts_message"; + exit 0; + } + my $num_scheduled = $rows{'offset'}[1]; + our $show; + foreach my $row (@{$rows{'rows'}}) { + last unless (($count < $num_recordings) || ($num_recordings < 0)); + $show = new MythTV::Program(@$row); + last if (($start_before) && ($show->{'recstartts'} > $start_before)); + next if ((!$scheduled) && (is_scheduled($show->{'recstatus'}))); + next if ((!$duplicates) && (is_duplicate($show->{'recstatus'}))); + next if ((!$deactivated) && (is_deactivated($show->{'recstatus'}))); + next if ((!$conflicts) && (is_conflict($show->{'recstatus'}))); + + # Print the recording information in the desired format + if (defined($plain_text)) { + text_print($count); + } + else { + status_print($count); + } + $count++; + } + +# Returns true if the show is scheduled to record + sub is_scheduled { + my $recstatus = (shift() or 0); + return (($MythTV::recstatus_willrecord == $recstatus) || + ($MythTV::recstatus_recorded == $recstatus) || + ($MythTV::recstatus_recording == $recstatus)); + } + +# Returns true if the show is a duplicate + sub is_duplicate { + my $recstatus = (shift() or 0); + return (($MythTV::recstatus_repeat == $recstatus) || + ($MythTV::recstatus_previousrecording == $recstatus) || + ($MythTV::recstatus_currentrecording == $recstatus)); + } + +# Returns true if the recording is deactivated + sub is_deactivated { + my $recstatus = (shift() or 0); + return (($MythTV::recstatus_inactive == $recstatus) || + ($MythTV::recstatus_toomanyrecordings == $recstatus) || + ($MythTV::recstatus_cancelled == $recstatus) || + ($MythTV::recstatus_deleted == $recstatus) || + ($MythTV::recstatus_aborted == $recstatus) || + ($MythTV::recstatus_notlisted == $recstatus) || + ($MythTV::recstatus_dontrecord == $recstatus) || + ($MythTV::recstatus_lowdiskspace == $recstatus) || + ($MythTV::recstatus_tunerbusy == $recstatus) || + ($MythTV::recstatus_neverrecord == $recstatus) || + ($MythTV::recstatus_earliershowing == $recstatus) || + ($MythTV::recstatus_latershowing == $recstatus)); + } + +# Returns true if the show cannot be recorded due to a conflict + sub is_conflict { + my $recstatus = (shift() or 0); + return ($MythTV::recstatus_conflict == $recstatus); + } + +# Print the output for use in the backend status page. + sub status_print { + my $count = shift; + my $text = $show->format_name($status_text_format, ' ', ' ', 1, 0 ,1); + $text =~ s/%rs/$MythTV::RecStatus_Types{$show->{'recstatus'}}/g; + my $value = $show->format_name($status_value_format, ' ', ' ', + 1, 0 ,1); + $value =~ s/%rs/$MythTV::RecStatus_Types{$show->{'recstatus'}}/g; + print("$heading
") if ($count == 0); + print("$text"); + print("
") if ($count == ($num_recordings - 1)); + print("[]:[]recording$count"); + print("[]:[]$value\n"); + } + +# Print the output in plain text format + sub text_print { + my $count = shift; + my $text = $show->format_name($text_format, ' ', ' ', 1, 0 ,1); + $text =~ s/%rs/$MythTV::RecStatus_Types{$show->{'recstatus'}}/g; + $text =~ s/\\r/\r/g; + $text =~ s/\\n/\n/g; + print("$heading") if ($count == 0); + print("$text"); + } diff --git a/abs/core/LinHES-system/misc_which_recorder.pl b/abs/core/LinHES-system/misc_which_recorder.pl new file mode 100755 index 0000000..f8a1022 --- /dev/null +++ b/abs/core/LinHES-system/misc_which_recorder.pl @@ -0,0 +1,105 @@ +#!/usr/bin/perl -w +# +# Parses the backend log file and includes information on which encoder was used to record shows. + +my ($time, $title, $subtitle, $chanid, $cardid, $sourceid); +my $index = 0; + +sub print_text +{ + print "$time - $title"; + print ": $subtitle" if ($subtitle); + print "\n"; + print " - Encoder ID: $cardid\n"; + print " - Video Source ID: $sourceid\n"; + print " - Channel ID: $chanid\n"; +} + +sub print_xml +{ + print "$time - $title"; + print ": $subtitle" if ($subtitle); + print " - Encoder: $cardid
". + "$title $time
"; + print "$subtitle
" if ($subtitle); + print "
Channel ID: $chanid
Encoder ID: $cardid
". + "Video Source ID: $sourceid

"; + # For XML parsers + print "[]:[]capture_info$index\[]:[]time='$time':title='$title'". + ":subtitle='$subtitle':chanid='$chanid':cardid='$cardid'". + ":sourceid='$sourceid'\n"; +} + +my $mode = shift; +my $log_file = shift; + +if (($mode ne "--text") && ($mode ne "--noheader")) +{ + $log_file = $mode; +} + +if ($log_file =~ m/^--.*/i) +{ + die ("Only one option can be used at a time.\n"); +} + +if ($log_file =~ /\.gz$/) +{ +# read top down +# open($fh, "gunzip -c $log_file |") or die "Unable to open log file '$log_file', stopping:"; + open($fh, "gunzip -c $log_file |tac |") or die "Unable to open log file '$log_file', stopping:"; +} +else +{ +# read top down +# open($fh, "<$log_file") or die "Unable to open log file '$log_file', stopping:"; + open($fh, "tac $log_file |") or die "Unable to open log file '$log_file', stopping:"; +} + +while (<$fh>) +{ +# Myth .24 regex to find start of recording +# if (/^(.*)(?:\d(?: I )?|I.* -) (?:Started|Tuning) recording: (.*): channel (\d+) on cardid (\d+), sourceid (\d+)/) + if (/^(\d+-\d+-\d+T\d+\:\d+\:\d+)(?:.*) (?:Started|Tuning) recording: (.*): channel (\d+) on cardid (\d+), sourceid (\d+)/) + { + if ($mode eq "--noheader") + { + print "
" + if (($index == 0) && ($mode ne "--text")); + } + else + { + print "

Encoder Information

" + if (($index == 0) && ($mode ne "--text")); + } + $index++; + + ($time, $title, $chanid, $cardid, $sourceid) = ($1, $2, $3, $4, $5); + $time = `date -d $time +%a' '%m/%d' '%H:%M' '%p`; + chomp ($time); + if (($title =~ /"?(.+)"?:"?(.*)"?/) || ($title =~ /(.+) "(.*)"/)) + { + $title = $1; + $subtitle = $2; + } + else + { + $subtitle = ''; + } + $title =~ s/^"//; + $subtitle =~ s/^"//; + $title =~ s/"$//; + $subtitle =~ s/"$//; + if ($mode eq "--text") + { + print_text; + } + else + { + print_xml; + } + } +} +print "
" if (($index > 0) && ($mode ne "--text")); + +close $fh; -- cgit v0.12