本文整理汇总了Python中database.DBSession.commit方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.commit方法的具体用法?Python DBSession.commit怎么用?Python DBSession.commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类database.DBSession
的用法示例。
在下文中一共展示了DBSession.commit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete_all_installations_for_host
# 需要导入模块: from database import DBSession [as 别名]
# 或者: from database.DBSession import commit [as 别名]
def delete_all_installations_for_host(hostname, status=None):
if not can_delete_install(current_user):
abort(401)
db_session = DBSession()
host = get_host(db_session, hostname)
if host is None:
abort(404)
try:
install_jobs = db_session.query(InstallJob).filter(
InstallJob.host_id == host.id, InstallJob.status == status).all()
if not install_jobs:
return jsonify(status="No record fits the delete criteria.")
for install_job in install_jobs:
db_session.delete(install_job)
if status == JobStatus.FAILED:
delete_install_job_dependencies(db_session, install_job.id)
db_session.commit()
return jsonify({'status': 'OK'})
except:
logger.exception('delete_install_job() hit exception')
return jsonify({'status': 'Failed: check system logs for details'})
示例2: scheduling
# 需要导入模块: from database import DBSession [as 别名]
# 或者: from database.DBSession import commit [as 别名]
def scheduling(self, scheduler, daily_time):
# First, re-set up the scheduler for the next day the same time. It is important to have
# this logic on the top so that if any error encountered below, the scheduling still works.
t = datetime.datetime.combine(datetime.datetime.now() + datetime.timedelta(days=1), daily_time)
scheduler.enterabs(time.mktime(t.timetuple()), 1, self.scheduling, (scheduler, daily_time,))
db_session = DBSession()
try:
system_option = SystemOption.get(db_session)
# If software inventory is enabled, submit the inventory jobs
if system_option.enable_inventory:
inventory_jobs = db_session.query(InventoryJob).all()
if len(inventory_jobs)> 0:
for inventory_job in inventory_jobs:
inventory_job.pending_submit = True
db_session.commit()
#Check if there is any housekeeping work to do
self.perform_housekeeping_tasks(db_session, system_option)
except:
logger.exception('InventoryManagerScheduler hit exception')
finally:
db_session.close()
示例3: refresh_all
# 需要导入模块: from database import DBSession [as 别名]
# 或者: from database.DBSession import commit [as 别名]
def refresh_all(cls):
"""
Retrieves all the catalog data and SMU XML file data and updates the database.
"""
db_session = DBSession()
catalog = SMUInfoLoader.get_catalog_from_cco()
if len(catalog) > 0:
system_option = SystemOption.get(db_session)
try:
# Remove all rows first
db_session.query(CCOCatalog).delete()
for platform in catalog:
releases = catalog[platform]
for release in releases:
cco_catalog = CCOCatalog(platform=platform,release=release)
db_session.add(cco_catalog)
SMUInfoLoader(platform, release)
system_option.cco_lookup_time = datetime.datetime.utcnow()
db_session.commit()
return True
except Exception:
logger.exception('refresh_all() hit exception')
db_session.rollback()
return False
示例4: api_create_tar_job
# 需要导入模块: from database import DBSession [as 别名]
# 或者: from database.DBSession import commit [as 别名]
def api_create_tar_job():
db_session = DBSession()
form = CreateTarForm(request.form)
server_id = request.args.get('server')
server_directory = request.args.get('server_directory')
source_tars = request.args.getlist('source_tars[]')
contents = request.args.getlist('tar_contents[]')
additional_packages = request.args.getlist('additional_packages[]')
new_tar_name = request.args.get('new_tar_name').strip('.tar')
create_tar_job = CreateTarJob(
server_id = server_id,
server_directory = server_directory,
source_tars = (',').join(source_tars),
contents = (',').join(contents),
additional_packages = (',').join(additional_packages),
new_tar_name = new_tar_name,
created_by = current_user.username,
status = 'Job Submitted.')
db_session.add(create_tar_job)
db_session.commit()
job_id = create_tar_job.id
return jsonify({'status': 'OK', 'job_id': job_id})
示例5: user_create
# 需要导入模块: from database import DBSession [as 别名]
# 或者: from database.DBSession import commit [as 别名]
def user_create():
if not can_create_user(current_user):
abort(401)
form = UserForm(request.form)
# Need to add the Required flag back as it is globally removed during user_edit()
add_validator(form.password, Required)
fill_user_privileges(form.privilege.choices)
if request.method == 'POST' and form.validate():
db_session = DBSession()
user = get_user(db_session, form.username.data)
if user is not None:
return render_template('user/edit.html', form=form, duplicate_error=True)
user = User(
username=form.username.data,
password=form.password.data,
privilege=form.privilege.data,
fullname=form.fullname.data,
email=form.email.data)
user.preferences.append(Preferences())
db_session.add(user)
db_session.commit()
return redirect(url_for('home'))
else:
# Default to Active
form.active.data = True
return render_template('user/edit.html', form=form)
示例6: user_preferences
# 需要导入模块: from database import DBSession [as 别名]
# 或者: from database.DBSession import commit [as 别名]
def user_preferences():
db_session = DBSession()
form = PreferencesForm(request.form)
user = get_user_by_id(db_session, current_user.id)
if request.method == 'POST' and form.validate():
user.preferences[0].cco_username = form.cco_username.data
if len(form.cco_password.data) > 0:
user.preferences[0].cco_password = form.cco_password.data
# All the checked checkboxes (i.e. platforms and releases to exclude).
values = request.form.getlist('check')
excluded_platform_list = ','.join(values)
preferences = Preferences.get(db_session, current_user.id)
preferences.excluded_platforms_and_releases = excluded_platform_list
db_session.commit()
return redirect(url_for('home'))
else:
preferences = user.preferences[0]
form.cco_username.data = preferences.cco_username
if not is_empty(user.preferences[0].cco_password):
form.password_placeholder = 'Use Password on File'
else:
form.password_placeholder = 'No Password Specified'
return render_template('cco/preferences.html', form=form,
platforms_and_releases=get_platforms_and_releases_dict(db_session))
示例7: command_profile_create
# 需要导入模块: from database import DBSession [as 别名]
# 或者: from database.DBSession import commit [as 别名]
def command_profile_create():
db_session = DBSession()
form = CustomCommandProfileForm(request.form)
if request.method == 'POST' and form.validate():
command_profile = get_command_profile(db_session, form.profile_name.data)
if command_profile is not None:
return render_template('custom_command/command_profile_edit.html',
form=form, duplicate_error=True)
command_profile = CustomCommandProfile(
profile_name=form.profile_name.data,
command_list=','.join([l for l in form.command_list.data.splitlines() if l]),
created_by=current_user.username
)
db_session.add(command_profile)
db_session.commit()
return redirect(url_for('custom_command.home'))
else:
return render_template('custom_command/command_profile_edit.html',
form=form)
示例8: software_profile_edit
# 需要导入模块: from database import DBSession [as 别名]
# 或者: from database.DBSession import commit [as 别名]
def software_profile_edit(profile_name):
db_session = DBSession()
software_profile = get_software_profile(db_session, profile_name)
if software_profile is None:
abort(404)
form = SoftwareProfileForm(request.form)
server_dialog_form = ServerDialogForm(request.form)
fill_servers(server_dialog_form.server_dialog_server.choices, get_server_list(db_session), False)
if request.method == 'POST' and form.validate():
if profile_name != form.profile_name.data and \
get_software_profile(db_session, form.profile_name.data) is not None:
return render_template('conformance/profile_edit.html',
form=form, server_dialog_form=server_dialog_form,
system_option=SystemOption.get(db_session), duplicate_error=True)
software_profile.name = form.profile_name.data
software_profile.description = form.description.data
software_profile.packages = ','.join([l for l in form.software_packages.data.splitlines() if l]),
db_session.commit()
return redirect(url_for('conformance.home'))
else:
form.profile_name.data = software_profile.name
form.description.data = software_profile.description
if software_profile.packages is not None:
form.software_packages.data = '\n'.join(software_profile.packages.split(','))
return render_template('conformance/profile_edit.html',
form=form, server_dialog_form=server_dialog_form,
system_option=SystemOption.get(db_session))
示例9: get_smu_info_from_cco
# 需要导入模块: from database import DBSession [as 别名]
# 或者: from database.DBSession import commit [as 别名]
def get_smu_info_from_cco(self, platform, release):
save_to_db = True
db_session = DBSession()
platform_release = platform + '_' + release
try:
self.smu_meta = SMUMeta(platform_release=platform_release)
# Load data from the SMU XML file
self.load()
# This can happen if the given platform and release is not valid.
# The load() method calls get_smu_info_from_db and failed.
if not self.is_valid:
logger.error('get_smu_info_from_cco() hit exception, platform_release=' + platform_release)
return
db_smu_meta = db_session.query(SMUMeta).filter(SMUMeta.platform_release == platform_release).first()
if db_smu_meta:
if db_smu_meta.created_time == self.smu_meta.created_time:
save_to_db = False
else:
# Delete the existing smu_meta and smu_info for this platform and release
db_session.delete(db_smu_meta)
db_session.commit()
if save_to_db:
db_session.add(self.smu_meta)
else:
db_smu_meta.retrieval_time = datetime.datetime.utcnow()
db_session.commit()
except Exception:
logger.exception('get_smu_info_from_cco() hit exception, platform_release=' + platform_release)
示例10: software_profile_create
# 需要导入模块: from database import DBSession [as 别名]
# 或者: from database.DBSession import commit [as 别名]
def software_profile_create():
# if not can_create_user(current_user):
# abort(401)
db_session = DBSession()
form = SoftwareProfileForm(request.form)
server_dialog_form = ServerDialogForm(request.form)
fill_servers(server_dialog_form.server_dialog_server.choices, get_server_list(db_session), False)
if request.method == 'POST' and form.validate():
software_profile = get_software_profile(db_session, form.profile_name.data)
if software_profile is not None:
return render_template('conformance/profile_edit.html',
form=form, system_option=SystemOption.get(db_session), duplicate_error=True)
software_profile = SoftwareProfile(
name=form.profile_name.data,
description=form.description.data,
packages=','.join([l for l in form.software_packages.data.splitlines() if l]),
created_by=current_user.username)
db_session.add(software_profile)
db_session.commit()
return redirect(url_for('conformance.home'))
else:
return render_template('conformance/profile_edit.html',
form=form, server_dialog_form=server_dialog_form,
system_option=SystemOption.get(db_session))
示例11: command_profile_edit
# 需要导入模块: from database import DBSession [as 别名]
# 或者: from database.DBSession import commit [as 别名]
def command_profile_edit(profile_name):
db_session = DBSession()
command_profile = get_command_profile(db_session, profile_name)
if command_profile is None:
abort(404)
form = CustomCommandProfileForm(request.form)
if request.method == 'POST' and form.validate():
if profile_name != form.profile_name.data and \
get_command_profile(db_session, form.profile_name.data) is not None:
return render_template('custom_commad/command_profile_edit.html',
form=form, duplicate_error=True)
command_profile.profile_name = form.profile_name.data
command_profile.command_list = ','.join([l for l in form.command_list.data.splitlines() if l]),
db_session.commit()
return redirect(url_for('custom_command.home'))
else:
form.profile_name.data = command_profile.profile_name
if command_profile.command_list is not None:
form.command_list.data = '\n'.join(command_profile.command_list.split(','))
return render_template('custom_command/command_profile_edit.html',
form=form)
示例12: init_encrypt
# 需要导入模块: from database import DBSession [as 别名]
# 或者: from database.DBSession import commit [as 别名]
def init_encrypt():
global encrypt_dict
db_session = DBSession()
if db_session.query(Encrypt).count() == 0:
db_session.add(Encrypt())
db_session.commit()
encrypt_dict = dict(Encrypt.get(db_session).__dict__)
示例13: init_sys_time
# 需要导入模块: from database import DBSession [as 别名]
# 或者: from database.DBSession import commit [as 别名]
def init_sys_time():
db_session = DBSession()
if db_session.query(System).count() == 0:
db_session.add(System())
db_session.commit()
else:
system = db_session.query(System).first()
system.start_time = datetime.datetime.utcnow()
db_session.commit()
示例14: delete_custom_command_profile
# 需要导入模块: from database import DBSession [as 别名]
# 或者: from database.DBSession import commit [as 别名]
def delete_custom_command_profile(profile_name):
db_session = DBSession()
command_profile = get_command_profile(db_session, profile_name)
if command_profile is None:
abort(404)
db_session.delete(command_profile)
db_session.commit()
return jsonify({'status': 'OK'})
示例15: user_delete
# 需要导入模块: from database import DBSession [as 别名]
# 或者: from database.DBSession import commit [as 别名]
def user_delete(username):
db_session = DBSession()
user = get_user(db_session, username)
if user is None:
abort(404)
db_session.delete(user)
db_session.commit()
return jsonify({'status': 'OK'})