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


Python db_session.add函数代码示例

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


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

示例1: add_edit_disk

def add_edit_disk():
    path = request.form['path']
    name = request.form['name']
    group = request.form['group']
    position = request.form['position']

    if path == '':
        return jsonify({'status': 'error'})

    if position == '':
        position = None

    if 'disk_id' in request.form:
        disk = HardDisk.query.filter(HardDisk.id == request.form['disk_id']).first()
        disk.data = {'path': path, 'name': name, 'group': group}
        disk.position = position

    else:
        disk = HardDisk(
            data={'path': path, 'name': name, 'group': group},
            position=position,
        )

    try:
        db_session.add(disk)
        db_session.commit()

    except:
        return jsonify({'status': 'error'})

    return xhr_diskspace()
开发者ID:wjbridge,项目名称:maraschino,代码行数:31,代码来源:diskspace.py

示例2: switch_server

def switch_server(server_id=None):
    """
    Switches Plex servers manually.
    """
    try:
        active_server = get_setting('active_server')

        if not active_server:
            active_server = Setting('active_server', 0)
            db_session.add(active_server)
            db_session.commit()

        server = PlexServer.query.filter(PlexServer.id == server_id).first()
        if server:
            active_server.value = server_id
            db_session.add(active_server)
            db_session.commit()
            logger.log('Switched active server to ID %s' % server_id , 'INFO')
            try:
                status, msg = plex_update_sections(server_id)
                if not status:
                    logger.log('Plex :: %s' % msg, 'ERROR')
            except Exception as e:
                return jsonify(success=False, msg='Failed to reach server, please check log for details.')
        else:
            logger.log('Switching server prevented, server ID %s does not exist in db' % server_id, 'INFO')

    except Exception as e:
        logger.log('Error setting active server to ID %s: %s' % (server_id, e) , 'WARNING')
        return jsonify(success=False)

    return jsonify(success=True)
开发者ID:RoostayFish,项目名称:maraschino,代码行数:32,代码来源:noneditable.py

示例3: tutorial_save

def tutorial_save():
    global user, servers
    # save login and password on db
    try:
        settings = json.JSONDecoder().decode(request.form['settings'])
        for s in settings:
            setting = get_setting(s['name'])

            if not setting:
                setting = Setting(s['name'])

            setting.value = s['value']
            db_session.add(setting)
        db_session.commit()
        logger.log('Plex :: Successfully saved Plex credentials', 'INFO')
    except:
        return jsonify(success=False, msg='Failed to save plex credentials to db')

    # Delete info for previous accounts
    try:
        PlexServer.query.delete()
    except:
        logger.log('Plex :: Failed to delete old server info', 'WARNING')

    try:
        if loginToPlex(): # login to plex
            servers = getServers()
            if servers: # retrieve servers
                return jsonify(success=True, servers=listServers())
            else:
                return jsonify(sucess=False, msg='Failed to retrieve servers')
        else:
            return jsonify(sucess=False, msg='Failed to login to plex')
    except:
        return jsonify(success=False, msg='Servers not populated Successfully')
开发者ID:RoostayFish,项目名称:maraschino,代码行数:35,代码来源:noneditable.py

示例4: loginToPlex

def loginToPlex(username=None, password=None):
    global user
    if username is None:
        if not get_setting_value('myPlex_username') or not get_setting_value('myPlex_password'):
            logger.log('Plex :: Missing Plex Credentials in db', 'INFO')
            return False
        else:
            username = get_setting_value('myPlex_username')
            password = get_setting_value('myPlex_password')

    logger.log('Plex :: Logging into plex.tv', 'INFO')
    try:
        user = User(username, password)
        user, token = user.MyPlexSignIn()

        if user is '':
            logger.log('Plex :: Log in FAILED', 'ERROR')
            return False # failed to sign in

        setting = get_setting('myPlex_token')
        if not setting:
            setting = Setting('myPlex_token')

        setting.value = token
        db_session.add(setting)
        db_session.commit()
        logger.log('Plex :: Log in successful', 'INFO')
        return True
    except:
        logger.log('Plex :: Log in FAILED', 'ERROR')
        return False
开发者ID:RoostayFish,项目名称:maraschino,代码行数:31,代码来源:noneditable.py

示例5: json_login

