本文整理汇总了Python中Cheetah.Template.Template.time方法的典型用法代码示例。如果您正苦于以下问题:Python Template.time方法的具体用法?Python Template.time怎么用?Python Template.time使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cheetah.Template.Template
的用法示例。
在下文中一共展示了Template.time方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ToGo
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import time [as 别名]
def ToGo(self, handler, query):
subcname = query['Container'][0]
cname = subcname.split('/')[0]
for name, data in config.getShares():
if cname == name:
if 'tivo_mak' in data:
tivo_mak = data['tivo_mak']
else:
tivo_mak = ""
if 'togo_path' in data:
togo_path = data['togo_path']
else:
togo_path = ""
if tivo_mak != "" and togo_path != "":
parse_url = urlparse(str(query['Url'][0]))
theurl = 'http://' + parse_url[1].split(':')[0] + parse_url[2] + "?" + parse_url[4]
password = tivo_mak #TiVo MAK
tivoIP = query['TiVo'][0]
name = unquote(parse_url[2])[10:300].split('.')
name.insert(-1," - " + unquote(parse_url[4]).split("id=")[1] + ".")
outfile = os.path.join(togo_path, "".join(name))
status[theurl] = {'running':True, 'error':'', 'rate':'', 'finished':False}
thread.start_new_thread(Admin.get_tivo_file, (self, theurl, password, tivoIP, outfile))
handler.send_response(200)
handler.end_headers()
t = Template(file=os.path.join(SCRIPTDIR,'templates', 'redirect.tmpl'))
t.container = cname
t.time = '3'
t.url = '/'+ query['Redirect'][0]
t.text = '<h3>Transfer Initiated.</h3> <br>You selected transfer has been initiated.'+\
'<br> The <a href="/'+ query['Redirect'][0] +'"> ToGo</a> page will reload in 3 seconds.'
handler.wfile.write(t)
else:
handler.send_response(200)
handler.end_headers()
t = Template(file=os.path.join(SCRIPTDIR,'templates', 'redirect.tmpl'))
t.container = cname
t.time = '10'
t.url = '/'+ query['Redirect'][0]
t.text = '<h3>Missing Data.</h3> <br>You must set both "tivo_mak" and "togo_path" before using this function.'+\
'<br> The <a href="/'+ query['Redirect'][0] +'"> ToGo</a> page will reload in 10 seconds.'
handler.wfile.write(t)
示例2: ToGoStop
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import time [as 别名]
def ToGoStop(self, handler, query):
parse_url = urlparse(str(query['Url'][0]))
theurl = 'http://' + parse_url[1].split(':')[0] + parse_url[2] + "?" + parse_url[4]
status[theurl]['running'] = False
subcname = query['Container'][0]
cname = subcname.split('/')[0]
handler.send_response(200)
handler.end_headers()
t = Template(file=os.path.join(SCRIPTDIR,'templates', 'redirect.tmpl'))
t.container = cname
t.time = '3'
t.url = '/'+ query['Redirect'][0]
t.text = '<h3>Transfer Stopped.</h3> <br>Your transfer has been stopped.'+\
'<br> The <a href="/'+ query['Redirect'][0] +'"> ToGo</a> page will reload in 3 seconds.'
handler.wfile.write(t)
示例3: Reset
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import time [as 别名]
def Reset(self, handler, query):
config.reset()
handler.server.reset()
if 'last_page' in query:
last_page = query['last_page'][0]
else:
last_page = 'Admin'
subcname = query['Container'][0]
cname = subcname.split('/')[0]
handler.send_response(200)
handler.end_headers()
t = Template(file=os.path.join(SCRIPTDIR,'templates', 'redirect.tmpl'))
t.container = cname
t.time = '3'
t.url = '/TiVoConnect?Command='+ last_page +'&Container=' + cname
t.text = '<h3>The pyTivo Server has been soft reset.</h3> <br>pyTivo has reloaded the pyTivo.conf'+\
'file and all changed should now be in effect. <br> The'+ \
'<a href="/TiVoConnect?Command='+ last_page +'&Container='+ cname +'"> previous</a> page will reload in 3 seconds.'
handler.wfile.write(t)
debug.debug_write(__name__, debug.fn_attr(), ['The pyTivo Server has been soft reset.'])
debug.print_conf(__name__, debug.fn_attr())
示例4: SaveNPL
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import time [as 别名]
def SaveNPL(self, handler, query):
config = ConfigParser.ConfigParser()
config.read(config_file_path)
if 'tivo_mak' in query:
config.set(query['Container'][0], 'tivo_mak', query['tivo_mak'][0])
if 'togo_path' in query:
config.set(query['Container'][0], 'togo_path', query['togo_path'][0])
f = open(config_file_path, "w")
config.write(f)
f.close()
subcname = query['Container'][0]
cname = subcname.split('/')[0]
handler.send_response(200)
handler.end_headers()
t = Template(file=os.path.join(SCRIPTDIR,'templates', 'redirect.tmpl'))
t.container = cname
t.time = '2'
t.url = '/TiVoConnect?last_page=NPL&Command=Reset&Container=' + cname
t.text = '<h3>Your Settings have been saved.</h3> <br>You settings have been saved to the pyTivo.conf file.'+\
'pyTivo will now do a <b>Soft Reset</b> to allow these changes to take effect.'+\
'<br> The <a href="/TiVoConnect?last_page=NPL&Command=Reset&Container='+ cname +'"> Reset</a> will occur in 2 seconds.'
handler.wfile.write(t)
示例5: UpdateSettings
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import time [as 别名]
def UpdateSettings(self, handler, query):
config = ConfigParser.ConfigParser()
config.read(config_file_path)
for key in query:
if key.startswith('Server.'):
section, option = key.split('.')
if option == "new__setting":
new_setting = query[key][0]
continue
if option == "new__value":
new_value = query[key][0]
continue
if query[key][0] == " ":
config.remove_option(section, option)
else:
config.set(section, option, query[key][0])
if not(new_setting == ' ' and new_value == ' '):
config.set('Server', new_setting, new_value)
sections = query['Section_Map'][0].split(']')
sections.pop() #last item is junk
for section in sections:
ID, name = section.split('|')
if query[ID][0] == "Delete_Me":
config.remove_section(name)
continue
if query[ID][0] != name:
config.remove_section(name)
config.add_section(query[ID][0])
for key in query:
if key.startswith(ID + '.'):
junk, option = key.split('.')
if option == "new__setting":
new_setting = query[key][0]
continue
if option == "new__value":
new_value = query[key][0]
continue
if query[key][0] == " ":
config.remove_option(query[ID][0], option)
else:
config.set(query[ID][0], option, query[key][0])
if not(new_setting == ' ' and new_value == ' '):
config.set(query[ID][0], new_setting, new_value)
if query['new_Section'][0] != " ":
config.add_section(query['new_Section'][0])
f = open(config_file_path, "w")
config.write(f)
f.close()
subcname = query['Container'][0]
cname = subcname.split('/')[0]
handler.send_response(200)
handler.end_headers()
t = Template(file=os.path.join(SCRIPTDIR,'templates', 'redirect.tmpl'))
t.container = cname
t.time = '10'
t.url = '/TiVoConnect?Command=Admin&Container=' + cname
t.text = '<h3>Your Settings have been saved.</h3> <br>You settings have been saved to the pyTivo.conf file.'+\
'However you will need to do a <b>Soft Reset</b> before these changes will take effect.'+\
'<br> The <a href="/TiVoConnect?Command=Admin&Container='+ cname +'"> Admin</a> page will reload in 10 seconds.'
handler.wfile.write(t)
示例6: NPL
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import time [as 别名]
def NPL(self, handler, query):
shows_per_page = 50 #Change this to alter the number of shows returned per page
subcname = query['Container'][0]
cname = subcname.split('/')[0]
folder = ''
AnchorItem = ''
AnchorOffset= ''
for name, data in config.getShares():
if cname == name:
if 'tivo_mak' in data:
tivo_mak = data['tivo_mak']
else:
tivo_mak = ""
if 'togo_path' in data:
togo_path = data['togo_path']
else:
togo_path = ""
if 'TiVo' in query:
tivoIP = query['TiVo'][0]
theurl = 'https://'+ tivoIP +'/TiVoConnect?Command=QueryContainer&ItemCount='+ str(shows_per_page) +'&Container=/NowPlaying'
if 'Folder' in query:
folder += str(query['Folder'][0])
theurl += '/' + folder
if 'AnchorItem' in query:
AnchorItem += str(query['AnchorItem'][0])
theurl += '&AnchorItem=' + quote(AnchorItem)
if 'AnchorOffset' in query:
AnchorOffset += str(query['AnchorOffset'][0])
theurl += '&AnchorOffset=' + AnchorOffset
password = tivo_mak #TiVo MAK
r=urllib2.Request(theurl)
auth_handler = urllib2.HTTPDigestAuthHandler()
auth_handler.add_password('TiVo DVR', tivoIP, 'tivo', password)
opener = urllib2.build_opener(auth_handler)
urllib2.install_opener(opener)
if theurl in tivo_cache: #check to see if we have accessed this page before
if tivo_cache[theurl]['thepage'] == '' or (time.time() - tivo_cache[theurl]['thepage_time']) >= 60: #if page is empty or old then retreive it
try:
handle = urllib2.urlopen(r)
except IOError, e:
handler.send_response(200)
handler.end_headers()
t = Template(file=os.path.join(SCRIPTDIR,'templates', 'redirect.tmpl'))
t.container = cname
t.time = '20'
t.url = '/TiVoConnect?Command=NPL&Container=' + cname
t.text = '<h3>Unable to Connect to TiVo.</h3> <br>pyTivo was unable to connect to the TiVo at ' + tivoIP +\
'<br>This most likely caused by an incorrect Media Access Key. Please return to the ToGo page and double check your Media Access Key.' +\
'<br> The <a href="/TiVoConnect?Command=NPL&Container='+ cname + '"> ToGo</a> page will reload in 20 seconds.'
handler.wfile.write(t)
return
tivo_cache[theurl]['thepage'] = handle.read()
tivo_cache[theurl]['thepage_time'] = time.time()
else: #not in cache
try:
handle = urllib2.urlopen(r)
except IOError, e:
handler.send_response(200)
handler.end_headers()
t = Template(file=os.path.join(SCRIPTDIR,'templates', 'redirect.tmpl'))
t.container = cname
t.time = '20'
t.url = '/TiVoConnect?Command=NPL&Container=' + cname
t.text = '<h3>Unable to Connect to TiVo.</h3> <br>pyTivo was unable to connect to the TiVo at ' + tivoIP +\
'<br>This most likely caused by an incorrect Media Access Key. Please return to the ToGo page and double check your Media Access Key.' +\
'<br> The <a href="/TiVoConnect?Command=NPL&Container='+ cname + '"> ToGo</a> page will reload in 20 seconds.'
handler.wfile.write(t)
return
tivo_cache[theurl] = {}
tivo_cache[theurl]['thepage'] = handle.read()
tivo_cache[theurl]['thepage_time'] = time.time()