#!/usr/bin/python2 from MythTV import MythBE,MythDB,MythLog import datetime,time,sys,subprocess try: be=MythBE() db = MythDB() except: print "Couldn't connect to MythTV service for status" sys.exit(1) cursor = db.cursor() now = datetime.datetime.now() farout=99999999 next_start_diff=datetime.timedelta(farout) num_upcoming=12 def formatTD(td): #print td days = td.days hours = td.seconds // 3600 minutes = (td.seconds % 3600) // 60 seconds = td.seconds % 60 if days > 1: day_string = "%s days" %days else: day_string = "%s day" %days if hours > 1: hour_string = "%s hours" %hours else: hour_string = "%s hour" %hours if minutes > 1: minute_string = "%s minutes" %minutes else: minute_string = "%s minute" %minutes if seconds > 1: second_string = "%s seconds" %seconds else: second_string = "%s second" %seconds return_string = '%s, %s, %s, %s' % (day_string, hour_string, minute_string, second_string) return return_string a=be.getRecorderList() header="#"*60 print header print "" print "Tuner Status: " print "--------------" for i in a: cmd="select cardtype,hostname from capturecard where cardid=%s;" %i cursor.execute(cmd) results=cursor.fetchall() type = results[0][0] hostname = results[0][1] id = i try: c=be.getCurrentRecording(i) if c.title == None: current_recording = "Idle" else: current_recording = "Recording %s" %c.title print " Tuner %s (%s) on %s : %s " %(id, type, hostname, current_recording) except: print " Tuner %s (%s) on %s : %s " %(id, type, hostname, "Tuner Error") print "" print "Upcoming Recordings (Next %s scheduled):" %(num_upcoming) print "--------------------" a=be.getUpcomingRecordings() r=0 for i in a: r += 1 if r > num_upcoming: break title_chan="%s (%s)" %(i.title, i.channame) print " %s - %s - %-50s " %(i.starttime,i.hostname, title_chan) #start_time=time.strptime(str(i.starttime), "%Y-%m-%d %H:%M:%S") diff = i.starttime - now if diff < next_start_diff : next_start_diff = diff print "" print "Conflicted Recordings:" print "----------------------" a=be.getConflictedRecordings() try: if len(a) == 0: print " No conflicts" else: for i in a: title_chan="%s (%s)" %(i.title, i.channame) print " %s - %-50s " %(i.starttime,title_chan) except: print " No conflicts" print "" print "" if next_start_diff == datetime.timedelta(farout): ur="No recordings are scheduled" else: ur=formatTD(next_start_diff) print "The next recording starts in:\n %s" %(ur) print "" subprocess.call("/usr/LH/bin/diskspace.sh",shell=True) print ""