Exemplo n.º 1
0
def backup():
    from nzbhydra import update
    logger.debug("Starting backup")
    backup_folder = os.path.join(nzbhydra.getBasePath(), "backup")
    logger.debug("Using backup folder %s" % backup_folder)
    if not os.path.exists(backup_folder):
        logger.debug("Backup folder %s doesn't exist. Creating it." % backup_folder)
        os.mkdir(backup_folder)
    backup_file = os.path.join(backup_folder, "nzbhydra-backup-%s.zip" % arrow.now().format("YYYY-MM-DD-HH-mm"))
    logger.debug("Writing backup to file %s" % backup_file)
    logger.debug("Compressing ZIP file" if compression == zipfile.ZIP_DEFLATED else "zlib not found. Not compressing ZIP file")
    zf = zipfile.ZipFile(backup_file, mode="w")
    fileInfo = json.dumps({"configFile": os.path.basename(nzbhydra.configFile),
                           "databaseFile": os.path.basename(nzbhydra.databaseFile),
                           "version": update.get_current_version()[1]})
    
    try:
        zf.write(nzbhydra.configFile, arcname=os.path.basename(nzbhydra.configFile), compress_type=compression)
        zf.write(nzbhydra.databaseFile, arcname=os.path.basename(nzbhydra.databaseFile), compress_type=compression)
        zf.writestr("hydraBackupInfo.txt", fileInfo, compress_type=compression)
        zf.close()
        logger.info("Successfully backed up database and settings to %s" % backup_file)
        return backup_file
    except Exception as e:
        logger.exception("Error creating backup file")
        return None
Exemplo n.º 2
0
def base(path):
    logger.debug("Sending index.html")
    base_url = ("/" + config.settings.main.urlBase + "/").replace("//", "/") if config.settings.main.urlBase else "/"
    _, currentVersion = get_current_version()

        
    bootstrapped = {
        "baseUrl": base_url,
        "authType": config.settings.auth.authType,
        "showAdmin": not config.settings.auth.restrictAdmin or len(config.settings.auth.users) == 0 or config.settings.auth.authType == "none",
        "showStats": not config.settings.auth.restrictStats or len(config.settings.auth.users) == 0 or config.settings.auth.authType == "none",
        "maySeeAdmin": not config.settings.auth.restrictAdmin or len(config.settings.auth.users) == 0 or config.settings.auth.authType == "none",
        "maySeeStats": not config.settings.auth.restrictStats or len(config.settings.auth.users) == 0 or config.settings.auth.authType == "none",
        "maySeeSearch": not config.settings.auth.restrictSearch or len(config.settings.auth.users) == 0 or config.settings.auth.authType == "none",
    }
    if request.authorization:
        for u in config.settings.auth.users:
            if u.username == request.authorization.username:
                if config.settings.auth.restrictAdmin:
                    bootstrapped["maySeeAdmin"] = u.maySeeAdmin
                    bootstrapped["showAdmin"] = u.maySeeAdmin
                if config.settings.auth.restrictStats:
                    bootstrapped["maySeeStats"] = u.maySeeStats
                    bootstrapped["showStats"] = u.maySeeStats
    else:
        bootstrapped["showStats"] = True
        bootstrapped["showAdmin"] = True
        

    return render_template("index.html", base_url=base_url, onProd="false" if config.settings.main.debug else "true", theme=config.settings.main.theme + ".css", bootstrapped=json.dumps(bootstrapped))
Exemplo n.º 3
0
def base(path):
    logger.debug("Sending index.html")
    base_url = ("/" + config.settings.main.urlBase + "/").replace(
        "//", "/") if config.settings.main.urlBase else "/"
    _, currentVersion = get_current_version()
    return render_template(
        "index.html",
        base_url=base_url,
        isAdmin=isAdminLoggedIn(),
        onProd="false" if config.settings.main.debug else "true")
Exemplo n.º 4
0
def internalapi_getversions():
    current_version, current_version_readable = get_current_version()
    rep_version, rep_version_readable = get_rep_version()

    versionsInfo = {"currentVersion": str(current_version_readable), "repVersion": str(rep_version_readable), "updateAvailable": rep_version > current_version}

    if rep_version > current_version:
        changelog = getChangelog(current_version_readable, rep_version_readable)
        versionsInfo["changelog"] = changelog

    return jsonify(versionsInfo)
Exemplo n.º 5
0
def internalapi_getversions():
    logger.debug("Get versions request")
    _, current_version = get_current_version()
    _, rep_version = get_rep_version()

    versionsInfo = {"currentVersion": str(current_version), "repVersion": str(rep_version), "updateAvailable": rep_version > current_version}

    if rep_version > current_version:
        changelog = getChangelog(current_version)
        versionsInfo["changelog"] = changelog

    return jsonify(versionsInfo)
Exemplo n.º 6
0
def internalapi_getversions():
    logger.debug("Get versions request")
    _, current_version = get_current_version()
    _, rep_version = get_rep_version()
    
    versionsInfo = {"currentVersion": str(current_version), "repVersion": str(rep_version), "updateAvailable": rep_version > current_version}
    
    if rep_version > current_version:
        changelog = getChangelog(current_version)
        versionsInfo["changelog"] = changelog

    return jsonify(versionsInfo)
