本文整理汇总了Python中model.User.nickname方法的典型用法代码示例。如果您正苦于以下问题:Python User.nickname方法的具体用法?Python User.nickname怎么用?Python User.nickname使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.User
的用法示例。
在下文中一共展示了User.nickname方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import nickname [as 别名]
def __init__(self, username = 'root', password = None):
'''
Try to create the database when there is none
initialize 'root' user and 'root' & 'primary' group
'''
try:
User.query.all()
except:
db.create_all()
if password == None:
#set a random password
password = os.urandom(16)
password = b64encode(password).decode('utf-8')
fsdir = env.getenv('FS_PREFIX')
f = open(fsdir + '/local/generated_password.txt', 'w')
f.write("User=%s\nPass=%s\n"%(username, password))
f.close()
sys_admin = User(username, hashlib.sha512(password.encode('utf-8')).hexdigest())
sys_admin.status = 'normal'
sys_admin.nickname = 'root'
sys_admin.description = 'Root_User'
sys_admin.user_group = 'root'
sys_admin.auth_method = 'local'
db.session.add(sys_admin)
path = env.getenv('DOCKLET_LIB')
subprocess.call([path+"/userinit.sh", username])
db.session.commit()
if not os.path.exists(fspath+"/global/sys/quota"):
groupfile = open(fspath+"/global/sys/quota",'w')
groups = []
groups.append({'name':'root', 'quotas':{ 'cpu':'4', 'disk':'2000', 'data':'100', 'memory':'2000', 'image':'10', 'idletime':'24', 'vnode':'8' }})
groups.append({'name':'admin', 'quotas':{'cpu':'4', 'disk':'2000', 'data':'100', 'memory':'2000', 'image':'10', 'idletime':'24', 'vnode':'8'}})
groups.append({'name':'primary', 'quotas':{'cpu':'4', 'disk':'2000', 'data':'100', 'memory':'2000', 'image':'10', 'idletime':'24', 'vnode':'8'}})
groups.append({'name':'foundation', 'quotas':{'cpu':'4', 'disk':'2000', 'data':'100', 'memory':'2000', 'image':'10', 'idletime':'24', 'vnode':'8'}})
groupfile.write(json.dumps(groups))
groupfile.close()
if not os.path.exists(fspath+"/global/sys/quotainfo"):
quotafile = open(fspath+"/global/sys/quotainfo",'w')
quotas = {}
quotas['default'] = 'foundation'
quotas['quotainfo'] = []
quotas['quotainfo'].append({'name':'cpu', 'hint':'the cpu quota, number of cores, e.g. 4'})
quotas['quotainfo'].append({'name':'memory', 'hint':'the memory quota, number of MB , e.g. 4000'})
quotas['quotainfo'].append({'name':'disk', 'hint':'the disk quota, number of MB, e.g. 4000'})
quotas['quotainfo'].append({'name':'data', 'hint':'the quota of data space, number of GB, e.g. 100'})
quotas['quotainfo'].append({'name':'image', 'hint':'how many images the user can save, e.g. 10'})
quotas['quotainfo'].append({'name':'idletime', 'hint':'will stop cluster after idletime, number of hours, e.g. 24'})
quotas['quotainfo'].append({'name':'vnode', 'hint':'how many containers the user can have, e.g. 8'})
quotafile.write(json.dumps(quotas))
quotafile.close()
示例2: __init__
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import nickname [as 别名]
def __init__(self, username = 'root', password = None):
'''
Try to create the database when there is none
initialize 'root' user and 'root' & 'primary' group
'''
try:
User.query.all()
UserGroup.query.all()
except:
db.create_all()
root = UserGroup('root')
db.session.add(root)
db.session.commit()
if password == None:
#set a random password
password = os.urandom(16)
password = b64encode(password).decode('utf-8')
fsdir = env.getenv('FS_PREFIX')
f = open(fsdir + '/local/generated_password.txt', 'w')
f.write("User=%s\nPass=%s\n"%(username, password))
f.close()
sys_admin = User(username, hashlib.sha512(password.encode('utf-8')).hexdigest())
sys_admin.status = 'normal'
sys_admin.nickname = 'root'
sys_admin.description = 'Root_User'
sys_admin.user_group = 'root'
sys_admin.auth_method = 'local'
db.session.add(sys_admin)
path = env.getenv('DOCKLET_LIB')
subprocess.call([path+"/userinit.sh", username])
db.session.commit()
admin = UserGroup('admin')
primary = UserGroup('primary')
db.session.add(admin)
db.session.add(primary)
db.session.commit()
示例3: import_data
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import nickname [as 别名]
def import_data():
model.clean_model("User", model.user_key())
model.clean_model("Day", model.day_key())
model.clean_model("Price", model.price_key())
data = fetch_data()
users = []
days = []
prices = []
user_by_index = dict()
user_by_nickname = dict()
# extracting users
for index, nickname in enumerate(data[0]):
if not nickname in [None, "Date", "", "Group Ticket"]:
user_id = nickname.lower() + "@swiftkey.net"
if nickname == "James":
user_id = "[email protected]"
user_by_index[index] = user_id
user_by_nickname[nickname] = user_id
users.append({'nickname': nickname, 'user_id': user_id})
user = User(parent=model.user_key())
user.nickname = nickname.strip()
user.user_id = user_id.strip()
user.put()
# extracting days
for row in data:
if not row[0] in ['', None, 'Date', 'BALANCE']:
date = None
custom_price = None
buyer = None
users_for_day = {}
guests = {}
for index, val in enumerate(row):
if index == 0:
date = datetime.datetime.strptime(val, "%m/%d/%Y").date()
if index == 1 and is_number(val):
custom_price = float(val)
if index > 1 and index < 20 and index % 2 == 0:
if val == 'Norm' or val == 'Yes' or val == 'Late' or val == 'No':
user_id = user_by_index[index]
users_for_day[user_id] = val
if index == 20 and val != None and val != '---':
buyer = user_by_nickname[val.strip()]
days.append({'date': date, 'price': custom_price, 'buyer': buyer, 'users': users_for_day, 'guests': guests})
day = Day(parent=model.day_key())
day.date = date
day.price = custom_price
day.buyer = buyer
day.users = json.dumps(users_for_day)
day.guests = json.dumps(guests)
day.put()
# extracting prices
prices.append({'since': datetime.date(2013, 1, 1), 'prices': {3: 45.60, 4: 46.00, 5: 69.00, 6: 91.20, 7: 91.60, 8: 92.00}})
# TODO: remove when done
return {'users': users, 'prices': prices, 'days': days}