Ejemplo n.º 1
0
def returnListOfConfigurationValues(util):
    '''
        Method that recovers the configuration information about each and every program.
        :param util: Any of the utils that are contained in the framework: domainfy, entify, mailfy, phonefy, searchfy, usufy.
        :return: A dictionary containing the default configuration.
    '''

    VALUES = {}

    # If a api_keys.cfg has not been found, creating it by copying from default
    configPath = os.path.join(getConfigPath()["appPath"], "general.cfg")

    # Checking if the configuration file exists
    if not os.path.exists(configPath):
        # Copy the data from the default folder
        defaultConfigPath = os.path.join(getConfigPath()["appPathDefaults"],
                                         "general.cfg")

        try:
            # Recovering default file
            with open(defaultConfigPath) as iF:
                cont = iF.read()
                # Moving its contents as the default values
                with open(configPath, "w") as oF:
                    oF.write(cont)
        except Exception, e:
            raise errors.DefaultConfigurationFileNotFoundError(
                configPath, defaultConfigPath)
Ejemplo n.º 2
0
def returnListOfConfigurationValues(util):
    """
    Method that recovers the configuration information about each program

    TODO: Grab the default file from the package data instead of storing it in
    the main folder.

    Args:
    -----
        util: Any of the utils that are contained in the framework: domainfy,
            entify, mailfy, phonefy, searchfy, usufy.

    Returns:
    --------
        A dictionary containing the default configuration.
    """

    VALUES = {}

    # If a api_keys.cfg has not been found, creating it by copying from default
    configPath = os.path.join(getConfigPath()["appPath"], "general.cfg")

    # Checking if the configuration file exists
    if not os.path.exists(configPath):
        # Copy the data from the default folder
        defaultConfigPath = os.path.join(getConfigPath()["appPathDefaults"],
                                         "general.cfg")

        try:
            # Recovering default file
            with open(defaultConfigPath) as iF:
                cont = iF.read()
                # Moving its contents as the default values
                with open(configPath, "w") as oF:
                    oF.write(cont)
        except Exception as e:
            raise errors.DefaultConfigurationFileNotFoundError(
                configPath, defaultConfigPath)

    # Reading the configuration file
    config = ConfigParser.ConfigParser()
    config.read(configPath)

    LISTS = [
        "tlds", "domains", "platforms", "extension", "exclude_platforms",
        "exclude_domains"
    ]

    # Iterating through all the sections, which contain the platforms
    for section in config.sections():
        incomplete = False
        if section.lower() == util.lower():
            # Iterating through parameters
            for (param, value) in config.items(section):
                if value == '':
                    # Manually setting an empty value
                    if param in LISTS:
                        value = []
                    else:
                        value = ""
                # Splitting the parameters to create the arrays when needed
                elif param in LISTS:
                    value = value.split(' ')
                # Converting threads to int
                elif param == "threads":
                    try:
                        value = int(value)
                    except Exception as err:
                        raise errors.ConfigurationParameterNotValidError(
                            configPath, section, param, value)
                elif param == "debug":
                    try:
                        if int(value) == 0:
                            value = False
                        else:
                            value = True
                    except Exception as err:
                        print(
                            "Something happened when processing this debug option. Resetting to default."
                        )
                        # Copy the data from the default folder
                        defaultConfigPath = os.path.join(
                            getConfigPath()["appPathDefaults"], "general.cfg")

                        try:
                            # Recovering default file
                            with open(defaultConfigPath) as iF:
                                cont = iF.read()
                                # Moving its contents as the default values
                                with open(configPath, "w") as oF:
                                    oF.write(cont)
                        except Exception as e:
                            raise errors.DefaultConfigurationFileNotFoundError(
                                configPath, defaultConfigPath)

                        #raise errors.ConfigurationParameterNotValidError(configPath, section, param, value)
                VALUES[param] = value
            break

    return VALUES
                        raise errors.ConfigurationParameterNotValidError(
                            configPath, section, param, value)
                elif param == "debug":
                    try:
                        if int(value) == 0:
                            value = False
                        else:
                            value = True
                    except Exception as err:
                        print "Something happened when processing this debug option. Resetting to default."
                        # Copy the data from the default folder
                        defaultConfigPath = os.path.join(
                            getConfigPath()["appPathDefaults"], "general.cfg")

                        try:
                            # Recovering default file
                            with open(defaultConfigPath) as iF:
                                cont = iF.read()
                                # Moving its contents as the default values
                                with open(configPath, "w") as oF:
                                    oF.write(cont)
                        except Exception, e:
                            raise errors.DefaultConfigurationFileNotFoundError(
                                configPath, defaultConfigPath)

                        #raise errors.ConfigurationParameterNotValidError(configPath, section, param, value)
                VALUES[param] = value
            break

    return VALUES