本文整理汇总了Python中turbogears.database.session.add函数的典型用法代码示例。如果您正苦于以下问题:Python add函数的具体用法?Python add怎么用?Python add使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了add函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: remove
def remove(self, id, *args, **kw):
labcontroller = LabController.by_id(id)
labcontroller.removed = datetime.utcnow()
systems = System.query.filter_by(lab_controller_id=id).values(System.id)
for system_id in systems:
sys_activity = SystemActivity(identity.current.user, 'WEBUI', \
'Changed', 'lab_controller', labcontroller.fqdn,
None, system_id=system_id[0])
session.add(sys_activity)
System.__table__.update().where(System.lab_controller_id == id).\
values(lab_controller_id=None).execute()
watchdogs = Watchdog.by_status(labcontroller=labcontroller,
status='active')
for w in watchdogs:
w.recipe.recipeset.job.cancel(msg='LabController %s has been deleted' % labcontroller.fqdn)
for lca in labcontroller._distro_trees:
lca.distro_tree.activity.append(DistroTreeActivity(
user=identity.current.user, service=u'WEBUI',
action=u'Removed', field_name=u'lab_controller_assocs',
old_value=u'%s %s' % (lca.lab_controller, lca.url),
new_value=None))
session.delete(lca)
labcontroller.disabled = True
labcontroller.record_activity(user=identity.current.user, service=u'WEBUI',
field=u'Disabled', action=u'Changed', old=unicode(False), new=unicode(True))
labcontroller.record_activity(user=identity.current.user, service=u'WEBUI',
field=u'Removed', action=u'Changed', old=unicode(False), new=unicode(True))
flash( _(u"%s removed") % labcontroller.fqdn )
raise redirect(".")
示例2: create_distro_tree
def create_distro_tree(distro=None, distro_name=None, osmajor=u'DansAwesomeLinux6',
distro_tags=None, arch=u'i386', variant=u'Server', lab_controllers=None,
urls=None):
if distro is None:
if distro_name is None:
distro = create_distro(osmajor=osmajor, tags=distro_tags)
else:
distro = Distro.by_name(distro_name)
if not distro:
distro = create_distro(name=distro_name)
distro_tree = DistroTree.lazy_create(distro=distro,
arch=Arch.by_name(arch), variant=variant)
session.add(distro_tree)
if distro_tree.arch not in distro.osversion.arches:
distro.osversion.arches.append(distro_tree.arch)
distro_tree.repos.append(DistroTreeRepo(repo_id=variant,
repo_type=u'variant', path=u''))
existing_urls = [lc_distro_tree.url for lc_distro_tree in distro_tree.lab_controller_assocs]
# make it available in all lab controllers
for lc in (lab_controllers or LabController.query):
default_urls = [u'%s://%s%s/distros/%s/%s/%s/os/' % (scheme, lc.fqdn,
scheme == 'nfs' and ':' or '',
distro_tree.distro.name, distro_tree.variant,
distro_tree.arch.arch) for scheme in ['nfs', 'http', 'ftp']]
for url in (urls or default_urls):
if url in existing_urls:
break
lab_controller_distro_tree = LabControllerDistroTree(
lab_controller=lc, url=url)
distro_tree.lab_controller_assocs.append(lab_controller_distro_tree)
log.debug('Created distro tree %r', distro_tree)
return distro_tree
示例3: add_json_plus_pub_uuid
def add_json_plus_pub_uuid(self, uuid, pub_uuid, host, token, smolt_protocol):
self._run_add_json_checks(uuid, host, token, smolt_protocol)
res = self.handle_submission(uuid, pub_uuid, host)
log_entry = BatchJob(host, uuid, added=True)
session.add(log_entry)
session.flush()
return res
示例4: remove
def remove(self, **kw):
item = ConfigItem.by_id(kw['id'])
item.set(None, None, identity.current.user)
session.add(item)
session.flush()
flash(_(u"%s cleared") % item.description)
raise redirect(".")
示例5: test_system_details_includes_cpus
def test_system_details_includes_cpus(self):
with session.begin():
cpu = Cpu(cores=5,
family=6,
model=7,
model_name='Intel',
flags=['beer', 'frob'],
processors=6,
sockets=2,
speed=24,
stepping=2,
vendor='Transmeta')
session.add(cpu)
self.system.cpu = cpu
response = requests.get(
get_server_base() + 'systems/%s' % self.system.fqdn)
json = response.json()
self.assertEqual([u'beer', u'frob'], json['cpu_flags'])
self.assertEqual(5, json['cpu_cores'])
self.assertEqual(6, json['cpu_family'])
self.assertEqual(7, json['cpu_model'])
self.assertEqual(u'Intel', json['cpu_model_name'])
self.assertEqual(True, json['cpu_hyper'])
self.assertEqual(6, json['cpu_processors'])
self.assertEqual(2, json['cpu_sockets'])
self.assertEqual(24, json['cpu_speed'])
self.assertEqual(2, json['cpu_stepping'])
self.assertEqual('Transmeta', json['cpu_vendor'])
示例6: from_csv
def from_csv(cls,user,data,log):
"""
Import data from CSV file into user.groups
"""
if 'group' in data and data['group']:
try:
group = Group.by_name(data['group'])
except InvalidRequestError:
group = Group(group_name=data['group'],
display_name=data['group'])
session.add(group)
deleted = False
if 'deleted' in data:
deleted = smart_bool(data['deleted'])
if deleted:
if group in user.groups:
group.remove_member(user, service=u'CSV',
agent=identity.current.user)
else:
if group not in user.groups:
group.add_member(user, service=u'CSV',
agent=identity.current.user)
else:
log.append("%s: group can't be empty!" % user)
return False
return True
示例7: remove
def remove(self, **kw):
u = identity.current.user
try:
group = Group.by_id(kw['group_id'])
except DatabaseLookupError:
flash(unicode('Invalid group or already removed'))
redirect('../groups/mine')
if not group.can_edit(u):
flash(_(u'You are not an owner of group %s' % group))
redirect('../groups/mine')
if group.is_protected_group():
flash(_(u'This group %s is predefined and cannot be deleted' % group))
redirect('../groups/mine')
if group.jobs:
flash(_(u'Cannot delete a group which has associated jobs'))
redirect('../groups/mine')
# Record the access policy rules that will be removed
# before deleting the group
for rule in group.system_access_policy_rules:
rule.record_deletion()
# For any system pool owned by this group, unset owning_group
# and set owning_user to the user deleting this group
pools = SystemPool.query.filter_by(owning_group_id=group.group_id)
for pool in pools:
pool.change_owner(user=u, service='WEBUI')
session.delete(group)
activity = Activity(u, u'WEBUI', u'Removed', u'Group', group.display_name, u"")
session.add(activity)
flash( _(u"%s deleted") % group.display_name )
raise redirect(".")
示例8: create_system_activity
def create_system_activity(user=None, **kw):
if not user:
user = create_user()
activity = SystemActivity(user, u'WEBUI', u'Changed', u'Loaned To',
unique_name(u'random_%s'), user.user_name)
session.add(activity)
return activity
示例9: add_system
def add_system():
# We accept JSON or form-encoded for convenience
if request.json:
if 'fqdn' not in request.json:
raise BadRequest400('Missing fqdn key')
new_fqdn = request.json['fqdn']
elif request.form:
if 'fqdn' not in request.form:
raise BadRequest400('Missing fqdn parameter')
new_fqdn = request.form['fqdn']
else:
raise UnsupportedMediaType415
with convert_internal_errors():
if System.query.filter(System.fqdn == new_fqdn).count() != 0:
raise Conflict409('System with fqdn %r already exists' % new_fqdn)
system = System(fqdn=new_fqdn, owner=identity.current.user)
session.add(system)
# new systems are visible to everybody by default
system.custom_access_policy = SystemAccessPolicy()
system.custom_access_policy.add_rule(SystemPermission.view,
everybody=True)
# XXX this should be 201 with Location: /systems/FQDN/ but 302 is more
# convenient because it lets us use a traditional browser form without AJAX
# handling, and for now we're redirecting to /view/FQDN until that is moved
# to /systems/FQDN/
return flask_redirect(url(u'/view/%s#essentials' % system.fqdn))
示例10: _handle_pbp
def _handle_pbp(session, data, machine_id):
name = "unknown"
profiles = ['unknown']
try:
myth_pb = data['features']['playbackprofile']
except:
myth_pb = {}
try:
name = myth_pb['name']
except:
pass
try:
profiles = myth_pb['profiles']
except:
pass
#Remove old entry
session.query(mythtvPbp).filter_by(machine_id = machine_id).delete()
#Add new entry
session.add(mythtvPbp(machine_id,name,profiles))
session.flush()
示例11: _from_csv
def _from_csv(cls,system,data,csv_type,log):
"""
Import data from CSV file into system.groups
"""
if 'group' in data and data['group']:
try:
group = Group.by_name(data['group'])
except InvalidRequestError:
group = Group(group_name=data['group'],
display_name=data['group'])
session.add(group)
session.flush([group])
deleted = False
if 'deleted' in data:
deleted = smart_bool(data['deleted'])
if deleted:
if group in system.groups:
activity = SystemActivity(identity.current.user, 'CSV', 'Removed', 'group', '%s' % group, '')
system.activity.append(activity)
system.groups.remove(group)
else:
if group not in system.groups:
system.groups.append(group)
activity = SystemActivity(identity.current.user, 'CSV', 'Added', 'group', '', '%s' % group)
system.activity.append(activity)
else:
log.append("%s: group can't be empty!" % system.fqdn)
return False
return True
示例12: _handle_historical
def _handle_historical(session, data,myth_uuid):
showcount = 0
rectime = 0
db_age = 0
reccount = 0
try:
myth_hist = data['features']['historical']
except:
myth_hist = {}
#session.query(mythtvHistorical).filter_by(machine_id = machine_id).delete()
session.query(mythtvHistorical).filter_by(myth_uuid = myth_uuid).delete()
try:
showcount = myth_hist['showcount']
except:
pass
try:
rectime = myth_hist['rectime']
except:
pass
try:
db_age = myth_hist['db_age']
except:
pass
try:
reccount = myth_hist['reccount']
except:
pass
session.add(mythtvHistorical(myth_uuid,
showcount,rectime,db_age,reccount)
)
session.flush()
示例13: update_products
def update_products(xml_file):
dom = etree.parse(xml_file)
xpath_string = "//cpe"
cpes = dom.xpath(xpath_string)
session.begin()
try:
to_add = {}
dupe_errors = []
for cpe in cpes:
cpe_text = cpe.text
if cpe_text in to_add:
dupe_errors.append(cpe_text)
else:
to_add[cpe_text] = 1
for cpe_to_add in to_add:
try:
prod = Product.by_name(u"%s" % cpe_to_add)
except NoResultFound:
session.add(Product(u"%s" % cpe_to_add))
continue
session.commit()
finally:
session.rollback()
示例14: genkey
def genkey(self):
username = turbogears.identity.current.user_name
person = People.by_username(username)
created = time.strftime("%Y-%m-%dT%H:%M:%S")
hexctr = "%012x" % person.id
publicname = hex2modhex(hexctr)
internalname = gethexrand(12)
aeskey = gethexrand(32)
lockcode = gethexrand(12)
try:
new_ykksm = Ykksm(serialnr=person.id, publicname=publicname, created=created, internalname=internalname, aeskey=aeskey, lockcode=lockcode, creator=username)
session.add(new_ykksm)
session.flush()
except IntegrityError:
session.rollback()
old_ykksm = session.query(Ykksm).filter_by(serialnr=person.id).all()[0]
session.delete(old_ykksm)
new_ykksm = Ykksm(serialnr=person.id, publicname=publicname, created=created, internalname=internalname, aeskey=aeskey, lockcode=lockcode, creator=username)
old_ykksm = new_ykksm
session.flush()
try:
old_ykval = session.query(Ykval).filter_by(yk_publicname=publicname).all()[0]
session.delete(old_ykval)
session.flush()
except IndexError:
# No old record? Maybe they never used their key
pass
string = "%s %s %s" % (publicname, internalname, aeskey)
return dict(key=string)
示例15: create_default_user
def create_default_user(user_name, password=None):
"""Create a default user."""
try:
u = User.by_user_name(user_name)
except:
u = None
if u:
print "User '%s' already exists in database." % user_name
return
from getpass import getpass
from sys import stdin
while password is None:
try:
password = getpass("Enter password for user '%s': "
% user_name.encode(stdin.encoding)).strip()
password2 = getpass("Confirm password: ").strip()
if password != password2:
print "Passwords do not match."
else:
password = password.decode(stdin.encoding)
break
except (EOFError, KeyboardInterrupt):
print "User creation cancelled."
return
u = User()
u.user_name = user_name
u.display_name = u"Default User"
u.email_address = u"%[email protected]" % user_name
u.password = password
session.add(u)
session.flush()
print "User '%s' created." % user_name