Exemplo n.º 7
0
def backup():
    from nzbhydra import update
    logger.debug("Starting backup")
    backup_folder = os.path.join(nzbhydra.getBasePath(), "backup")
    logger.debug("Using backup folder %s" % backup_folder)
    if not os.path.exists(backup_folder):
        logger.debug("Backup folder %s doesn't exist. Creating it." %
                     backup_folder)
        os.mkdir(backup_folder)
    backup_file = os.path.join(
        backup_folder,
        "nzbhydra-backup-%s.zip" % arrow.now().format("YYYY-MM-DD-HH-mm"))
    logger.debug("Writing backup to file %s" % backup_file)
    logger.debug("Compressing ZIP file" if compression == zipfile.
                 ZIP_DEFLATED else "zlib not found. Not compressing ZIP file")
    zf = zipfile.ZipFile(backup_file, mode="w")
    fileInfo = json.dumps({
        "configFile":
        os.path.basename(nzbhydra.configFile),
        "databaseFile":
        os.path.basename(nzbhydra.databaseFile),
        "version":
        update.get_current_version()[1]
    })

    try:
        zf.write(nzbhydra.configFile,
                 arcname=os.path.basename(nzbhydra.configFile),
                 compress_type=compression)
        zf.write(nzbhydra.databaseFile,
                 arcname=os.path.basename(nzbhydra.databaseFile),
                 compress_type=compression)
        zf.writestr("hydraBackupInfo.txt", fileInfo, compress_type=compression)
        zf.close()
        logger.info("Successfully backed up database and settings to %s" %
                    backup_file)
        return backup_file
    except Exception as e:
        logger.exception("Error creating backup file")
        return None
Exemplo n.º 8
0
import json
import os
import requests
from bs4 import BeautifulSoup
from subprocess import call
from nzbhydra import update

DO_PUSH = DO_RELEASE = True

_, version = update.get_current_version()

html = update.getVersionHistory(sinceLastVersion=True)
find_all = [x.text for x in BeautifulSoup(html, "html.parser").findAll("p")]
text = '\n\n'.join(find_all)

returncode = call(["buildWindowsdist.cmd", version])

if returncode == 0 and DO_PUSH:
    returncode = call(["pushWindowsdist.cmd", version])

if returncode == 0 and DO_RELEASE:
    token = os.environ.get("TOKEN")
    data = {
        "tag_name": version,
        "target_commitish": "master",
        "name": version,
        "body": text,
        "draft": False,
        "prerelease": False
    }
    r = requests.post(
Exemplo n.º 9
0
import json
import os
import requests
from bs4 import BeautifulSoup
from subprocess import call
from nzbhydra import update

DO_PUSH = DO_RELEASE = True

_, version = update.get_current_version()

html = update.getVersionHistory(sinceLastVersion=True)
find_all = [x.text for x in BeautifulSoup(html, "html.parser").findAll("p")]
text = '\n\n'.join(find_all)

returncode = call(["buildWindowsdist.cmd", version])

if returncode == 0 and DO_PUSH:
    returncode = call(["pushWindowsdist.cmd", version])

if returncode == 0 and DO_RELEASE:
    token = os.environ.get("TOKEN")
    data = {"tag_name": version, "target_commitish": "master", "name": version, "body": text, "draft": False, "prerelease": False}
    r = requests.post("https://api.github.com/repos/theotherp/nzbhydra-windows-releases/releases?access_token=" + token, data=json.dumps(data))
    r.raise_for_status()

    token = os.environ.get("TOKEN")
    data = {"tag_name": version, "target_commitish": "master", "name": version, "body": text, "draft": False, "prerelease": False}
    r = requests.post("https://api.github.com/repos/theotherp/nzbhydra/releases?access_token=" + token, data=json.dumps(data))
    r.raise_for_status()
Exemplo n.º 10
0
def internalapi_getchangelog():
    logger.debug("Get changelog request")
    _, current_version = get_current_version()
    changelog = getChangelog(current_version)
    return jsonify({"changelog": changelog})
Exemplo n.º 11
0
def base(path):
    logger.debug("Sending index.html")
    base_url = ("/" + config.settings.main.urlBase + "/").replace("//", "/") if config.settings.main.urlBase else "/"
    _, currentVersion = get_current_version()
    return render_template("index.html", base_url=base_url, isAdmin=isAdminLoggedIn(), onProd="false" if config.settings.main.debug else "true")
Exemplo n.º 12
0
def internalapi_getchangelog(args):
    _, current_version_readable = get_current_version()
    changelog = getChangelog(args["currentVersion"], args["repVersion"])
    return jsonify({"changelog": changelog})
Exemplo n.º 13
0
def internalapi_getchangelog():
    logger.debug("Get changelog request")
    _, current_version = get_current_version()
    changelog = getChangelog(current_version)
    return jsonify({"changelog": changelog})
Exemplo n.º 14
0
def base(path):
    logger.debug("Sending index.html")
    host_url = "//" + request.host + request.environ['MY_URL_BASE']
    _, currentVersion = get_current_version()
    return render_template("index.html", host_url=host_url, isAdmin=isAdminLoggedIn(), onProd="false" if config.settings.main.debug else "true")