def json_login():
    if not loginToPlex():
        return jsonify(success=False, msg='Failed to login to plex.tv, plese make sure this is a valid username/password.')

    # Delete info for previous accounts
    try:
        PlexServer.query.delete()
    except:
        logger.log('Plex :: Failed to delete old server info', 'WARNING')

    # Populate servers for new user
    if not getServers():
        return jsonify(success=False, msg='Failed to retrieve server information from https://plex.tv/pms/servers.')

    # Set active server to 0 (no server selected)
    try:
        active_server = get_setting('active_server')

        if not active_server:
            active_server = Setting('active_server', 0)
            db_session.add(active_server)
            db_session.commit()

        else:
            active_server.value = 0
            db_session.add(active_server)
            db_session.commit()

    except:
        logger.log('Plex :: Failed to reset server, please make sure to select new one.', 'WARNING')

    # return a list of (server name, server id)
    return jsonify(success=True, servers=listServers())
开发者ID:RoostayFish,项目名称:maraschino,代码行数:33,代码来源:noneditable.py

示例6: add_edit_disk

def add_edit_disk():
    path = request.form['path']
    position = request.form['position']

    if path == '':
        return jsonify({ 'status': 'error' })

    if position == '':
        position = None

    if 'disk_id' in request.form:
        disk = Disk.query.filter(Disk.id == request.form['disk_id']).first()
        disk.path = path
        disk.position = position

    else:
        disk = Disk(
            path,
            position,
        )

    try:
        disk_usage(disk.path)
        db_session.add(disk)
        db_session.commit()

    except:
        return jsonify({ 'status': 'error' })

    return xhr_diskspace()
开发者ID:alejandroblanco82,项目名称:maraschino,代码行数:30,代码来源:diskspace.py

示例7: add_edit_application

def add_edit_application():
    name = request.form['name']
    url = request.form['url']
    description = request.form['description']
    image = request.form['image']
    position = request.form['position']

    if name == '' or url == '':
        return jsonify({ 'status': 'error' })

    if position == '':
        position = None

    if 'application_id' in request.form:
        application = Application.query.filter(Application.id == request.form['application_id']).first()
        application.name = name
        application.url = url
        application.description = description
        application.image = image
        application.position = position

    else:
        application = Application(
            name,
            url,
            description,
            image,
            position,
        )

    db_session.add(application)
    db_session.commit()

    return xhr_applications()
开发者ID:BeegorMif,项目名称:maraschino,代码行数:34,代码来源:applications.py

示例8: server_settings_dialog

def server_settings_dialog(server_id=None):
    """
    Server settings dialog.
    If server_id exists then we're editing a server, otherwise we're adding one.
    """

    server = None

    if server_id:
        try:
            server = XbmcServer.query.get(server_id)

        except:
            logger.log('Error retrieving server details for server ID %s' % server_id , 'WARNING')

    # GET

    if request.method == 'GET':
        return render_template('dialogs/server_settings_dialog.html',
            server = server,
        )

    # POST

    else:
        if not server:
            server = XbmcServer('', 1, '')

        label = request.form['label']
        if not label:
            label = 'XBMC server'

        try:
            server.label = label
            server.position = request.form['position']
            server.hostname = request.form['hostname']
            server.port = request.form['port']
            server.username = request.form['username']
            server.password = request.form['password']
            server.mac_address = request.form['mac_address']

            db_session.add(server)
            db_session.commit()

            active_server = get_setting('active_server')

            if not active_server:
                active_server = Setting('active_server', server.id)
                db_session.add(active_server)
                db_session.commit()

            return render_template('includes/servers.html',
                servers = XbmcServer.query.order_by(XbmcServer.position),
            )

        except:
            logger.log('Error saving XBMC server to database', 'WARNING')
            return jsonify({ 'status': 'error' })

    return jsonify({ 'status': 'error' })
开发者ID:wjbridge,项目名称:maraschino,代码行数:60,代码来源:modules.py

示例9: start_script

def start_script(script_id):
    #first get the script we want
    script = None
    message = None
    script = Script.query.filter(Script.id == script_id).first()
    now = datetime.datetime.now()

    command = os.path.join(maraschino.SCRIPT_DIR,script.script)

    if (script.parameters):
        command = ''.join([command, ' ', script.parameters])

    #Parameters needed for scripts that update
    host = maraschino.HOST
    port = maraschino.PORT
    webroot = maraschino.WEBROOT

    if not webroot:
        webroot = '/'

    file_ext = os.path.splitext(script.script)[1]

    if (file_ext == '.py'):
        if (script.updates == 1):        
            #these are extra parameters to be passed to any scripts ran, so they 
            #can update the status if necessary
            extras = '--i "%s" --p "%s" --s "%s" --w "%s"' % (host, port, script.id, webroot)

            #the command in all its glory
            command = ''.join([command, ' ', extras])
            script.status="Script Started at: %s" % now.strftime("%m-%d-%Y %H:%M")
        else:
            script.status="Last Ran: %s" % now.strftime("%m-%d-%Y %H:%M")

        command =  ''.join(['python ', command])

    elif (file_ext in ['.sh', '.pl', '.cmd']):
        if (script.updates == 1):
            extras = '%s %s %s %s' % (host, port, script.id, webroot)
            #the command in all its glory
            command = ''.join([command, ' ', extras])
            script.status="Script Started at: %s" % now.strftime("%m-%d-%Y %H:%M")
        else:
            script.status="Last Ran: %s" % now.strftime("%m-%d-%Y %H:%M")

        if(file_ext == '.pl'):
            command = ''.join(['perl ', command])

        if(file_ext == '.cmd'):
            command = ''.join([command])


    logger.log('SCRIPT_LAUNCHER :: %s' % command, 'INFO')
    #now run the command
    subprocess.Popen(command, shell=True)

    db_session.add(script)
    db_session.commit()

    return script_launcher()  
开发者ID:disengaged,项目名称:maraschino,代码行数:60,代码来源:mobile.py

示例10: add_edit_newznab

def add_edit_newznab():
    name = request.form["name"]
    url = request.form["url"]
    apikey = request.form["apikey"]

    if url.endswith("/"):
        url = url[:-1]

    if not name:
        return jsonify(error=True)
    if not apikey:
        return jsonify(error=True)
    if not url:
        return jsonify(error=True)

    if "newznab_id" in request.form:
        logger.log("SEARCH :: Editing Newznab site %s" % request.form["newznab_id"], "INFO")
        newznab = NewznabSite.query.filter(NewznabSite.id == request.form["newznab_id"]).first()
        newznab.name = name
        newznab.url = url
        newznab.apikey = apikey

    else:
        logger.log("SEARCH :: Adding new Newznab site", "INFO")
        newznab = NewznabSite(name=name, url=url, apikey=apikey)

    try:
        db_session.add(newznab)
        db_session.commit()

    except Exception as e:
        logger.log(e, "DEBUG")
        return jsonify(error=True)

    return xhr_search()
开发者ID:stefaanlepever,项目名称:maraschino,代码行数:35,代码来源:search.py

示例11: module_settings_save

def module_settings_save(name):
    """Save options in settings dialog"""
    try:
        settings = json.JSONDecoder().decode(request.form['settings'])
    except:
        return jsonify({ 'status': 'error' })

    for s in settings:

        # poll and delay are stored in the modules tables

        if s['name'] == 'poll' or s['name'] == 'delay':
            module = get_module(name)

            if s['name'] == 'poll':
                module.poll = int(s['value'])

            if s['name'] == 'delay':
                module.delay = int(s['value'])

            db_session.add(module)

        # other settings are stored in the settings table

        else:
            setting = get_setting(s['name'])

            if not setting:
                setting = Setting(s['name'])

            setting.value = s['value']
            db_session.add(setting)

            if s['name'] == 'maraschino_username':
                maraschino.AUTH['username'] = s['value'] if s['value'] != '' else None

            if s['name'] == 'maraschino_password':
                maraschino.AUTH['password'] = s['value'] if s['value'] != '' else None

    db_session.commit()

    # you can't cancel server settings - instead, return an updated template
    # with 'Settings saved' text on the button

    if name == 'server_settings':
        return extra_settings_dialog(dialog_type='server_settings', updated=True)
    elif name == 'plex_login':
        from maraschino.noneditable import json_login
        try:
            return json_login()
        except:
            logger.log('Plex :: Failed to populate servers with new credentials', 'ERROR')


    # for everything else, return the rendered module

    return module_settings_cancel(name)
开发者ID:Torf,项目名称:maraschino,代码行数:57,代码来源:modules.py

示例12: server_settings_dialog

def server_settings_dialog(server_id=None):
    """
    Server settings dialog.
    If server_id exists then we're editing a server, otherwise we're adding one.
    """

    server = None

    if server_id:
        try:
            server = XbmcServer.query.get(server_id)

        except:
            logger.log("Error retrieving server details for server ID %s" % server_id, "WARNING")

    # GET

    if request.method == "GET":
        return render_template("dialogs/server_settings_dialog.html", server=server)

    # POST

    else:
        if not server:
            server = XbmcServer("", 1, "")

        label = request.form["label"]
        if not label:
            label = "XBMC server"

        try:
            server.label = label
            server.position = request.form["position"]
            server.hostname = request.form["hostname"]
            server.port = request.form["port"]
            server.username = request.form["username"]
            server.password = request.form["password"]
            server.mac_address = request.form["mac_address"]

            db_session.add(server)
            db_session.commit()

            active_server = get_setting("active_server")

            if not active_server:
                active_server = Setting("active_server", server.id)
                db_session.add(active_server)
                db_session.commit()

            return render_template("includes/servers.html", servers=XbmcServer.query.order_by(XbmcServer.position))

        except:
            logger.log("Error saving XBMC server to database", "WARNING")
            return jsonify({"status": "error"})

    return jsonify({"status": "error"})
