Logo Search packages:      
Sourcecode: hellanzb version File versions  Download package

def Hellanzb::Core::loadConfig (   fileName  ) 

Attempt to load the specified config file. If successful, clean the variables/data the
config file has setup 

Definition at line 55 of file Core.py.

00055                         :
    """ Attempt to load the specified config file. If successful, clean the variables/data the
    config file has setup """
    if not os.path.isfile(fileName):
        return False

    if not os.access(fileName, os.R_OK):
        warn('Unable to read config file: ' + fileName)
        return False

        # Cache this operation (whether or not we're in debug mode) for faster (hardly)
        # debug spamming (from NZBLeecher)
        if hasattr(Hellanzb, 'DEBUG_MODE') and Hellanzb.DEBUG_MODE is not None and \
                Hellanzb.DEBUG_MODE != False:
            # Set this ASAP for sane logging. FIXME: You could possibly lose some debug
            # output during initialization if you're using the -d option
            Hellanzb.DEBUG_MODE_ENABLED = True

        # Ensure the types are lower case
        for varName in ('NOT_REQUIRED_FILE_TYPES', 'KEEP_FILE_TYPES'):
            types = getattr(Hellanzb, varName)
            lowerTypes = [ext.lower() for ext in types]
            setattr(Hellanzb, varName, lowerTypes)

        if not hasattr(Hellanzb, 'MAX_RATE') or Hellanzb.MAX_RATE is None:
            Hellanzb.MAX_RATE = 0
            Hellanzb.MAX_RATE = int(Hellanzb.MAX_RATE)

        if not hasattr(Hellanzb, 'UNRAR_CMD') or Hellanzb.UNRAR_CMD is None:
            Hellanzb.UNRAR_CMD = assertIsExe(['rar', 'unrar'])
            Hellanzb.UNRAR_CMD = assertIsExe([Hellanzb.UNRAR_CMD])

        if not hasattr(Hellanzb, 'PAR2_CMD') or Hellanzb.PAR2_CMD is None:
            Hellanzb.PAR2_CMD = assertIsExe(['par2'])
            Hellanzb.PAR2_CMD = assertIsExe([Hellanzb.PAR2_CMD])

        if not hasattr(Hellanzb, 'SKIP_UNRAR') or Hellanzb.SKIP_UNRAR is None:
            Hellanzb.SKIP_UNRAR = False

        if not hasattr(Hellanzb, 'SMART_PAR'):
            Hellanzb.SMART_PAR = True

        if not hasattr(Hellanzb, 'OTHER_NZB_FILE_TYPES'):
            # By default, just match .nzb files in the queue dir
            Hellanzb.NZB_FILE_RE = re.compile(r'(?i)\.(nzb)$')
            nzbTypeRe = r'(?i)\.(%s)$'
            if not isinstance(Hellanzb.OTHER_NZB_FILE_TYPES, list):
                Hellanzb.OTHER_NZB_FILE_TYPES = [Hellanzb.OTHER_NZB_FILE_TYPES]
            if 'nzb' not in Hellanzb.OTHER_NZB_FILE_TYPES:
            typesStr = '|'.join(Hellanzb.OTHER_NZB_FILE_TYPES)
            Hellanzb.NZB_FILE_RE = re.compile(nzbTypeRe % typesStr)

        # Make sure we expand pathnames so that ~ can be used
        for expandPath in ('PREFIX_DIR', 'QUEUE_DIR', 'DEST_DIR', 'POSTPONED_DIR',
                           'CURRENT_DIR', 'TEMP_DIR', 'PROCESSING_DIR', 'STATE_XML_FILE',
                           'WORKING_DIR', 'LOG_FILE', 'DEBUG_MODE',
                           'UNRAR_CMD', 'PAR2_CMD', 'EXTERNAL_HANDLER_SCRIPT'):
                if hasattr(Hellanzb, expandPath):
                        thisDir = getattr(Hellanzb, expandPath)
                        if thisDir is not None:
                                expandedDir = os.path.expanduser(thisDir)
                                setattr(Hellanzb, expandPath, expandedDir)

        if not hasattr(Hellanzb, 'EXTERNAL_HANDLER_SCRIPT') or \
               Hellanzb.EXTERNAL_HANDLER_SCRIPT is None or \
               not os.path.isfile(Hellanzb.EXTERNAL_HANDLER_SCRIPT) or \
               not os.access(Hellanzb.EXTERNAL_HANDLER_SCRIPT, os.X_OK):
            Hellanzb.EXTERNAL_HANDLER_SCRIPT = None

        debug('Found config file in directory: ' + os.path.dirname(fileName))
        return True
    except FatalError, fe:
        error('A problem occurred while reading the config file', fe)
    except Exception, e:
        msg = 'An unexpected error occurred while reading the config file'
        error(msg, e)

# FIXME I think due to the recent change that shutdown()s, then logs -- logShutdown can be
# replaced with normal logging calls
def signalHandler(signum, frame):

Generated by  Doxygen 1.6.0   Back to index