Ejemplo n.º 1
0
    def background():
        if (expected_batches is not None
            ) or expected_idx is not None:  # called with arguments
            execute_all = False
        else:
            execute_all = True

        if plans is None:
            try:
                backups = get_plans_from_db(get_sql_connection())
            except sqlite3.Error:
                return

        for idx, rest in enumerate(backups):
            title, description, source, destination, mode, batch = rest
            if execute_all or \
                    (expected_batches is not None and batch in expected_batches) or \
                    (expected_idx is not None and expected_idx == idx):
                # todo async
                log = ""
                try:
                    print(batch)
                    log = backup(source, destination, mode=mode)
                except ValueError:
                    log = title, "from", source, "to", destination, "has invalid mode", mode
                finally:
                    try:
                        send_notification(title, log)
                    except NotificationError:
                        print(
                            "can't send notification; token is probably incorrect"
                        )
Ejemplo n.º 2
0
def updatePlan():
    # read the posted values from the UI
    _idx = request.form['idx']
    _title = request.form['title']
    _description = request.form['description']
    _src = request.form['src']
    _dest = request.form['dest']
    _arrow = request.form['arrow']
    _batch = request.form['batch']

    if any(_ is None
           for _ in (_idx, _title, _description, _src, _dest, _arrow, _batch)):
        raise BadRequest("Some variable is missing.")

    try:
        sql = get_sql_connection()
        plans = get_plans_from_db(sql)
        pm.edit_plan(sql,
                     plans,
                     idx=_idx,
                     src=_src,
                     dest=_dest,
                     title=_title,
                     description=_description,
                     mode=2 if _arrow == "↔" else 1,
                     batch=_batch)
        close(sql)
    except ValueError as e:  # todo
        return str(e), 400
    except Exception as e:
        print(e)
        return "Error. Reason:" + str(e), 500
    else:
        return "Plan updated.", 200
Ejemplo n.º 3
0
def addPlan():
    # read the posted values from the UI
    _title = request.form['title']
    _description = request.form['description']
    _src = request.form['src']
    _dest = request.form['dest']
    _arrow = request.form['arrow']
    _batch = request.form['batch']

    if any(_ is None
           for _ in (_title, _description, _src, _dest, _arrow, _batch)):
        return "Some variable is missing.", 400

    try:
        sql = get_sql_connection()
        plans = get_plans_from_db(sql)
        pm.add_plan(sql, plans, _title, _description, _src, _dest,
                    2 if _arrow == "↔" else 1, _batch)
        close(sql)
    except ValueError as e:
        return str(e), 400
    except Exception as e:
        print(e)
        return "Error with DB. Reason:" + str(e), 500
    else:
        return "Plan added.", 200
Ejemplo n.º 4
0
def showBackups():
    try:
        sql = get_sql_connection()
        plans = get_plans_from_db(sql)
        close(sql)
    except Exception as e:
        return "Error with DB. Reason:" + str(e), 500

    plans_list = [(id_, plan[TITLE], plan[DESCRIPTION], plan[SRC], plan[DEST],
                   get_html_arrow(plan[MODE]), plan[BATCH])
                  for id_, plan in plans.items()]

    return render_template('backups.html', plans=plans_list)
Ejemplo n.º 5
0
def removePlan():
    # read the posted values from the UI
    idx = request.form['idx']

    if idx is None:
        return "Idx is missing.", 400

    try:
        sql = get_sql_connection()
        plans = get_plans_from_db(sql)
        pm.remove_plan(sql, plans, idx)
        close(sql)
    except Exception as e:
        print(e)
        return "Error with DB. Reason:" + str(e), 500
    else:
        return "Plan removed.", 200