开发者ID:robweber,项目名称:maraschino,代码行数:56,代码来源:modules.py

示例13: plex_update_sections

def plex_update_sections(id):
    db_section = {
        'movie': {'size': 0, 'sections': {}, 'label': 'movie', 'preferred': 0},
        'home': {'size': 0, 'sections': {}, 'label': 'home', 'preferred': 0},
        'photo': {'size': 0, 'sections': {}, 'label': 'photo', 'preferred': 0},
        'artist': {'size': 0, 'sections': {}, 'label': 'artist', 'preferred': 0},
        'show': {'size': 0, 'sections': {}, 'label': 'show', 'preferred': 0},
    }

    # attempt to get sections from server
    dbserver = PlexServer.query.filter(PlexServer.id == id).first()
    try:
        server = Server(dbserver.localAddresses, token=dbserver.token)
        sections = server.sections()
        if not sections:
            return (False, 'Failed to get sections')
    except:
        return (False, 'Failed to retrieve server with id: %i' %id)

    # keeping old preferred sections
    try:
        db_section['movie']['preferred'] = dbserver.sections['movie']['preferred']
        db_section['home']['preferred'] = dbserver.sections['home']['preferred']
        db_section['photo']['preferred'] = dbserver.sections['photo']['preferred']
        db_section['artist']['preferred'] = dbserver.sections['artist']['preferred']
        db_section['show']['preferred'] = dbserver.sections['show']['preferred']
    except:
        pass

    # Go through each section and add it to new section dictionary
    try:
        for section in sections:
            if 'video' in section['thumb']:
                section['type'] = u'home'

            db_section[section['type']]['sections'].update(
                {
                    db_section[section['type']]['size']:
                    {
                        'key': section['key'],
                        'type': section['type'],
                        'title': section['title'],
                        'uuid': section['uuid']
                    }
                }
            )
            db_section[section['type']]['size'] += 1
        dbserver.sections = db_section
        db_session.add(dbserver)
        db_session.commit()
        logger.log('Plex :: Successfully updated %s sections' % server, 'INFO')
    except:
        logger.log('Plex :: Failed to update sections for server', 'ERROR')
        return (False, 'Failed to update sections for server')

    return (True, None)
开发者ID:ouldsmobile,项目名称:maraschino,代码行数:56,代码来源:noneditable.py

示例14: savePreferredSection

def savePreferredSection(type, id):
    try:
        server = PlexServer.query.filter(PlexServer.id == get_setting_value('active_server')).first()
        server.sections[type]['preferred'] = int(id)
        db_session.add(server)
        db_session.commit()
        logger.log('Plex :: Changed preferred %s section to %i' %(type, id), 'INFO')
        return jsonify(success=True)
    except:
        return jsonify(success=False, msg='Failed to set preferred category')
开发者ID:RoostayFish,项目名称:maraschino,代码行数:10,代码来源:noneditable.py

示例15: add_module

def add_module():
    """Add a new module to Maraschino"""
    try:
        module_id = request.form['module_id']
        column = request.form['column']
        position = request.form['position']

        # make sure that it's a valid module

        module_info = get_module_info(module_id)

        if not module_info:
            raise Exception

    except:
        return jsonify({ 'status': 'error' })

    module = Module(
        module_info['name'],
        column,
        position,
        module_info['poll'],
        module_info['delay'],
    )

    db_session.add(module)

    # if module template has extra settings then create them in the database
    # with default values if they don't already exist

    if 'settings' in module_info:
        for s in module_info['settings']:
            setting = get_setting(s['key'])

            if not setting:
                setting = Setting(s['key'], s['value'])
                db_session.add(setting)

    db_session.commit()

    module_info['template'] = '%s.html' % (module_info['name'])

    # if the module is static and doesn't have any extra settings, return
    # the rendered module

    if module_info['static'] and not 'settings' in module_info:
        return render_template('placeholder_template.html',
            module = module_info
        )

    # otherwise return the rendered module settings dialog

    else:
        return module_settings_dialog(module_info['name'])
开发者ID:wjbridge,项目名称:maraschino,代码行数:54,代码来源:modules.py


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