# Path: pycaf/tools/logs.py
# def create_logger(name, config, is_main=False):
#     """
#     Function wich create a logger with settings in config file
#     """
#     # Get if exist the main logger
#     global main_logger
# 
#     # Get previous logger
#     logger = logging.getLogger(name)
# 
#     # If the logger was not previously initialized (no handlers)
#     if not logger.handlers:
#         path = config.logs_path
# 
#         if not is_main:
#             path += tmp_dir_name
# 
#         if not os.path.exists(path):
#             os.makedirs(path)
# 
#         level_str = config.logs_level.lower()
#         if level_str == "debug":
#             level = logging.DEBUG
#         elif level_str == "info":
#             level = logging.INFO
#         elif level_str == "warning":
#             level = logging.WARNING
#         elif level_str == "error":
#             level = logging.ERROR
#         elif level_str == "critical":
#             level = logging.CRITICAL
# 
#         logger.setLevel(level)
# 
#         # Set the log file name stored into de conf file
#         if not is_main:
#             path += name
#         else:
#             path += config.logs_file_name
# 
#         formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
#         hdlr = logging.FileHandler(path, mode='w')
#         hdlr.setFormatter(formatter)
#         logger.addHandler(hdlr)
# 
#         steam_handler = logging.StreamHandler()
#         steam_handler.setLevel(level)
#         logger.addHandler(steam_handler)
# 
#         if is_main:
#             main_logger = logger
#             logger.debug("Main logger : " + str(path))
#             logger.debug("Temp logs path at : " + str(config.logs_path + tmp_dir_name))
# 
#         elif not is_main and (main_logger is not None):
#             main_logger.debug("New logger : " + str(name) + " - path : " + str(path))
# 
#     return logger


import urllib2
import os
import hashlib
import gzip
        import traceback
    import pickle
    import pickle
from pycaf.tools.logs import create_logger
# -*- coding: utf-8 -*-
"""
Created on Tue Apr  8 09:49:19 2014

@author: thierry
"""



def checkInternetAccess(config):
    """
    Function which instanciate an internet connection and return True if it is established
    """
    logger = create_logger(__name__, config)

    try:
        adress = "https://www.google.com"
        urllib2.urlopen(adress)
        logger.debug("Internet access available")
        return True
    except urllib2.URLError, e:
        logger.warning("Internet connection unavailable")
        logger.warning(e)
        return False


def downloadFile(url, name, config, path=None):
    """
    Download a file according to the url and saved it at the path+name
    """

# Path: pycaf/tools/logs.py
# def create_logger(name, config, is_main=False):
#     """
#     Function wich create a logger with settings in config file
#     """
#     # Get if exist the main logger
#     global main_logger
# 
#     # Get previous logger
#     logger = logging.getLogger(name)
# 
#     # If the logger was not previously initialized (no handlers)
#     if not logger.handlers:
#         path = config.logs_path
# 
#         if not is_main:
#             path += tmp_dir_name
# 
#         if not os.path.exists(path):
#             os.makedirs(path)
# 
#         level_str = config.logs_level.lower()
#         if level_str == "debug":
#             level = logging.DEBUG
#         elif level_str == "info":
#             level = logging.INFO
#         elif level_str == "warning":
#             level = logging.WARNING
#         elif level_str == "error":
#             level = logging.ERROR
#         elif level_str == "critical":
#             level = logging.CRITICAL
# 
#         logger.setLevel(level)
# 
#         # Set the log file name stored into de conf file
#         if not is_main:
#             path += name
#         else:
#             path += config.logs_file_name
# 
#         formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
#         hdlr = logging.FileHandler(path, mode='w')
#         hdlr.setFormatter(formatter)
#         logger.addHandler(hdlr)
# 
#         steam_handler = logging.StreamHandler()
#         steam_handler.setLevel(level)
#         logger.addHandler(steam_handler)
# 
#         if is_main:
#             main_logger = logger
#             logger.debug("Main logger : " + str(path))
#             logger.debug("Temp logs path at : " + str(config.logs_path + tmp_dir_name))
# 
#         elif not is_main and (main_logger is not None):
#             main_logger.debug("New logger : " + str(name) + " - path : " + str(path))
# 
#     return logger


# Path: pycaf/tools/files_processing.py
import urllib2
import os
import hashlib
import gzip
        import traceback
    import pickle
    import pickle
from pycaf.tools.logs import create_logger

# -*- coding: utf-8 -*-
"""
Created on Tue Apr  8 09:49:19 2014

@author: thierry
"""



def checkInternetAccess(config):
    """
    Function which instanciate an internet connection and return True if it is established
    """
    logger = create_logger(__name__, config)

    try:
        adress = "https://www.google.com"
        urllib2.urlopen(adress)
        logger.debug("Internet access available")
        return True
    except urllib2.URLError, e:
        logger.warning("Internet connection unavailable")
        logger.warning(e)
        return False


def downloadFile(url, name, config, path=None):
    """
    Download a file according to the url and saved it at the path+name
    """

    logger = create_logger(__name__, config)