本文整理汇总了Python中database.DatabaseManager类的典型用法代码示例。如果您正苦于以下问题:Python DatabaseManager类的具体用法?Python DatabaseManager怎么用?Python DatabaseManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DatabaseManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: backuper
def backuper():
"""
Backs up each item in backup list.
"""
# start logging
logging.info('Starting backups')
# bring in the backups
db = DatabaseManager(BACKUP_FILE_PATH)
logging.debug('Database loaded')
sql = 'SELECT * FROM backups'
backup_list = db.select(sql, None)
# backup schema:
# [0]coordinate, [1]name, [2]owner, [3]active, [4]backup_times
for entry in backup_list:
# Is this planet being actively backed up?
if not entry[3]:
# nope, skip it
continue
# perform the backup action
perform_backup(db, entry)
# update log to reflect new backup
prune_backups(db, entry)
logging.info('Backups completed.')
logging.info('=====================================================.')
示例2: register
def register():
db_manager = DatabaseManager()
username = request.json.get('username')
password = sha512_crypt.encrypt(request.json.get('password'), salt=app.config['SECURITY_PASSWORD_SALT'], rounds=5000)
email = request.json.get('email')
# Check if everything filled in
if username is None or password is None or email is None:
return abort(400) # missing arguments
# Check if already exists
elif db_manager.username_exists(username) or db_manager.email_exists(email):
# username and/or email do already exist
return response_cache_header("ERROR, username and/or email do already exist", cache_control="no-cache")
else:
db_manager.create_user(username=username, password_hash=password, email=email, email_verified=False)
# Email verification
token = generate_confirmation_token(email)
confirm_url = url_for('verify_email', token=token, _external=True)
html = render_template('email.html', confirm_url=confirm_url)
subject = "Please confirm your email"
send_email(email, subject, html)
return response_cache_header("Successfully created user, please verify email.\n", cache_control="no-cache")
示例3: get_dbm
class get_dbm(object):
def __enter__(self):
self.dbm = DatabaseManager(config.DB_HOST, config.DB_USER, config.DB_PASSWORD, config.DB_NAME)
return self.dbm
def __exit__(self, type, value, traceback):
self.dbm.close()
示例4: _add_message
def _add_message(self, data):
database = DatabaseManager()
security = Security()
user = security.user
password = security.password
database.connect(dialect=self.dialect, user=user, passwd=password, database=self.db)
database.add_messages(data)
示例5: get_friends
def get_friends():
db_manager = DatabaseManager()
username = request.json.get("username").lower()
token = request.json.get("token")
if username == None or token == None:
abort(400)
# Verifiy token
token_credentials = db_manager.verify_auth_token(token=token)
if token_credentials is None:
abort(401)
elif not db_manager.check_password(token_credentials[0], token_credentials[1]):
abort(401)
elif token_credentials[0] != username:
abort(401)
friends = db_manager.get_friends_for_user(username)
# It is unsafe to send your friends password hash to the browser... email_verified and id aren't needed
for friend in friends:
if friend == None:
friends.remove(friend)
continue
del friend["password_hash"]
del friend["email_verified"]
del friend["id"]
return response_cache_header(json.dumps({"friends": friends}))
示例6: change_status
def change_status(self):
self.engine.conv_state = not self.engine.conv_state
DatabaseManager.set_current_state(self.engine.conv_state)
if self.engine.conv_state:
self.show_on_status()
self.load_keyboard()
else:
self.show_off_status()
示例7: accept_friend
def accept_friend(token):
db_manager = DatabaseManager()
names = confirm_token(token)
if db_manager.users_are_friends(names[0], names[1]):
return response_cache_header("Already friends", cache_control="no-cache")
else:
db_manager.create_friendship(names[0], names[1])
return response_cache_header("Now friends", cache_control="no-cache")
示例8: accept_friend
def accept_friend(token):
db_manager = DatabaseManager()
names = confirm_token(token)
if db_manager.users_are_friends(names[0], names[1]):
return "Already friends"
else:
db_manager.create_friendship(names[0], names[1])
return "Now friends"
示例9: verify_email
def verify_email(token):
db_manager = DatabaseManager()
email = confirm_token(token)
if db_manager.email_is_verified(email):
return response_cache_header("Email already verified.\n", cache_control="no-cache")
else:
# Verify
db_manager.verify_email(email)
return response_cache_header("Email Successfully verified.\n", cache_control="no-cache")
示例10: verify_email
def verify_email(token):
db_manager = DatabaseManager()
email = confirm_token(token)
if db_manager.email_is_verified(email):
return "Email already verified.\n"
else:
# Verify
db_manager.verify_email(email)
return "Email Successfully verified.\n"
示例11: ok_file
def ok_file(self, button, filesel):
path = filesel.get_filename()
mdpath = join(dirname(path), 'machine_database.xml')
action = filesel.get_data('action')
filesel.destroy()
dir = dirname(path)
dbm = DatabaseManager(self.conn)
if action == 'backup':
dbm.backup(dir)
elif action == 'restore':
dbm.restore(dir)
示例12: init_combobox
def init_combobox(self):
self.keyboard_cbox.blockSignals(True)
self.keyboard_cbox.clear()
current_keyboard = DatabaseManager.get_current_keyboard()
index = 0
for keyboard in DatabaseManager.get_all_keyboards()[1]:
self.keyboard_cbox.addItem(keyboard.language_name, keyboard.id)
if int(current_keyboard) == keyboard.id:
self.keyboard_cbox.setCurrentText(keyboard.language_name)
self.keyboard_cbox.setCurrentIndex(index)
index += 1
self.keyboard_cbox.blockSignals(False)
示例13: cli
def cli(ctx, verbose, no_prompts):
ctx.obj = dict() # Context object that stores application state in dict, could make class at some point
ctx.obj['VERBOSE'] = verbose
ctx.obj['NO_PROMPTS'] = no_prompts
# Check for ucon64
try:
devnull = open(os.devnull)
subprocess.Popen(['ucon64'], stdout=devnull, stderr=devnull).communicate()
except OSError as e:
if e.errno == os.errno.ENOENT:
click.echo("WARNING: ucon64 not installed. Required for NES, SNES and N64 rom info.")
# Check for data root
if not os.path.exists(LOCAL_DATA_ROOT):
click.echo("Local data root not found, creating {}".format(LOCAL_DATA_ROOT))
os.makedirs(LOCAL_DATA_ROOT)
# Check for tables, extracted, game citation and performance citation
dbm.create_tables()
# Check for data directory
for data_path, path_name in ((LOCAL_GAME_DATA_STORE, "game data"), (LOCAL_CITATION_DATA_STORE, "citation data")):
if not os.path.exists(data_path):
click.echo("Local {} store: '{}' not found, creating...".format(path_name, data_path))
os.makedirs(data_path)
示例14: createCharacter
def createCharacter(account, name, model):
if hasPlayer(name):
raise CharacterAlreadyExists()
try:
ID = idFactory.createID()
# these values are only for test puporse, must be tested and fixed
# all players stats must be saved on DB
if model == 1:
spd = 2
df = 2
fc = 2
hp = 300
elif model == 2:
spd = 1
df = 2
fc = 3
hp = 350
elif model == 3:
spd = 3
df = 1
fc = 2
hp = 250
DB.getInstance().query("INSERT INTO Players (ID, account, name, speed, defense, `force`, maxHp, hp, model)" \
"Values (%s,%s,%s,%s,%s,%s,%s,%s,%s)",(ID,account,name,spd,df,fc,hp,hp,model))
except Exception, e:
print e
return False
示例15: add_rl_save_state_data
def add_rl_save_state_data(uuid):
rl_starts_b64 = request.form.get('rl_starts')
rl_lengths_b64 = request.form.get('rl_lengths')
rl_total_length = int(request.form.get('rl_total_length'))
rl_lengths_length = int(request.form.get('rl_lengths_length'))
rl_starts_length = int(request.form.get('rl_starts_length'))
rl_starts_b_array = bytearray(base64.b64decode(rl_starts_b64))
rl_lengths_b_array = bytearray(base64.b64decode(rl_lengths_b64))
if len(rl_starts_b_array) != rl_starts_length:
rl_starts_b_array.extend([0 for _ in range(len(rl_starts_b_array), rl_starts_length)])
if len(rl_lengths_b_array) != rl_lengths_length:
rl_lengths_b_array.extend([0 for _ in range(len(rl_lengths_b_array), rl_lengths_length)])
rl_start_hash, file_name = save_byte_array_to_store(rl_starts_b_array, file_name=uuid)
rl_lengths_hash, file_name = save_byte_array_to_store(rl_lengths_b_array, file_name=uuid)
dbm.update_table(dbm.GAME_SAVE_TABLE,
['rl_starts_data','rl_lengths_data','rl_total_length','compressed'],
[rl_start_hash, rl_lengths_hash, rl_total_length, True],
['uuid'], [uuid])
return jsonify({'record': dbm.retrieve_save_state(uuid=uuid)[0]})