• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python session.add函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中turbogears.database.session.add函数的典型用法代码示例。如果您正苦于以下问题:Python add函数的具体用法?Python add怎么用?Python add使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了add函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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(".")
开发者ID:ustbgaofan,项目名称:beaker,代码行数:30,代码来源:labcontroller.py


示例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
开发者ID:ustbgaofan,项目名称:beaker,代码行数:32,代码来源:data_setup.py


示例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
开发者ID:MythTV,项目名称:smolt,代码行数:7,代码来源:client_impl.py


示例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(".")
开发者ID:beaker-project,项目名称:beaker,代码行数:7,代码来源:configuration.py


示例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'])
开发者ID:beaker-project,项目名称:beaker,代码行数:29,代码来源:test_systems.py


示例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
开发者ID:beaker-project,项目名称:beaker,代码行数:26,代码来源:CSV_import_export.py


示例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(".")
开发者ID:ShaolongHu,项目名称:beaker,代码行数:35,代码来源:group.py


示例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
开发者ID:sujithshankar,项目名称:beaker,代码行数:7,代码来源:data_setup.py


示例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))
开发者ID:sujithshankar,项目名称:beaker,代码行数:26,代码来源:systems.py


示例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()
开发者ID:MythTV,项目名称:smolt,代码行数:26,代码来源:client_impl_mythtv.py


示例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
开发者ID:sibiaoluo,项目名称:beaker,代码行数:29,代码来源:CSV_import_export.py


示例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()
开发者ID:MythTV,项目名称:smolt,代码行数:35,代码来源:client_impl_mythtv.py


示例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()
开发者ID:sibiaoluo,项目名称:beaker,代码行数:26,代码来源:product_update.py


示例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)
开发者ID:chepioq,项目名称:fas,代码行数:33,代码来源:__init__.py


示例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
开发者ID:bmcfee,项目名称:gordon,代码行数:32,代码来源:model.py


示例16: create_job_for_recipes

def create_job_for_recipes(recipes, owner=None, whiteboard=None, cc=None,product=None,
        retention_tag=None, group=None, submitter=None, priority=None, **kwargs):
    if retention_tag is None:
        retention_tag = RetentionTag.by_tag(u'scratch') # Don't use default, unpredictable
    else:
        retention_tag = RetentionTag.by_tag(retention_tag)

    if owner is None:
        owner = create_user()
    if whiteboard is None:
        whiteboard = unique_name(u'job %s')
    job = Job(whiteboard=whiteboard, ttasks=sum(r.ttasks for r in recipes),
        owner=owner, retention_tag=retention_tag, group=group, product=product,
        submitter=submitter)
    if cc is not None:
        job.cc = cc
    if priority is None:
        priority = TaskPriority.default_priority()
    recipe_set = RecipeSet(ttasks=sum(r.ttasks for r in recipes),
            priority=priority)
    recipe_set.recipes.extend(recipes)
    job.recipesets.append(recipe_set)
    session.add(job)
    session.flush()
    log.debug('Created %s', job.t_id)
    return job
开发者ID:sujithshankar,项目名称:beaker,代码行数:26,代码来源:data_setup.py


示例17: init_db

def init_db(metadata):
    logger.info('Creating tables in empty database')
    if metadata != tg_metadata:
        metadata.tables = tg_metadata.tables.copy()
    metadata.create_all()

    logger.info('Stamping database with Alembic "head" revision')
    def stamp(rev, context):
        try:
            return context.script._stamp_revs('head', rev)
        except AttributeError: # alembic < 0.7
            current = context._current_rev()
            head = context.script.get_revision('head')
            context._update_current_rev(current, head.revision)
            return []
    run_alembic_operation(metadata, stamp)

    # Also mark all data migrations as done, because there is no data to 
    # migrate. This avoids beakerd wasting time trying to run them all when it 
    # first starts up.
    session = create_session(bind=metadata.bind)
    with session.begin():
        for migration_name in DataMigration.all_names():
            logger.info('Marking data migration %s finished', migration_name)
            session.add(DataMigration(name=migration_name,
                    finish_time=datetime.datetime.utcnow()))
开发者ID:beaker-project,项目名称:beaker,代码行数:26,代码来源:init.py


示例18: save

 def save(self, id=None, **kw):
     retention_tag = Tag(tag=kw['tag'], default=kw['default'],
             needs_product=kw['needs_product'],
             expire_in_days=kw['expire_in_days'])
     session.add(retention_tag)
     flash(_(u"OK"))
     redirect("./admin")
开发者ID:beaker-project,项目名称:beaker,代码行数:7,代码来源:retention_tags.py


示例19: _new_group

 def _new_group(self, group_id, display_name, group_name, ldap,
     root_password):
     user = identity.current.user
     if ldap and not user.is_admin():
         flash(_(u'Only admins can create LDAP groups'))
         redirect('.')
     try:
         Group.by_name(group_name)
     except NoResultFound:
         pass
     else:
         flash( _(u"Group %s already exists." % group_name) )
         redirect(".")
     group = Group()
     session.add(group)
     activity = Activity(user, u'WEBUI', u'Added', u'Group', u"", display_name)
     group.display_name = display_name
     group.group_name = group_name
     group.ldap = ldap
     if group.ldap:
         group.refresh_ldap_members()
     group.root_password = root_password
     if not ldap: # LDAP groups don't have owners
         group.user_group_assocs.append(UserGroup(user=user, is_owner=True))
         group.activity.append(GroupActivity(user, service=u'WEBUI',
             action=u'Added', field_name=u'User',
             old_value=None, new_value=user.user_name))
         group.activity.append(GroupActivity(user, service=u'WEBUI',
             action=u'Added', field_name=u'Owner',
             old_value=None, new_value=user.user_name))
     return group
开发者ID:sibiaoluo,项目名称:beaker,代码行数:31,代码来源:group.py


示例20: 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.record_activity(user=identity.current.user, service=u'CSV',
                         field=u'User', action=u'Removed', old=user)
                 user.groups.remove(group)
         else:
             if group not in user.groups:
                 group.record_activity(user=identity.current.user, service=u'CSV',
                         field=u'User', action=u'Added', new=user)
                 user.groups.append(group)
     else:
         log.append("%s: group can't be empty!" % user)
         return False
     return True
开发者ID:ShaolongHu,项目名称:beaker,代码行数:28,代码来源:CSV_import_export.py



注:本文中的turbogears.database.session.add函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python session.begin函数代码示例发布时间:2022-05-27
下一篇:
Python config.update函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap