本文整理汇总了Python中messages.Messages类的典型用法代码示例。如果您正苦于以下问题:Python Messages类的具体用法?Python Messages怎么用?Python Messages使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Messages类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete
def delete(self, key):
if auth.user_is_admin():
Idea.get(key).delete()
else:
Messages.add('Only and administrator may delete submitted ideas. ' +
'This incident has been logged.')
return self.redirect('/ideas')
示例2: signup
def signup(self):
user = auth.User(auth.current_user())
if user.in_group():
Messages.add('You are already in a group')
return self.redirect('/groups')
else:
return self.render('groups_signup')
示例3: create
def create(self):
"""Handles the POST data for creating a group.
Form Variables:
name: the name of the new group
public: true if the group should be joinable by the public
"""
if auth.logged_in():
name = self.request.get('name')
public = self.request.get('public') == 'public'
owner = auth.current_user()
if Group.exists(name):
Messages.add('A group with that name already exists')
return self.redirect('/groups/signup')
Group(name=name,
public=public,
owner=owner,
members=[owner]).put()
return self.redirect('/groups')
else:
Messages.add('You must be logged in to create a group')
return self.redirect('/groups/signup')
示例4: get
def get(self):
generate_nml_out = subprocess.check_output('do_generate_collection_nml', shell=True, stderr=subprocess.STDOUT)
Messages.add_message(generate_nml_out, 'success')
install = 'install -m 0775 -g traktor output.nml /mnt/disk_array/traktor/TraktorProRootDirectory/new-collection.nml'
subprocess.call(install, shell=True, stderr=subprocess.STDOUT)
current_route.CURRENT_ROUTE = 'push'
示例5: EventHandler
class EventHandler(object):
def __init__(self):
self.dict = OrderedDict()
self.dict['a'] = False
self.dict['b'] = False
self.dict['c'] = False
self.dict['d'] = False
self.dict['e'] = False
self.dict['f'] = False
self.messages = Messages()
# 向服务器发送item
def send(self):
for key in self.dict:
value = self.dict[key]
if not value:
self.item = key
break
if self.dict[key]:
return
host = self.messages.getValue("socket1", "host")
port = int(self.messages.getValue("socket1", "port"))
params = (("deliverItem", self.item), self.sendCallBack)
# 检查当前item在服务器的状态,7次
Thread(target=TCPClient(host, port).send, args=params).start()
self.check(self.item)
def sendCallBack(self, params):
if params[1]:
print("Send", params[0], "成功")
elif len(params) == 3:
print("Send", params[0], "出现异常", params[2])
# 轮询检查服务器端item的还行状况,7次
def check(self, item):
totalTimes = 7
times = 0
while times < totalTimes:
time.sleep(1)
if self.dict[item]:
return
host = self.messages.getValue("socket2", "host")
port = int(self.messages.getValue("socket2", "port"))
params = (("checkItemStatus", item), self.checkCallBack)
Thread(target=TCPClient(host, port).send, args=params).start()
times += 1
else:
print("已经对", item, "发起", totalTimes, "次校验,没有结果. 任务终止.")
def checkCallBack(self, params):
if params[1]:
self.dict[params[0]] = params[1]
print("Check", params[0], "成功。当前队列状态为:", self.dict.items())
self.send()
elif len(params) == 3:
print("Check", params[0], "出现异常:", params[2])
else:
print("Check", params[0], "未得到结果")
示例6: do_push_artists
def do_push_artists(self):
# patch credentials
if not request.headers.get('Authorization'):
abort(401)
else:
auth = request.headers['Authorization'].lstrip('Basic ')
username, password = base64.b64decode(auth).split(':')
if username and password:
conf.CHIRPRADIO_AUTH = '%s %s' % (username, password)
chirpradio.connect()
else:
abort(401)
dry_run = False
# reload artists from file
artists._init()
# Find all of the library artists
all_library_artists = set(artists.all())
# Find all of the artists in the cloud.
all_chirpradio_artists = set()
mapped = 0
t1 = time.time()
for art in models.Artist.fetch_all():
if art.revoked:
continue
std_name = artists.standardize(art.name)
if std_name != art.name:
#print "Mapping %d: %s => %s" % (mapped, art.name, std_name)
mapped += 1
art.name = std_name
idx = search.Indexer()
idx._transaction = art.parent_key()
idx.add_artist(art)
if not dry_run:
idx.save()
all_chirpradio_artists.add(art.name)
to_push = list(all_library_artists.difference(all_chirpradio_artists))
Messages.add_message("Pushing %d artists" % len(to_push), 'warning')
while to_push:
# Push the artists in batches of 50
this_push = to_push[:50]
to_push = to_push[50:]
idx = search.Indexer()
for name in this_push:
#print name
art = models.Artist.create(parent=idx.transaction, name=name)
idx.add_artist(art)
if not dry_run:
idx.save()
#print "+++++ Indexer saved"
Messages.add_message("Artist push complete. OK!", 'success')
示例7: update_group
def update_group(self, key):
if not auth.logged_in():
return self.redirect('/groups')
user = auth.current_user()
group = Group.get(key)
if group.owner.user_id() != user.user_id() and not auth.user_is_admin():
Messages.add('Only the owner of the group owner may modify it')
return self.redirect('/groups')
name = self.request.get('name')
public = self.request.get('public') == 'public'
abandon = self.request.get('abandon-project')
sub_text = self.request.get('submission-text')
sub_url = self.request.get('submission-url')
remove_submission = self.request.get_all('remove-submission')
remove = self.request.get_all('remove')
owner = self.request.get('owner')
delete = self.request.get('delete')
if delete:
group.delete()
return self.redirect('/groups')
group.name = name
group.public = public
if abandon:
group.project = None
if sub_text and sub_url:
Submission(text=sub_text, url=sub_url, group=group).put()
for sub in Submission.get(remove_submission):
sub.delete()
pending = list(group.pending_users)
for user in pending:
approve = self.request.get("approve-%s" % user)
if approve == "approve":
group.members.append(user)
group.pending_users.remove(user)
elif approve == "refuse":
group.pending_users.remove(user)
group.owner = auth.user_from_email(owner)
for user in remove:
if auth.user_from_email(user) == group.owner:
Messages.add('Cannot remove the group owner')
return self.redirect('/groups/%s/edit' % key)
else:
group.members.remove(auth.user_from_email(user))
group.put()
return self.redirect('/groups/%s' % key)
示例8: edit
def edit(self, key):
if not auth.logged_in():
return self.redirect('/groups')
user = auth.current_user()
group = Group.get(key)
if group.owner.user_id() == user.user_id() or auth.user_is_admin():
return self.render('groups_edit', { 'group': group })
else:
Messages.add('Only the owner of this group may edit it')
return self.redirect('/groups/%s' % key)
示例9: leave
def leave(self, key):
group = Group.get(key)
user = auth.User(auth.current_user())
if user.group != group:
Messages.add('You cannot leave a group you are not in')
return self.redirect('/groups/%s' % key)
group.members.remove(user.gae_user)
group.put()
return self.redirect('/groups')
示例10: claim
def claim(self, key):
user = auth.User(auth.current_user())
group = user.group
if group.owner.user_id() == auth.current_user().user_id():
project = Project.get(key)
group.project = project
group.put()
return self.redirect('/groups/%s' % group.key())
else:
Messages.add('You are not the owner of your group. Only the ' +
'owner of the group may select a project.')
return self.redirect('/projects')
示例11: approve
def approve(self, key):
if auth.user_is_admin():
idea = Idea.get(key)
Project(name=idea.name,
description=idea.description,
author=idea.author,
post_time=idea.post_time).put()
idea.delete()
return self.redirect('/projects')
else:
Messages.add('Only and administrator may approve submitted ' +
'ideas. This incident has been logged.')
return self.redirect('/ideas')
示例12: render
def render(self, template_name, data={}):
"""Renders the template in the site wide manner.
Retrieves the template data needed for the base template (login URL and
text, user information, etc.) and merges it with the data passed to the
method. Templates are retrieved from the template directory specified
in the settings and appended with the suffix ".html"
Arguments:
template_name: the name of the template. this is the file name of the
template without the .html extension.
data: a dictionary containing data to be passed to the template.
"""
(login_text, login_url) = auth.login_logout(self.request)
if auth.logged_in():
data['user'] = auth.User(auth.current_user())
data['admin'] = auth.user_is_admin()
data['login_url'] = login_url
data['login_text'] = login_text
data['messages'] = Messages.get()
path = os.path.join(settings.BASE_DIR, settings.TEMPLATE_DIR,
"%s.html" % template_name)
return self.response.out.write(template.render(path, data))
示例13: restart
def restart(): # this really could be health
lock = None
try:
lock = LockFile('json/health.json', 'r')
lock.acquire()
with open('json/health.json', 'r') as json_file:
data = json.load(json_file, encoding='utf-8')
if request.method == 'POST':
status = request.args.get('status', type=str)
if status is None:
print 'no status given, defaults to true'
status = 'true'
data['restart'] = status
with open('json/health.json', 'w') as json_file:
json_file.write(json.dumps(data))
lock.release()
return 'restart set to %s' % status
if request.method == 'GET':
lock.release()
return data['restart']
except IOError:
if lock is not None:
lock.release()
return Messages.inventoryNotFound()
示例14: dump_dropbox
def dump_dropbox(self):
drop = chirp.library.dropbox.Dropbox()
result = []
for path in sorted(drop._dirs):
try:
chirp_albums = chirp.library.album.from_directory(path, fast=True)
except (IOError, chirp.library.album.AlbumError), e:
Messages.add_message('There was an error at %s.' % path, 'error')
# propagate error to ui so the album may be removed
result.append({'path': path, 'title': 'There was an error at %s' % path, 'error': True})
continue
# build albums
for album in chirp_albums:
json = album_to_json(album, path)
result.append(json)
示例15: __init__
def __init__(self):
self.dict = OrderedDict()
self.dict['a'] = False
self.dict['b'] = False
self.dict['c'] = False
self.dict['d'] = False
self.dict['e'] = False
self.dict['f'] = False
self.messages = Messages()