本文整理汇总了Python中stalker.db.session.DBSession.rollback方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.rollback方法的具体用法?Python DBSession.rollback怎么用?Python DBSession.rollback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stalker.db.session.DBSession
的用法示例。
在下文中一共展示了DBSession.rollback方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: reject
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import rollback [as 别名]
def reject(self):
QtWidgets.QDialog.reject(self)
from stalker.db.session import DBSession
if self.version:
DBSession.delete(self.version)
DBSession.commit()
DBSession.rollback()
示例2: accept
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import rollback [as 别名]
def accept(self):
"""overridden accept method
"""
if not self.name_lineEdit.is_valid:
QtWidgets.QMessageBox.critical(
self,
'Error',
'Please fix <b>name</b> field!'
)
return
name = self.name_lineEdit.text()
windows_path = self.windows_path_lineEdit.text()
linux_path = self.linux_path_lineEdit.text()
osx_path = self.osx_path_lineEdit.text()
from stalker import Repository
from stalker.db.session import DBSession
logged_in_user = self.get_logged_in_user()
if self.mode == 'Create':
# Create a new Repository
try:
repo = Repository(
name=name,
windows_path=windows_path,
linux_path=linux_path,
osx_path=osx_path
)
self.repository = repo
DBSession.add(repo)
DBSession.commit()
except Exception as e:
DBSession.rollback()
QtWidgets.QMessageBox.critical(
self,
'Error',
str(e)
)
return
elif self.mode == 'Update':
# Update the repository
try:
self.repository.name = name
self.repository.windows_path = windows_path
self.repository.linux_path = linux_path
self.repository.osx_path = osx_path
self.repository.updated_by = logged_in_user
DBSession.add(self.repository)
DBSession.commit()
except Exception as e:
DBSession.rollback()
QtWidgets.QMessageBox.critical(
self,
'Error',
str(e)
)
return
super(MainDialog, self).accept()
示例3: create_ticket_statuses
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import rollback [as 别名]
def create_ticket_statuses():
"""creates the default ticket statuses
"""
from stalker import User
# create as admin
admin = User.query.filter(User.login == defaults.admin_name).first()
# create statuses for Tickets
ticket_names = defaults.ticket_status_names
ticket_codes = defaults.ticket_status_codes
create_entity_statuses('Ticket', ticket_names, ticket_codes, admin)
# Again I hate doing this in this way
from stalker import Type
types = Type.query \
.filter_by(target_entity_type="Ticket") \
.all()
t_names = [t.name for t in types]
# create Ticket Types
logger.debug("Creating Ticket Types")
if 'Defect' not in t_names:
ticket_type_1 = Type(
name='Defect',
code='Defect',
target_entity_type='Ticket',
created_by=admin,
updated_by=admin
)
DBSession.add(ticket_type_1)
if 'Enhancement' not in t_names:
ticket_type_2 = Type(
name='Enhancement',
code='Enhancement',
target_entity_type='Ticket',
created_by=admin,
updated_by=admin
)
DBSession.add(ticket_type_2)
try:
DBSession.commit()
except IntegrityError:
DBSession.rollback()
logger.debug("Ticket Types are already in the database!")
else:
# DBSession.flush()
logger.debug("Ticket Types are created successfully")
示例4: create_entity_statuses
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import rollback [as 别名]
def create_entity_statuses(entity_type="", status_names=None, status_codes=None, user=None):
"""creates the default task statuses
"""
if not entity_type:
raise ValueError("Please supply entity_type")
if not status_names:
raise ValueError("Please supply status names")
if not status_codes:
raise ValueError("Please supply status codes")
# create statuses for entity
from stalker import Status, StatusList
logger.debug("Creating %s Statuses" % entity_type)
statuses = Status.query.filter(Status.name.in_(status_names)).all()
status_names_in_db = map(lambda x: x.name, statuses)
for name, code in zip(status_names, status_codes):
if name not in status_names_in_db:
logger.debug("Creating Status: %s (%s)" % (name, code))
new_status = Status(name=name, code=code, created_by=user, updated_by=user)
statuses.append(new_status)
DBSession.add(new_status)
# create the Status List
status_list = StatusList.query.filter(StatusList.target_entity_type == entity_type).first()
if status_list is None:
logger.debug("No %s Status List found, creating new!" % entity_type)
status_list = StatusList(
name="%s Statuses" % entity_type, target_entity_type=entity_type, created_by=user, updated_by=user
)
else:
logger.debug("%s Status List already created, updating statuses" % entity_type)
status_list.statuses = statuses
DBSession.add(status_list)
try:
DBSession.commit()
except IntegrityError as e:
logger.debug("error in DBSession.commit, rolling back: %s" % e)
DBSession.rollback()
else:
logger.debug("Created %s Statuses successfully" % entity_type)
DBSession.flush()
示例5: get_alembic_version
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import rollback [as 别名]
def get_alembic_version():
"""returns the alembic version of the database
"""
# try to query the version value
conn = DBSession.connection()
engine = conn.engine
if engine.dialect.has_table(conn, 'alembic_version'):
sql_query = 'select version_num from alembic_version'
try:
return DBSession.connection().execute(sql_query).fetchone()[0]
except (OperationalError, ProgrammingError, TypeError):
DBSession.rollback()
return None
else:
return None
示例6: accept
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import rollback [as 别名]
#.........这里部分代码省略.........
from stalker.db.session import DBSession
from stalker.exceptions import (OverBookedError,
DependencyViolationError)
utc_now = local_to_utc(datetime.datetime.now())
# TODO: Remove this in a later version
import stalker
from distutils.version import LooseVersion
if LooseVersion(stalker.__version__) >= LooseVersion('0.2.18'):
# inject timezone info
import pytz
utc_start_date = utc_start_date.replace(tzinfo=pytz.utc)
utc_end_date = utc_end_date.replace(tzinfo=pytz.utc)
utc_now = utc_now.replace(tzinfo=pytz.utc)
from sqlalchemy.exc import IntegrityError
if not self.timelog:
try:
new_time_log = TimeLog(
task=task,
resource=resource,
start=utc_start_date,
end=utc_end_date,
description=description,
date_created=utc_now
)
except (OverBookedError, DependencyViolationError) as e:
# inform the user that it can not do that
QtWidgets.QMessageBox.critical(
self,
'Error',
'%s' % e
)
DBSession.rollback()
return
try:
DBSession.add(new_time_log)
DBSession.commit()
self.timelog_created = True
except IntegrityError as e:
DBSession.rollback()
QtWidgets.QMessageBox.critical(
self,
'Error',
'Database Error!!!'
'<br>'
'%s' % e
)
return
else:
# just update the date values
self.timelog.start = utc_start_date
self.timelog.end = utc_end_date
self.timelog.date_updated = utc_now
DBSession.add(self.timelog)
DBSession.commit()
if self.no_time_left:
# we have no time left so automatically extend the task
from stalker import Task
schedule_timing, schedule_unit = \
task.least_meaningful_time_unit(
task.total_logged_seconds
)
示例7: register
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import rollback [as 别名]
def register(class_):
"""Registers the given class to the database.
It is mainly used to create the :class:`.Action`\ s needed for the
:class:`.User`\ s and :class:`.Group`\ s to be able to interact with the
given class. Whatever class you have created needs to be registered.
Example, lets say that you have a data class which is specific to your
studio and it is not present in Stalker Object Model (SOM), so you need to
extend SOM with a new data type. Here is a simple Data class inherited from
the :class:`.SimpleEntity` class (which is the simplest class you should
inherit your classes from or use more complex classes down to the
hierarchy)::
from sqlalchemy import Column, Integer, ForeignKey
from stalker.models.entity import SimpleEntity
class MyDataClass(SimpleEntity):
'''This is an example class holding a studio specific data which is not
present in SOM.
'''
__tablename__ = 'MyData'
__mapper_arguments__ = {'polymorphic_identity': 'MyData'}
my_data_id = Column('id', Integer, ForeignKey('SimpleEntities.c.id'),
primary_key=True)
Now because Stalker is using Pyramid authorization mechanism it needs to be
able to have an :class:`.Permission` about your new class, so you can
assign this :class;`.Permission` to your :class:`.User`\ s or
:class:`.Group`\ s. So you ned to register your new class with
:func:`stalker.db.register` like shown below::
from stalker import db
db.register(MyDataClass)
This will create the necessary Actions in the 'Actions' table on your
database, then you can create :class:`.Permission`\ s and assign these to
your :class:`.User`\ s and :class:`.Group`\ s so they are Allowed or Denied
to do the specified Action.
:param class_: The class itself that needs to be registered.
"""
from stalker.models.auth import Permission
# create the Permissions
permissions_db = Permission.query.all()
if not isinstance(class_, type):
raise TypeError("To register a class please supply the class itself.")
# register the class name to entity_types table
from stalker import EntityType, StatusMixin, DateRangeMixin, ReferenceMixin, ScheduleMixin
class_name = class_.__name__
if not EntityType.query.filter_by(name=class_name).first():
new_entity_type = EntityType(class_name)
# update attributes
if issubclass(class_, StatusMixin):
new_entity_type.statusable = True
if issubclass(class_, DateRangeMixin):
new_entity_type.dateable = True
if issubclass(class_, ScheduleMixin):
new_entity_type.schedulable = True
if issubclass(class_, ReferenceMixin):
new_entity_type.accepts_references = True
DBSession.add(new_entity_type)
for action in defaults.actions:
for access in ["Allow", "Deny"]:
permission_obj = Permission(access, action, class_name)
if permission_obj not in permissions_db:
DBSession.add(permission_obj)
try:
DBSession.commit()
except IntegrityError:
DBSession.rollback()
示例8: accept
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import rollback [as 别名]
def accept(self):
"""overridden accept method
"""
if not self.name_line_edit.is_valid:
QtWidgets.QMessageBox.critical(
self,
'Error',
'Please fix <b>name</b> field!'
)
return
name = self.name_line_edit.text()
width = self.width_spin_box.value()
height = self.height_spin_box.value()
pixel_aspect = self.pixel_aspect_double_spin_box.value()
from stalker import ImageFormat
from stalker.db.session import DBSession
logged_in_user = self.get_logged_in_user()
if self.mode == 'Create':
# Create a new Image Format
try:
imf = ImageFormat(
name=name,
width=width,
height=height,
pixel_aspect=pixel_aspect,
created_by=logged_in_user
)
self.image_format = imf
DBSession.add(imf)
DBSession.commit()
except Exception as e:
DBSession.rollback()
QtWidgets.QMessageBox.critical(
self,
'Error',
str(e)
)
return
elif self.mode == 'Update':
# Update the image format
try:
self.image_format.name = name
self.image_format.width = width
self.image_format.height = height
self.image_format.pixel_aspect = pixel_aspect
self.image_format.updated_by = logged_in_user
DBSession.add(self.image_format)
DBSession.commit()
except Exception as e:
DBSession.rollback()
QtWidgets.QMessageBox.critical(
self,
'Error',
str(e)
)
return
super(MainDialog, self).accept()
示例9: accept
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import rollback [as 别名]
def accept(self):
"""overridden accept method
"""
if not self.name_lineEdit.is_valid:
QtWidgets.QMessageBox.critical(
self,
'Error',
'Please fix <b>name</b> field!'
)
return
name = self.name_lineEdit.text()
custom_template = self.custom_template_plainTextEdit.toPlainText()
filename_template_items = \
self.filename_templates_double_list_widget.secondary_items()
filename_template_ids = []
for item in filename_template_items:
filename_template_id = \
int(item.text().split('(')[-1].split(')')[0])
filename_template_ids.append(filename_template_id)
from stalker import FilenameTemplate
filename_templates = FilenameTemplate.query\
.filter(FilenameTemplate.id.in_(filename_template_ids)).all()
from stalker import Structure
from stalker.db.session import DBSession
logged_in_user = self.get_logged_in_user()
if self.mode == 'Create':
# Create a new Structure
try:
structure = Structure(
name=name,
templates=filename_templates,
custom_template=custom_template,
created_by=logged_in_user
)
self.structure = structure
DBSession.add(structure)
DBSession.commit()
except Exception as e:
DBSession.rollback()
QtWidgets.QMessageBox.critical(
self,
'Error',
str(e)
)
return
elif self.mode == 'Update':
# Update the structure
try:
self.structure.name = name
self.structure.templates = filename_templates
self.structure.custom_template = custom_template
self.structure.updated_by = logged_in_user
DBSession.add(self.structure)
DBSession.commit()
except Exception as e:
DBSession.rollback()
QtWidgets.QMessageBox.critical(
self,
'Error',
str(e)
)
return
super(MainDialog, self).accept()
示例10: save_previs_to_shots
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import rollback [as 别名]
def save_previs_to_shots(self, take_name):
"""exports previs to animation shots
"""
self.pre_publish_previs()
shot_tasks = self.scene_shot_tasks
shot_nodes = self.shot_list
shots_to_export = []
for shot_node in shot_nodes:
for shot_task in shot_tasks:
for task in shot_task.tasks:
if task.type == self.anim_type:
shot_number = shot_task.name.split('_')[-1]
if shot_node.getShotName() == shot_number:
shots_to_export.append([shot_node, task, shot_number])
from anima.env import mayaEnv
from stalker import Version
from anima.ui.progress_dialog import ProgressDialogManager
pdm = ProgressDialogManager()
pdm.close()
m_env = mayaEnv.Maya()
versions = []
description = 'Auto Created By Shot Exporter'
# create versions to save and show in pop-up window
for shot_info in shots_to_export:
version = Version(
task=shot_info[1],
description=description,
take_name=take_name,
created_by=self.logged_in_user
)
versions.append(version)
if len(versions) != len(shots_to_export):
from stalker.db.session import DBSession
DBSession.rollback()
raise RuntimeError('Something is critically wrong. Contact Mehmet ERER.')
# pop-up a window to show everything will be saved properly before actually doing it
message = 'Shots will be Saved as Below:\r\n'
message += '\r'
index = 0
for shot_info in shots_to_export:
v = versions[index]
message += 'shot[ %s ] -> %s\n' % (shot_info[2], v)
index += 1
dialog = pm.confirmDialog(title='Important Warning',
message=message,
button=['OK, Start Saving Shots', 'STOP, wrong paths!'])
if dialog == 'OK, Start Saving Shots':
pass
else:
from stalker.db.session import DBSession
DBSession.rollback()
raise RuntimeError('Process Interrupted by User.')
previs_version = self.current_version
errored_shots = []
ind = 0
caller = pdm.register(len(shots_to_export), 'Batch Saving Previs Shot Nodes to Animation Shot Tasks...')
from anima.env.mayaEnv import toolbox
reload(toolbox)
from stalker.db.session import DBSession
for shot_info in shots_to_export:
shot_task = versions[ind].task.parent
try:
# open previs version
m_env.open(previs_version, force=True, reference_depth=3, skip_update_check=True)
# clear scene
except_this_shot = pm.PyNode(shot_info[0].name())
self.clear_scene(except_this_shot)
# set frame range before save
toolbox.Animation.set_range_from_shot()
# update shot.cut_in and shot.cut_out info
cut_in = pm.playbackOptions(q=1, min=1)
cut_out = pm.playbackOptions(q=1, max=1)
shot_task.cut_in = int(cut_in)
shot_task.cut_out = int(cut_out)
# save it
m_env.save_as(versions[ind])
except:
errored_shots.append(shot_info[2])
else:
# store information to database
DBSession.add(shot_task)
DBSession.add(versions[ind])
DBSession.commit()
ind += 1
caller.step()
#.........这里部分代码省略.........
示例11: accept
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import rollback [as 别名]
def accept(self):
"""the overridden accept method
"""
target_entity_type = self.target_entity_type_combo_box.currentText()
if not self.name_line_edit.is_valid:
QtWidgets.QMessageBox.critical(
self,
'Error',
'Please fix <b>name</b> field!'
)
return
name = self.name_line_edit.text()
path = self.path_line_edit.text()
if path == '':
QtWidgets.QMessageBox.critical(
self,
'Error',
'Please fix <b>path</b> field!'
)
return
filename = self.filename_line_edit.text()
if path == '':
QtWidgets.QMessageBox.critical(
self,
'Error',
'Please fix <b>filename</b> field!'
)
return
logged_in_user = self.get_logged_in_user()
from stalker.db.session import DBSession
if self.mode == 'Create':
try:
from stalker import FilenameTemplate
# create a new FilenameTemplate
ft = FilenameTemplate(
name=name,
path=path,
filename=filename,
target_entity_type=target_entity_type,
created_by=logged_in_user
)
self.filename_template = ft
DBSession.add(ft)
DBSession.commit()
except Exception as e:
DBSession.rollback()
QtWidgets.QMessageBox.critical(
self,
'Error',
str(e)
)
return
elif self.mode == 'Update':
try:
self.filename_template.name = name
self.filename_template.path = path
self.filename_template.filename = filename
self.filename_template.updated_by = logged_in_user
DBSession.add(self.filename_template)
DBSession.commit()
except Exception as e:
DBSession.rollback()
QtWidgets.QMessageBox.critical(
self,
'Error',
str(e)
)
return
super(MainDialog, self).accept()
示例12: accept
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import rollback [as 别名]
def accept(self):
"""create/update the project
"""
# Name
if not self.name_lineEdit.is_valid:
QtWidgets.QMessageBox.critical(
self,
'Error',
'Please fix <b>name</b> field!'
)
return
name = self.name_lineEdit.text()
# Code
if not self.code_lineEdit.is_valid:
QtWidgets.QMessageBox.critical(
self,
'Error',
'Please fix <b>code</b> field!'
)
return
code = self.code_lineEdit.text()
# Type
from stalker import Type
index = self.type_comboBox.currentIndex()
type_id = self.type_comboBox.itemData(index)
type_ = Type.query.get(type_id) # None type is ok
# Image Format
image_format = self.image_format.get_current_image_format()
if not image_format:
QtWidgets.QMessageBox.critical(
self,
'Error',
'Please select a valid <b>Image Format</b>!'
)
return
# FPS
fps = self.fps_spinBox.value()
# Repository
repo = self.get_current_repository()
if not repo:
QtWidgets.QMessageBox.critical(
self,
'Error',
'Please select a valid <b>Repository</b>!'
)
return
# Structure
structure = self.get_current_structure()
if not structure:
QtWidgets.QMessageBox.critical(
self,
'Error',
'Please select a valid <b>Structure</b>!'
)
return
# Status
from stalker import Status
index = self.status_comboBox.currentIndex()
status_id = self.status_comboBox.itemData(index)
status = Status.query.get(status_id)
if not status:
QtWidgets.QMessageBox.critical(
self,
'Error',
'Please select a valid <b>Status</b>!'
)
return
# TODO: Add Client Data fields (which I don't care for now)
logged_in_user = self.get_logged_in_user()
# create or update project
from stalker.db.session import DBSession
if self.mode == 'Create':
# create a new project
from stalker import Project
new_project = Project(
name=name,
code=code,
type=type_,
repositories=[repo],
structure=structure,
image_format=image_format,
fps=fps,
created_by=logged_in_user
)
DBSession.add(new_project)
try:
DBSession.commit()
except Exception as e:
DBSession.rollback()
QtWidgets.QMessageBox.critical(
self,
#.........这里部分代码省略.........