Ticket #6678: pyth.update.patch
| File pyth.update.patch, 6.6 KB (added by , 17 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. … … 304 338 self.subtitle_type = data[45] 305 339 self.year = data[46] 306 340 341 def toString(self): 342 string = self.title 343 string += BACKEND_SEP + self.subtitle 344 string += BACKEND_SEP + self.description 345 string += BACKEND_SEP + self.category 346 if self.chanid: 347 string += BACKEND_SEP + str(self.chanid) 348 else: 349 string += BACKEND_SEP 350 string += BACKEND_SEP + self.channum 351 string += BACKEND_SEP + self.callsign 352 string += BACKEND_SEP + self.channame 353 string += BACKEND_SEP + self.filename 354 string += BACKEND_SEP + self.fs_high 355 string += BACKEND_SEP + self.fs_low 356 string += BACKEND_SEP + str(int(mktime(self.starttime.timetuple()))) 357 string += BACKEND_SEP + str(int(mktime(self.endtime.timetuple()))) 358 string += BACKEND_SEP + str(self.duplicate) 359 string += BACKEND_SEP + str(self.shareable) 360 string += BACKEND_SEP + str(self.findid) 361 string += BACKEND_SEP + self.hostname 362 string += BACKEND_SEP + str(self.sourceid) 363 string += BACKEND_SEP + str(self.cardid) 364 string += BACKEND_SEP + str(self.inputid) 365 string += BACKEND_SEP + str(self.recpriority) 366 string += BACKEND_SEP + str(self.recstatus) 367 string += BACKEND_SEP + str(self.recordid) 368 string += BACKEND_SEP + self.rectype 369 string += BACKEND_SEP + self.dupin 370 string += BACKEND_SEP + self.dupmethod 371 string += BACKEND_SEP + str(int(mktime(self.recstartts.timetuple()))) 372 string += BACKEND_SEP + str(int(mktime(self.recendts.timetuple()))) 373 string += BACKEND_SEP + str(self.repeat) 374 string += BACKEND_SEP + self.programflags 375 string += BACKEND_SEP + self.recgroup 376 string += BACKEND_SEP + str(self.commfree) 377 string += BACKEND_SEP + self.outputfilters 378 string += BACKEND_SEP + self.seriesid 379 string += BACKEND_SEP + self.programid 380 string += BACKEND_SEP + self.lastmodified 381 string += BACKEND_SEP + str(self.stars) 382 string += BACKEND_SEP + self.airdate 383 string += BACKEND_SEP + str(self.hasairdate) 384 string += BACKEND_SEP + self.playgroup 385 string += BACKEND_SEP + str(self.recpriority2) 386 string += BACKEND_SEP + self.parentid 387 string += BACKEND_SEP + self.storagegroup 388 string += BACKEND_SEP + self.audio_props 389 string += BACKEND_SEP + self.video_props 390 string += BACKEND_SEP + self.subtitle_type 391 string += BACKEND_SEP + self.year 392 393 return string 394 307 395 if __name__ == '__main__': 308 396 banner = '\'m\' is a MythTV instance.' 309 397 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
