summaryrefslogtreecommitdiffstats
path: root/abs/core/LinHES-system/myth_status.py
blob: f0e41f3fd388f086eec7e005d2b42b079f727d4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/python2
from MythTV import MythBE,MythDB,MythLog
import datetime,time,sys,subprocess,re
try:
    be = MythBE()
    db = MythDB()
except:
    print "\nCouldn'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 == 0:
      day_string = ""
    elif 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)
    #remove timezone
    start_time=re.split("[-+]\d\d:\d\d",str(i.starttime))[0]
    start_time_struct=datetime.datetime.strptime(start_time, "%Y-%m-%d %H:%M:%S")
    start_time_out=start_time_struct.strftime("%a %b %d %I:%M%p")
    print "    %s - %s - %s" %(start_time_out,i.hostname, title_chan)
    diff = start_time_struct - now
    if diff < next_start_diff :
        next_start_diff = diff


print ""
print "Recording Conflicts:"
print "----------------------"
a=be.getConflictedRecordings()
c=0
for i in a:
    title_chan="%s (%s)" %(i.title, i.channame)
    print "    %s -  %-50s " %(i.starttime,title_chan)
    c=c+1

if c == 0:
    print "    No Conflicts"

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:"
print "-----------------------------"
print "    %s" %(ur)
print ""
subprocess.call("/usr/LH/bin/diskspace.sh",shell=True)
print ""
print header