コード例 #1
0
ファイル: backup_debug.py プロジェクト: gspu/nzbhydra
def getDebuggingInfos():
    logger.debug("Starting creation of debugging infos ZIP")
    ac = json.dumps(config.getAnonymizedConfig(), indent=4)
    debug_folder = os.path.join(nzbhydra.getBasePath(), "debug")
    logger.debug("Using debug folder %s" % debug_folder)
    if not os.path.exists(debug_folder):
        logger.debug("Debug folder %s doesn't exist. Creating it." % debug_folder)
        os.mkdir(debug_folder)
    debuginfo_file = os.path.join(debug_folder, "nzbhydra-debuginfo-%s.zip" % arrow.now().format("YYYY-MM-DD-HH-mm"))
    logger.debug("Writing debugging info to file %s" % debuginfo_file)
    logger.debug("Using compression for ZIP file" if compression == zipfile.ZIP_DEFLATED else "zlib not found. Not compressing ZIP file")

    al_file = os.path.join(debug_folder, "logfile.txt")
    log.getAnonymizedLogFile(config.getSettingsToHide(), al_file)

    ac_file = os.path.join(debug_folder, "settings.txt")
    logger.debug("Writing settings to temp file %s" % ac_file)
    with codecs.open(ac_file, "w", "utf-8") as textfile:
        textfile.write(ac)

    logger.debug("Writing ZIP file")
    zf = zipfile.ZipFile(debuginfo_file, mode="w")
    try:
        zf.write(filename=al_file, arcname=os.path.basename(al_file), compress_type=compression)
        zf.write(filename=ac_file, arcname=os.path.basename(ac_file), compress_type=compression)
        
        zf.close()
        os.remove(ac_file)
        os.remove(al_file)
        logger.info("Successfully wrote debugging infos to file %s" % debuginfo_file)
        return debuginfo_file
    except Exception as e:
        logger.exception("Error creating debug infos")
        return None
コード例 #2
0
ファイル: test_Config.py プロジェクト: junkman690/nzbhydra
 def testGetAnonymizedConfig(self):
     config.settings = {
         "downloader": {
             "nzbget": {
                 "host": "3.4.5.6",
                 "password": "******",
                 "username": "******"
             },
             "sabnzbd": {
                 "apikey": "sabnzbdapikey",
                 "password": "******",
                 "url": "http://localhost:8080/sabnzbd/",
                 "username": "******"
             }
         },
         "indexers": {
             "newznab": [
                 {
                     "apikey": "newznabapikey",
                 },
             ],
             "omgwtfnzbs": {
                 "apikey": "omgwtfapikey",
                 "username": "******"
             }
         },
         "main": {
             "apikey": "hydraapikey",
             "externalUrl": "http://www.hydradomain.com/nzbhydra",
             "host": "1.2.3.4"
         },
         "auth": {
             "users": [
                 {
                     "username": "******",
                     "password": "******"
                 }
             ]
         }
     }
     ac = config.getAnonymizedConfig()
     ac = Bunch.fromDict(ac)
     self.assertEqual("<APIKEY:3f7ccf2fa729e7329f8d2af3ae5b2d00>", ac.indexers.newznab[0].apikey)
     self.assertEqual("<USERNAME:be1cd7618f0bc25e333d996582c037b2>", ac.indexers.omgwtfnzbs.username)
     self.assertEqual("<APIKEY:680eae14a056ebd0d1c71dbfb6c5ebbc>", ac.indexers.omgwtfnzbs.apikey)
     self.assertEqual("<IPADDRESS:6465ec74397c9126916786bbcd6d7601>", ac.main.host)
     self.assertEqual("<APIKEY:b5f0bb7a7671d14f3d79866bcdfac6b5>", ac.main.apikey)
     self.assertEqual("http://<DOMAIN:ea2cbe92bacf786835b93ff2ca78c459>/nzbhydra", ac.main.externalUrl)
     self.assertEqual("<USERNAME:25adeda6f43bf9adf9781d29d1435986>", ac.auth.users[0].username)
     self.assertEqual("<PASSWORD:9c42a1346e333a770904b2a2b37fa7d3>", ac.auth.users[0].password)
     self.assertEqual("<USERNAME:df60a3d2b6cdc05d169e684c0aaa7b20>", ac.downloader.nzbget.username)
     self.assertEqual("<IPADDRESS:c6deeee6bee7ff3d4cc2048843f5678b>", ac.downloader.nzbget.host)
     self.assertEqual("<PASSWORD:78afef0fe4ffe1ed97aff6ab577ef5a4>", ac.downloader.nzbget.password)
     self.assertEqual("http://<NOTIPADDRESSORDOMAIN:421aa90e079fa326b6494f812ad13e79>:8080/sabnzbd/", ac.downloader.sabnzbd.url)
     self.assertEqual("<USERNAME:96c4173454468a77d67b2c813ffe307a>", ac.downloader.sabnzbd.username)
     self.assertEqual("<APIKEY:f5095bc1520183e76be64af1c5f9e7e3>", ac.downloader.sabnzbd.apikey)
     self.assertEqual("<PASSWORD:4c471a175d85451486af666d7eebe4f8>", ac.downloader.sabnzbd.password)
