Esempio n. 1
0
def create():
    """ Create a new RSS feed over XHR

    :return: Feed creation status response
    :rtype: Response
    """
    status = api.STATUS_FAIL

    feed = "rss_{0}".format(re.sub('[^0-9a-zA-Z]+', '_', request.values['feed'].lower()))
    if config.has_section(feed):
        msg = "Duplicate feed name"
    else:
        config.add_section(feed)
        try:
            config.set(feed, "url", request.values['url'])
            config.set(feed, "interval", request.values['interval'])
            config.set(feed, "enabled", request.values['enabled'])
            if config.save():
                msg = "Feed {0} saved successfully, reloading page.".format(request.values['feed'])
                status = api.STATUS_OK
            else:
                msg = "Error saving config to disk."
        except KeyError:
            msg = "Failed to save config. Malformed request: {0}".format(feed)
    log.error(msg) if status == api.STATUS_FAIL else log.info(msg)
    return dict(msg=msg, status=status)
Esempio n. 2
0
def create():
    """ Create a new RSS feed over XHR

    :return: Feed creation status response
    :rtype: Response
    """
    status = api.STATUS_FAIL

    feed = "rss_{0}".format(re.sub('[^0-9a-zA-Z]+', '_', request.values['feed'].lower()))
    if config.has_section(feed):
        msg = "Duplicate feed name"
    else:
        config.add_section(feed)
        try:
            config.set(feed, "url", request.values['url'])
            config.set(feed, "interval", request.values['interval'])
            config.set(feed, "enabled", request.values['enabled'])
            if config.save():
                msg = "Feed {0} saved successfully, reloading page.".format(request.values['feed'])
                status = api.STATUS_OK
            else:
                msg = "Error saving config to disk."
        except KeyError:
            msg = "Failed to save config. Malformed request: {0}".format(feed)
    log.error(msg) if status == api.STATUS_FAIL else log.info(msg)
    return dict(msg=msg, status=status)
Esempio n. 3
0
def create():
    status = 1
    try:
        feed = "rss_{0}".format(request.values['new_short_name'])
        if config.has_section(feed):
            raise KeyError()
        else:
            config.add_section(feed)
    except KeyError:
        msg = "Duplicate feed name"
    else:
        try:
            config.set(feed, "url", request.values['new_url'])
            config.set(feed, "interval", request.values['new_interval'])
            config.set(feed, "enabled", request.values['new_enabled'])

            if config.save():
                msg = "RSS Feed saved successfully: {0}".format(request.values['new_short_name'])
                status = 0
            else:
                msg = "Error saving config to disk."
        except KeyError:
            msg = "Failed to save config. Malformed request: {0}".format(feed)
    if status == 1:
        logger.error(msg)
    else:
        logger.info(msg)
    return redirect(url_for(".index"))
Esempio n. 4
0
def save():
    """ Save the new config values of an existing feed over XHR

    :return: Save status response
    :rtype: dict
    """
    status = api.STATUS_FAIL

    feed = "rss_{0}".format(request.values['feed'])
    if not config.has_section(feed):
        msg = "Invalid feed name"
    else:
        try:
            config.set(feed, "url", request.values['url'])
            config.set(feed, "interval", request.values['interval'])
            config.set(feed, "enabled", request.values['enabled'])
            config.save()
            msg = "RSS Feed saved successfully: {0}".format(request.values['feed'])
            status = api.STATUS_OK
        except KeyError:
            msg = "Failed to save config. Malformed request: {0}".format(feed)
    return dict(msg=msg, status=status)
Esempio n. 5
0
def save():
    """ Save the new config values of an existing feed over XHR

    :return: Save status response
    :rtype: dict
    """
    status = api.STATUS_FAIL

    feed = "rss_{0}".format(request.values['feed'])
    if not config.has_section(feed):
        msg = "Invalid feed name"
    else:
        try:
            config.set(feed, "url", request.values['url'])
            config.set(feed, "interval", request.values['interval'])
            config.set(feed, "enabled", request.values['enabled'])
            config.save()
            msg = "RSS Feed saved successfully: {0}".format(request.values['feed'])
            status = api.STATUS_OK
        except KeyError:
            msg = "Failed to save config. Malformed request: {0}".format(feed)
    return dict(msg=msg, status=status)
