netsoc_admin.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:netsocadmin2 作者: UCCNetworkingSociety 项目源码 文件源码
def backup(username:str, timeframe:str, backup_date:str):
    """
    Route: /backup/username/timeframe/backup_date
        This route returns the requested backup.

    :param username the server username of the user needing their backup.
    :param timeframe the timeframe of the requested backup. Can be either
        "weekly", or "monthly".
    :param backup_date the backup-date of the requested backup. Must be in the
        form YYYY-MM-DD.
    """
    if flask.request.method != "GET":
        return flask.abort(400)

    # make sure the arguments are valid
    if not re.match(r"^[a-z]+$", username) or \
            not re.match(r"^[0-9]{4}-[0-9]{2}-[0-9]{2}", backup_date) or \
            timeframe not in ["weekly", "monthly"]:
        app.logger.debug("backups(%s, %s, %s): invalid arguments"%(
                username, timeframe, backup_date))
        return flask.abort(400)

    backups_base_dir = os.path.join(b.BACKUPS_DIR, username, timeframe)
    return flask.send_from_directory(backups_base_dir, backup_date+".tgz")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号