Пример #1
0
    def fix_folder(self, element):
        f = element["name"]
        if element["fix_func"]:
            element["fix_func"](element)
        elif not files.is_dir(f):
            files.mkdir(f)

        if files.is_dir(f):
            files.chmod(f, **element["perm"])
Пример #2
0
    def init_logger(self):
        '''
        This method create a logger with an output to a file
        '''
        
        logger = logging.getLogger(CONF_MAP()['core']['tool_name'])

        if CONF_MAP()['core']['tool_name'] not in self.initialised_logger:
            self.initialised_logger.append(CONF_MAP()['core']['tool_name'])

            logger.setLevel(logging.DEBUG)

            log_name =  '%s.log' % CONF_MAP()['core']['tool_name'].split('.')[0]
            logfile = '%s/%s' % (CONF_MAP()['core']['log_path'], log_name)

            if not files.is_dir(CONF_MAP()['core']['log_path']):
                files.mkdir(CONF_MAP()['core']['log_path'])

            fh = logging.FileHandler(logfile, mode='a+')
            fh.setLevel(logging.DEBUG)
            formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
            fh.setFormatter(formatter)
            logger.addHandler(fh)

            fh = logging.StreamHandler(sys.stdout)
            fh.setLevel(logging.DEBUG)
            formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
            fh.setFormatter(formatter)
            logger.addHandler(fh)

        return logger
Пример #3
0
    def check_folder(self, element):
        is_ok = False

        if element["ck_func"]:
            is_ok = element["ck_func"](element)
        else:
            f = element["name"]
            is_ok = files.is_dir(f) and files.check_perm(f, **element["perm"])

        return is_ok
Пример #4
0
    def get_file_list(self, path):
        allowed_type = ["application/javascript", "application/x-httpd-php", "text/"]
        file_list = []
        local_list = files.ls(path)
        for f in local_list:
            if files.is_dir(f):
                file_list += self.get_file_list("%s/*" % f)
            else:
                mt = str(mimetypes.guess_type(f)[0])
                for allowed in allowed_type:
                    if mt.startswith(allowed):
                        file_list.append(f)
                        break

        return file_list