Esempio n. 6
0
def save(service):
    try:
        for k, v in request.values.items():
            config.set(service, k.replace(service + "_", ""), v)
    except (KeyError, TypeError):
        logger.warning("Malformed request received")
        abort(httplib.BAD_REQUEST)
    else:
        if config.save():
            flash("Saved configuration successfully")
        else:
            flash("There was an error saving your config")
        return redirect(url_for(".index"))
Esempio n. 7
0
def delete():
    """ Delete a RSS feed from the config over XHR

    :return: Deletion status response
    :rtype: dict
    """
    status = api.STATUS_FAIL

    feed = "rss_{0}".format(re.sub('[^0-9a-zA-Z]+', '_', request.values['feed'].lower()))
    if not config.has_section(feed):
        msg = "Invalid feed name"
    else:
        if config.remove_section(feed) and config.save():
            msg = "RSS Feed deleted successfully: {0}".format(request.values['feed'])
            status = api.STATUS_OK
        else:
            msg = "Failed to remove configuration section: {0}".format(feed)
    return dict(msg=msg, status=status)
Esempio n. 8
0
def delete():
    """ Delete a RSS feed from the config over XHR

    :return: Deletion status response
    :rtype: dict
    """
    status = api.STATUS_FAIL

    feed = "rss_{0}".format(re.sub('[^0-9a-zA-Z]+', '_', request.values['feed'].lower()))
    if not config.has_section(feed):
        msg = "Invalid feed name"
    else:
        if config.remove_section(feed) and config.save():
            msg = "RSS Feed deleted successfully: {0}".format(request.values['feed'])
            status = api.STATUS_OK
        else:
            msg = "Failed to remove configuration section: {0}".format(feed)
    return dict(msg=msg, status=status)
Esempio n. 9
0
def save():
    """ Save the settings for the posted config section

    :return: Save status response
    :rtype: dict
    """
    for name, value in request.values.items():
        section, key = name.split("__")
        if value == "on":
            value = "true"
        elif value == "off":
            value = "false"
        config.set(section, key, value)
    if config.save():
        status = api.STATUS_OK
        msg = "Saved settings successfully"
    else:
        status = api.STATUS_FAIL
        msg = "Error saving settings"
    return {"msg": msg, "status": status}
Esempio n. 10
0
def save():
    """ Save the settings for the posted config section

    :return: Save status response
    :rtype: dict
    """
    for name, value in list(request.values.items()):
        section, key = name.split("__")
        if value == "on":
            value = "true"
        elif value == "off":
            value = "false"
        config.set(section, key, value)
    if config.save():
        status = api.STATUS_OK
        msg = "Saved settings successfully"
    else:
        status = api.STATUS_FAIL
        msg = "Error saving settings"
    return {'msg': msg, 'status': status}
Esempio n. 11
0
def delete():
    status = 1
    try:
        feed = "rss_{0}".format(request.values['feed'])
        if not config.has_section(feed):
            raise KeyError()
    except KeyError:
        msg = "Invalid feed name"
    else:

        if config.remove_section(feed) and config.save():
            msg = "RSS Feed deleted successfully: {0}".format(request.values['feed'])
            status = 0
        else:
            msg = "Failed to remove configuration section: {0}".format(feed)
    response = {
        'msg': msg,
        'status': status
    }
    return dumps(response)
Esempio n. 12
0
def save(provider):
    """ Save a providers configuration

    TODO Use PUT?

    :param provider: Provider key/name
    :type provider: unicode
    :return: Redirect response
    :rtype: Response
    """
    try:
        for k, v in request.values.items():
            config.set(provider, k.replace(provider + "_", ""), v)
    except (KeyError, TypeError):
        log.warning("Malformed request received")
        abort(httplib.BAD_REQUEST)
    else:
        if config.save():
            flash("Saved configuration successfully")
        else:
            flash("There was an error saving your provider config")
        return redirect(url_for(".index"))
Esempio n. 13
0
def save(provider):
    """ Save a providers configuration

    TODO Use PUT?

    :param provider: Provider key/name
    :type provider: unicode
    :return: Redirect response
    :rtype: Response
    """
    try:
        for k, v in request.values.items():
            config.set(provider, k.replace(provider + "_", ""), v)
    except (KeyError, TypeError):
        log.warning("Malformed request received")
        abort(httplib.BAD_REQUEST)
    else:
        if config.save():
            flash("Saved configuration successfully")
        else:
            flash("There was an error saving your provider config")
        return redirect(url_for(".index"))