コード例 #3
0
ファイル: test_Config.py プロジェクト: petrichor8/nzbhydra
 def testGetAnonymizedConfig(self):
     config.settings = {
         "downloader": {
             "nzbget": {
                 "host": "3.4.5.6",
                 "password": "******",
                 "username": "******"
             },
             "sabnzbd": {
                 "apikey": "sabnzbdapikey",
                 "password": "******",
                 "url": "http://localhost:8080/sabnzbd/",
                 "username": "******"
             }
         },
         "indexers": {
             "newznab": [
                 {
                     "apikey": "newznabapikey",
                 },
             ],
             "omgwtfnzbs": {
                 "apikey": "omgwtfapikey",
                 "username": "******"
             }
         },
         "main": {
             "apikey": "hydraapikey",
             "externalUrl": "http://www.hydradomain.com/nzbhydra",
             "host": "1.2.3.4"
         },
         "auth": {
             "users": [
                 {
                     "username": "******",
                     "password": "******"
                 }
             ]
         }
     }
     ac = config.getAnonymizedConfig()
     ac = Bunch.fromDict(ac)
     self.assertEqual("<APIKEY:3f7ccf2fa729e7329f8d2af3ae5b2d00>", ac.indexers.newznab[0].apikey)
     self.assertEqual("<USERNAME:be1cd7618f0bc25e333d996582c037b2>", ac.indexers.omgwtfnzbs.username)
     self.assertEqual("<APIKEY:680eae14a056ebd0d1c71dbfb6c5ebbc>", ac.indexers.omgwtfnzbs.apikey)
     self.assertEqual("<IPADDRESS:6465ec74397c9126916786bbcd6d7601>", ac.main.host)
     self.assertEqual("<APIKEY:b5f0bb7a7671d14f3d79866bcdfac6b5>", ac.main.apikey)
     self.assertEqual("http://<DOMAIN:ea2cbe92bacf786835b93ff2ca78c459>/nzbhydra", ac.main.externalUrl)
     self.assertEqual("<USERNAME:25adeda6f43bf9adf9781d29d1435986>", ac.auth.users[0].username)
     self.assertEqual("<PASSWORD:9c42a1346e333a770904b2a2b37fa7d3>", ac.auth.users[0].password)
     self.assertEqual("<USERNAME:df60a3d2b6cdc05d169e684c0aaa7b20>", ac.downloader.nzbget.username)
     self.assertEqual("<IPADDRESS:c6deeee6bee7ff3d4cc2048843f5678b>", ac.downloader.nzbget.host)
     self.assertEqual("<PASSWORD:78afef0fe4ffe1ed97aff6ab577ef5a4>", ac.downloader.nzbget.password)
     self.assertEqual("http://<NOTIPADDRESSORDOMAIN:421aa90e079fa326b6494f812ad13e79>:8080/sabnzbd/", ac.downloader.sabnzbd.url)
     self.assertEqual("<USERNAME:96c4173454468a77d67b2c813ffe307a>", ac.downloader.sabnzbd.username)
     self.assertEqual("<APIKEY:f5095bc1520183e76be64af1c5f9e7e3>", ac.downloader.sabnzbd.apikey)
     self.assertEqual("<PASSWORD:4c471a175d85451486af666d7eebe4f8>", ac.downloader.sabnzbd.password)
コード例 #4
0
def getDebuggingInfos():
    logger.debug("Starting creation of debugging infos ZIP")
    ac = json.dumps(config.getAnonymizedConfig(), indent=4)
    debug_folder = os.path.join(nzbhydra.getBasePath(), "debug")
    logger.debug("Using debug folder %s" % debug_folder)
    if not os.path.exists(debug_folder):
        logger.debug("Debug folder %s doesn't exist. Creating it." %
                     debug_folder)
        os.mkdir(debug_folder)
    debuginfo_file = os.path.join(
        debug_folder,
        "nzbhydra-debuginfo-%s.zip" % arrow.now().format("YYYY-MM-DD-HH-mm"))
    logger.debug("Writing debugging info to file %s" % debuginfo_file)
    logger.debug("Compressing ZIP file" if compression == zipfile.
                 ZIP_DEFLATED else "zlib not found. Not compressing ZIP file")

    al = log.getAnonymizedLogFile(config.getSettingsToHide())
    al_file = os.path.join(debug_folder, "logfile.txt")
    logger.debug("Writing log to temp file %s" % al_file)
    with codecs.open(al_file, "w", "utf-8") as textfile:
        textfile.write(al)

    ac_file = os.path.join(debug_folder, "settings.txt")
    logger.debug("Writing settings to temp file %s" % ac_file)
    with codecs.open(ac_file, "w", "utf-8") as textfile:
        textfile.write(ac)

    zf = zipfile.ZipFile(debuginfo_file, mode="w")
    try:
        zf.write(filename=al_file,
                 arcname=os.path.basename(al_file),
                 compress_type=compression)
        zf.write(filename=ac_file,
                 arcname=os.path.basename(ac_file),
                 compress_type=compression)

        zf.close()
        os.remove(ac_file)
        os.remove(al_file)
        logger.info("Successfully wrote debugging infos to file %s" %
                    debuginfo_file)
        return debuginfo_file
    except Exception as e:
        logger.exception("Error creating debug infos", e)
        return None