Ticket #6678: pyth.update2.patch
File pyth.update2.patch, 8.9 KB (added by , 15 years ago) |
---|
-
mythtv/bindings/python/MythTV/MythTV.py
14 14 import socket 15 15 import code 16 16 from datetime import datetime 17 from time import mktime 17 18 18 19 from MythDB import * 19 20 from MythLog import * … … 162 163 Returns a list of recorders, or an empty list if none. 163 164 """ 164 165 recorders = [] 165 c = self.db.cursor()166 pc = self.db.cursor() 166 167 c.execute('SELECT cardid FROM capturecard') 167 168 row = c.fetchone() 168 169 while row is not None: … … 220 221 else: 221 222 return False 222 223 224 def getRecording(self, chanid, starttime): 225 """ 226 Returns a Program object matching the channel id and start time 227 """ 228 res = self.backendCommand('QUERY_RECORDING TIMESLOT %d %d' % (chanid, starttime)).split(BACKEND_SEP) 229 if res[0] == 'ERROR': 230 return None 231 else: 232 return Program(res[1:]) 233 234 def getRecordings(self): 235 """ 236 Returns a list of all Program objects which have already recorded 237 """ 238 programs = [] 239 res = self.backendCommand('QUERY_RECORDINGS') 240 num_progs = int(res.pop(0)) 241 log.Msg(DEBUG, '%s total recordings', num_progs) 242 for i in range(num_progs): 243 programs.append(Program(res[i * PROGRAM_FIELDS:(i * PROGRAM_FIELDS) 244 + PROGRAM_FIELDS])) 245 return programs 246 247 def getCheckfile(self,program): 248 """ 249 Returns location of recording in file system 250 """ 251 res = self.backendCommand('QUERY_CHECKFILE[]:[]1[]:[]%s' % program.toString()).split(BACKEND_SEP) 252 if res[0] == 0: 253 return None 254 else: 255 return res[1] 256 223 257 class Recorder: 224 258 """ 225 259 Represents a MythTV capture card. … … 265 299 self.callsign = data[6] #chansign 266 300 self.channame = data[7] 267 301 self.filename = data[8] #pathname 268 self.fs_high = data[9]269 self.fs_low = data[10]302 self.fs_high = int(data[9]) 303 self.fs_low = int(data[10]) 270 304 self.starttime = datetime.fromtimestamp(int(data[11])) # startts 271 305 self.endtime = datetime.fromtimestamp(int(data[12])) #endts 272 306 self.duplicate = int(data[13]) … … 303 337 self.video_props = data[44] 304 338 self.subtitle_type = data[45] 305 339 self.year = data[46] 340 self.filesize = self.fs_low 341 if self.fs_low < 0: 342 self.filesize = 2**32+self.fs_low 343 if self.fs_high < 0: 344 self.filesize += 2**32*(2**32+self.fs_high) 345 else: 346 self.filesize += 2**32*self.fs_high 306 347 348 def toString(self): 349 string = self.title 350 string += BACKEND_SEP + self.subtitle 351 string += BACKEND_SEP + self.description 352 string += BACKEND_SEP + self.category 353 if self.chanid: 354 string += BACKEND_SEP + str(self.chanid) 355 else: 356 string += BACKEND_SEP 357 string += BACKEND_SEP + self.channum 358 string += BACKEND_SEP + self.callsign 359 string += BACKEND_SEP + self.channame 360 string += BACKEND_SEP + self.filename 361 string += BACKEND_SEP + str(self.fs_high) 362 string += BACKEND_SEP + str(self.fs_low) 363 string += BACKEND_SEP + str(int(mktime(self.starttime.timetuple()))) 364 string += BACKEND_SEP + str(int(mktime(self.endtime.timetuple()))) 365 string += BACKEND_SEP + str(self.duplicate) 366 string += BACKEND_SEP + str(self.shareable) 367 string += BACKEND_SEP + str(self.findid) 368 string += BACKEND_SEP + self.hostname 369 string += BACKEND_SEP + str(self.sourceid) 370 string += BACKEND_SEP + str(self.cardid) 371 string += BACKEND_SEP + str(self.inputid) 372 string += BACKEND_SEP + str(self.recpriority) 373 string += BACKEND_SEP + str(self.recstatus) 374 string += BACKEND_SEP + str(self.recordid) 375 string += BACKEND_SEP + self.rectype 376 string += BACKEND_SEP + self.dupin 377 string += BACKEND_SEP + self.dupmethod 378 string += BACKEND_SEP + str(int(mktime(self.recstartts.timetuple()))) 379 string += BACKEND_SEP + str(int(mktime(self.recendts.timetuple()))) 380 string += BACKEND_SEP + str(self.repeat) 381 string += BACKEND_SEP + self.programflags 382 string += BACKEND_SEP + self.recgroup 383 string += BACKEND_SEP + str(self.commfree) 384 string += BACKEND_SEP + self.outputfilters 385 string += BACKEND_SEP + self.seriesid 386 string += BACKEND_SEP + self.programid 387 string += BACKEND_SEP + self.lastmodified 388 string += BACKEND_SEP + str(self.stars) 389 string += BACKEND_SEP + self.airdate 390 string += BACKEND_SEP + str(self.hasairdate) 391 string += BACKEND_SEP + self.playgroup 392 string += BACKEND_SEP + str(self.recpriority2) 393 string += BACKEND_SEP + self.parentid 394 string += BACKEND_SEP + self.storagegroup 395 string += BACKEND_SEP + self.audio_props 396 string += BACKEND_SEP + self.video_props 397 string += BACKEND_SEP + self.subtitle_type 398 string += BACKEND_SEP + self.year 399 400 return string 401 307 402 if __name__ == '__main__': 308 403 banner = '\'m\' is a MythTV instance.' 309 404 try: -
mythtv/bindings/python/MythTV/MythDB.py
160 160 else: 161 161 return None 162 162 163 def setSetting(self, value, data, hostname=None): 164 """ 165 Sets the value for the given MythTV setting. 166 """ 167 log.Msg(DEBUG, 'Setting %s for host %s to %s', value, hostname, data) 168 c = self.db.cursor() 169 ws = None 170 ss = None 171 172 if hostname is None: 173 ws = "WHERE value LIKE ('%s') AND hostname IS NULL" % (value) 174 ss = "(value,data) VALUES ('%s','%s')" % (value, data) 175 else: 176 ws = "WHERE value LIKE ('%s') AND hostname LIKE ('%s%%')" % (value, hostname) 177 ss = "(value,data,hostname) VALUES ('%s','%s','%s')" % (value, data, hostname) 178 179 if c.execute("""UPDATE settings SET data %s LIMIT 1""" % ws) == 0: 180 c.execute("""INSERT INTO settings %s""" % ss) 181 c.close() 182 183 def getCast(self, chanid, starttime, roles=None): 184 """ 185 Returns cast members for a recording 186 A string for 'roles' will return a tuple of members for that role 187 A tuple of strings will return a touple containing all listed roles 188 No 'roles' will return a dictionary of tuples 189 """ 190 if roles is None: 191 c = self.db.cursor() 192 length = c.execute("SELECT name,role FROM people,credits WHERE people.person=credits.person AND chanid=%d AND starttime=%d ORDER BY role" % (chanid, starttime)) 193 if length == 0: 194 return () 195 crole = None 196 clist = [] 197 dict = {} 198 for name,role in c.fetchall(): 199 if crole is None: 200 crole = role 201 if crole == role: 202 clist.append(name) 203 else: 204 dict[crole] = tuple(clist) 205 clist = [] 206 clist.append(name) 207 crole = role 208 dict[crole] = tuple(clist) 209 c.close() 210 return dict 211 elif isinstance(roles,str): 212 c = self.db.cursor() 213 length = c.execute("SELECT name FROM people,credits WHERE people.person=credits.person AND chanid=%d AND starttime=%d AND role='%s'" % (chanid, starttime, roles)) 214 if length == 0: 215 return () 216 names = [] 217 for name in c.fetchall(): 218 names.append(name[0]) 219 return tuple(names) 220 elif isinstance(roles,tuple): 221 c = self.db.cursor() 222 length = c.execute("SELECT name FROM people,credits WHERE people.person=credits.person AND chanid=%d AND starttime=%d AND role IN %s" % (chanid, starttime, roles)) 223 if length == 0: 224 return () 225 names = [] 226 for name in c.fetchall(): 227 names.append(name[0]) 228 return tuple(names) 229 163 230 def cursor(self): 164 231 return self.db.cursor() 165 232 233 class Job: 234 jobid = None 235 chanid = None 236 starttime = None 237 host = None 238 mythdb = None 239 def __init__(self, *inp): 240 if len(inp) == 1: 241 self.jobid = inp[0] 242 self.getProgram() 243 elif len(inp) == 2: 244 self.chanid = inp[0] 245 self.starttime = inp[1] 246 self.getJobID() 247 else: 248 print("improper input length") 249 return None 250 self.getHost() 251 252 def getProgram(self): 253 if self.mythdb is None: 254 self.mythdb = MythDB() 255 c = self.mythdb.cursor() 256 c.execute("SELECT chanid,starttime FROM jobqueue WHERE id=%d" % self.jobid) 257 self.chanid, self.starttime = c.fetchone() 258 c.close() 259 260 def getJobID(self): 261 if self.mythdb is None: 262 self.mythdb = MythDB() 263 if self.jobid is None: 264 c = self.mythdb.cursor() 265 c.execute("SELECT id FROM jobqueue WHERE chanid=%d AND starttime=%d" % (self.chanid, self.starttime)) 266 self.jobid = c.fetchone()[0] 267 c.close() 268 return self.jobid 269 270 def getHost(self): 271 if self.mythdb is None: 272 self.mythdb = MythDB() 273 if self.host is None: 274 c = self.mythdb.cursor() 275 c.execute("SELECT hostname FROM jobqueue WHERE id=%d" % self.jobid) 276 self.host = c.fetchone()[0] 277 c.close() 278 return self.host 279 280 def setComment(self,comment): 281 if self.mythdb is None: 282 self.mythdb = MythDB() 283 c = self.mythdb.cursor() 284 c.execute("UPDATE jobqueue SET comment='%s' WHERE id=%d" % (comment,self.jobid)) 285 c.close() 286 287 def setStatus(self,status): 288 if self.mythdb is None: 289 self.mythdb = MythDB() 290 c = self.mythdb.cursor() 291 c.execute("UPDATE jobqueue SET status=%d WHERE id=%d" % (status,self.jobid)) 292 c.close() 293 166 294 if __name__ == '__main__': 167 295 banner = "'mdb' is a MythDB instance." 168 296 try: