当前位置: 首页>>代码示例>>Python>>正文


Python database.DBSession类代码示例

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


在下文中一共展示了DBSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: api_get_distinct_host_roles

def api_get_distinct_host_roles(platform, software_versions, region_ids):
    """
    software_versions may equal to 'ALL' or multiple software versions
    region_ids may equal to 'ALL' or multiple region ids
    """
    clauses = []
    db_session = DBSession()

    clauses.append(Host.software_platform == platform)
    if 'ALL' not in software_versions:
        clauses.append(Host.software_version.in_(software_versions.split(',')))
    if 'ALL' not in region_ids:
        clauses.append(Host.region_id.in_(region_ids.split(',')))

    host_roles = db_session.query(Host.roles).filter(and_(*clauses)).distinct()

    # Change a list of tuples to a list
    # Example of roles_list  = [u'PE Router', u'PE1,R0', u'PE1,PE4', u'PE2,R1', u'Core']
    roles_list = [roles[0] for roles in host_roles if not is_empty(roles[0])]

    # Collapses the comma delimited strings to list
    roles_list = [] if is_empty(roles_list) else ",".join(roles_list).split(',')

    # Make the list unique, then sort it
    roles_list = sorted(list(set(roles_list)))

    rows = []
    for role in roles_list:
        rows.append({'role': role})

    return jsonify(**{'data': rows})
开发者ID:smjurcak,项目名称:csm,代码行数:31,代码来源:csmserver.py

示例2: api_get_hosts_by_region

def api_get_hosts_by_region(region_id, role, software):
    selected_roles = []
    selected_software = []

    if 'ALL' not in role:
        selected_roles = role.split(',')

    if 'ALL' not in software:
        selected_software = software.split(',')

    rows = []
    db_session = DBSession()    

    hosts = db_session.query(Host).filter(Host.region_id == region_id). \
        order_by(Host.hostname.asc())

    for host in hosts:
        host_roles = [] if host.roles is None else host.roles.split(',')
        if not selected_roles or any(role in host_roles for role in selected_roles):
            if host.software_platform is not None and host.software_version is not None:
                host_platform_software = host.software_platform + ' (' + host.software_version + ')'
            else:
                host_platform_software = UNKNOWN

            if not selected_software or host_platform_software in selected_software:
                row = {'hostname': host.hostname,
                       'roles': host.roles,
                       'platform_software': host_platform_software}

                rows.append(row)
    
    return jsonify(**{'data': rows})
开发者ID:smjurcak,项目名称:csm,代码行数:32,代码来源:csmserver.py

示例3: api_get_distinct_host_regions

def api_get_distinct_host_regions(platform, software_versions):
    """
    software_versions may equal to 'ALL' or multiple software versions
    """
    clauses = []
    db_session = DBSession()

    clauses.append(Host.software_platform == platform)
    if 'ALL' not in software_versions:
        clauses.append(Host.software_version.in_(software_versions.split(',')))

    region_ids = db_session.query(Host.region_id).filter(and_(*clauses)).distinct()

    # Change a list of tuples to a list
    region_ids_list = [region_id[0] for region_id in region_ids]

    rows = []
    if not is_empty(region_ids):
        regions = db_session.query(Region).filter(Region.id.in_(region_ids_list)). \
            order_by(Region.name.asc()).all()

        for region in regions:
            rows.append({'region_id': region.id, 'region_name': region.name})

    return jsonify(**{'data': rows})
开发者ID:smjurcak,项目名称:csm,代码行数:25,代码来源:csmserver.py

示例4: command_profile_create

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)
开发者ID:anushreejangid,项目名称:csm,代码行数:26,代码来源:custom_command.py

示例5: user_preferences

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))
开发者ID:smjurcak,项目名称:csm,代码行数:33,代码来源:cco.py

示例6: start

 def start(self):
     db_session = DBSession()
     for sql in sql_statements:
         try:
             db_session.execute(sql)
         except:
             pass
开发者ID:anushreejangid,项目名称:csm,代码行数:7,代码来源:migrate_to_version_4.py

示例7: run

 def run(self):
     db_session = DBSession()   
     try:         
         system_option = SystemOption.get(db_session)            
         inventory_hour = system_option.inventory_hour
         db_session.close()
                     
         # Build a scheduler object that will look at absolute times
         scheduler = sched.scheduler(time.time, time.sleep)
         current_hour = datetime.datetime.now().hour
 
         # Put task for today at the designated hour.
         daily_time = datetime.time(inventory_hour)
         
         # If the scheduled time already passed, schedule it for tomorrow
         if current_hour > inventory_hour:
             first_time = datetime.datetime.combine(datetime.datetime.now() + datetime.timedelta(days=1), daily_time)
         else:
             first_time = datetime.datetime.combine(datetime.datetime.now(), daily_time)
         
         scheduler.enterabs(time.mktime(first_time.timetuple()), 1,
             self.scheduling, (scheduler, daily_time,))
        
         scheduler.run()
         
     except:
         logger.exception('InventoryManagerScheduler hit exception')
         db_session.close()
开发者ID:ommaurya,项目名称:csm,代码行数:28,代码来源:scheduler.py

示例8: user_create

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)
开发者ID:smjurcak,项目名称:csm,代码行数:33,代码来源:authenticate.py

示例9: dispatch

    def dispatch(self):
        db_session = DBSession()

        try:
            # Check if Scheduled Installs are allowed to run.
            if not db_session.query(SystemOption).first().can_install:
                return
                
            install_jobs = db_session.query(InstallJob).filter(
                InstallJob.scheduled_time <= datetime.datetime.utcnow()).order_by(InstallJob.scheduled_time.asc()).all()
            download_job_key_dict = get_download_job_key_dict()

            if len(install_jobs) > 0:
                for install_job in install_jobs:
                    if install_job.status != JobStatus.FAILED:
                        # If there is pending download, don't submit the install job
                        if self.is_pending_on_download(download_job_key_dict, install_job):
                            continue

                        # This install job has a dependency, check if the expected criteria is met
                        if install_job.dependency is not None:
                            dependency_completed = self.get_install_job_dependency_completed(db_session, install_job)
                            # If the dependency has not been completed, don't proceed
                            if len(dependency_completed) == 0:
                                continue

                        self.submit_job(InstallWorkUnit(install_job.host_id, install_job.id))

        except Exception:
            # print(traceback.format_exc())
            # Purpose ignore.  Otherwise, it may generate continue exception
            pass
        finally:
            db_session.close()
开发者ID:smjurcak,项目名称:csm,代码行数:34,代码来源:sum.py

示例10: api_get_scheduled_download_jobs

def api_get_scheduled_download_jobs():
    dt_params = DataTableParams(request)
    db_session = DBSession()

    clauses = []
    if len(dt_params.search_value):
        criteria = '%' + dt_params.search_value + '%'
        clauses.append(DownloadJob.cco_filename.like(criteria))
        clauses.append(DownloadJob.scheduled_time.like(criteria))
        clauses.append(DownloadJob.created_by.like(criteria))

    query = db_session.query(DownloadJob)

    total_count = query.filter(DownloadJob.status == None).count()
    filtered_count = query.filter(and_(DownloadJob.status == None), or_(*clauses)).count()

    columns = [getattr(DownloadJob.cco_filename, dt_params.sort_order)(),
               getattr(DownloadJob.scheduled_time, dt_params.sort_order)(),
               '',
               getattr(DownloadJob.created_by, dt_params.sort_order)()]

    download_jobs = query.order_by(columns[dt_params.column_order])\
        .filter(and_(DownloadJob.status == None), or_(*clauses))\
        .slice(dt_params.start_length, dt_params.start_length + dt_params.display_length).all()

    response = dict()
    response['draw'] = dt_params.draw
    response['recordsTotal'] = total_count
    response['recordsFiltered'] = filtered_count
    response.update(get_download_job_json_dict(db_session, download_jobs))

    return jsonify(**response)
开发者ID:smjurcak,项目名称:csm,代码行数:32,代码来源:datatable.py

示例11: api_create_tar_job

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})
开发者ID:anushreejangid,项目名称:csm,代码行数:28,代码来源:tar_support.py

示例12: api_get_smu_details

def api_get_smu_details(smu_id):
    rows = []
    db_session = DBSession()

    smu_info = db_session.query(SMUInfo).filter(SMUInfo.id == smu_id).first()
    if smu_info is not None:
        row = dict()
        row['id'] = smu_info.id
        row['name'] = smu_info.name
        row['status'] = smu_info.status
        row['type'] = smu_info.type
        row['posted_date'] = smu_info.posted_date
        row['ddts'] = smu_info.ddts
        row['description'] = smu_info.description
        row['functional_areas'] = smu_info.functional_areas
        row['impact'] = smu_info.impact
        row['package_bundles'] = smu_info.package_bundles
        row['compressed_image_size'] = str(smu_info.compressed_image_size)
        row['uncompressed_image_size'] = str(smu_info.uncompressed_image_size)
        row['prerequisites'] = smu_info.prerequisites
        row['supersedes'] = smu_info.supersedes
        row['superseded_by'] = smu_info.superseded_by
        row['composite_DDTS'] = smu_info.composite_DDTS
        row['prerequisites_smu_ids'] = get_smu_ids(db_session, smu_info.prerequisites)
        row['supersedes_smu_ids'] = get_smu_ids(db_session, smu_info.supersedes)
        row['superseded_by_smu_ids'] = get_smu_ids(db_session, smu_info.superseded_by)

        rows.append(row)

    return jsonify(**{'data': rows})
开发者ID:smjurcak,项目名称:csm,代码行数:30,代码来源:cco.py

示例13: software_profile_edit

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))
开发者ID:kstaniek,项目名称:csm,代码行数:34,代码来源:conformance.py

示例14: command_profile_edit

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)
开发者ID:anushreejangid,项目名称:csm,代码行数:28,代码来源:custom_command.py

示例15: software_profile_create

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))
开发者ID:kstaniek,项目名称:csm,代码行数:34,代码来源:conformance.py


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