# Path: pyoptix/utils.py
# def glob_recursive(path, pattern):
#     matches = []
#     for dirpath, dirnames, filenames in os.walk(path):
#         for filename in fnmatch.filter(filenames, pattern):
#             matches.append(os.path.join(dirpath, filename))
#     return matches
# 
# def find_sub_path(sub_path, search_paths):
#     import os.path
# 
#     for search_path in search_paths:
#         path = os.path.join(search_path, sub_path)
#         if os.path.exists(path):
#             return path
# 
#     raise ValueError('Sub-path not found in searched paths: {0}'.format(sub_path))


import logging
import re
import os
import sys
import shlex
import fnmatch
from stat import S_IRUSR, S_IWUSR, S_IRGRP, S_IWGRP, S_IROTH, S_IWOTH, S_IXUSR, S_IXGRP, S_IXOTH
from subprocess import check_call, CalledProcessError
from pyoptix.utils import glob_recursive, find_sub_path
    from configparser import ConfigParser
    from ConfigParser import SafeConfigParser as ConfigParser
            is_compiled = False

        return output_ptx_path, is_compiled

    @classmethod
    def compile_all_directories(cls, source_extension='.cu'):
        for program_dir in cls._program_directories:
            for program_path in glob_recursive(program_dir, '*' + source_extension):
                Compiler.compile(os.path.abspath(program_path))

    @classmethod
    def clean(cls):
        if os.path.exists(cls.output_path):
            for dirpath, dirnames, filenames in os.walk(cls.output_path):
                for filename in fnmatch.filter(filenames, '*.ptx'):
                    os.remove(os.path.join(dirpath, filename))

    @staticmethod
    def is_ptx(file_path):
        return os.path.splitext(file_path)[1].lower() == '.ptx'

    @staticmethod
    def get_ptx_name(file_path):
        return '%s.ptx' % file_path.replace(os.sep, '_')

    @classmethod
    def get_abs_program_path(cls, file_path):
        if os.path.exists(file_path):
            return file_path
        else:

# Path: pyoptix/utils.py
# def glob_recursive(path, pattern):
#     matches = []
#     for dirpath, dirnames, filenames in os.walk(path):
#         for filename in fnmatch.filter(filenames, pattern):
#             matches.append(os.path.join(dirpath, filename))
#     return matches
# 
# def find_sub_path(sub_path, search_paths):
#     import os.path
# 
#     for search_path in search_paths:
#         path = os.path.join(search_path, sub_path)
#         if os.path.exists(path):
#             return path
# 
#     raise ValueError('Sub-path not found in searched paths: {0}'.format(sub_path))


# Path: pyoptix/compiler.py
import logging
import re
import os
import sys
import shlex
import fnmatch
from stat import S_IRUSR, S_IWUSR, S_IRGRP, S_IWGRP, S_IROTH, S_IWOTH, S_IXUSR, S_IXGRP, S_IXOTH
from subprocess import check_call, CalledProcessError
from pyoptix.utils import glob_recursive, find_sub_path
    from configparser import ConfigParser
    from ConfigParser import SafeConfigParser as ConfigParser

            is_compiled = False

        return output_ptx_path, is_compiled

    @classmethod
    def compile_all_directories(cls, source_extension='.cu'):
        for program_dir in cls._program_directories:
            for program_path in glob_recursive(program_dir, '*' + source_extension):
                Compiler.compile(os.path.abspath(program_path))

    @classmethod
    def clean(cls):
        if os.path.exists(cls.output_path):
            for dirpath, dirnames, filenames in os.walk(cls.output_path):
                for filename in fnmatch.filter(filenames, '*.ptx'):
                    os.remove(os.path.join(dirpath, filename))

    @staticmethod
    def is_ptx(file_path):
        return os.path.splitext(file_path)[1].lower() == '.ptx'

    @staticmethod
    def get_ptx_name(file_path):
        return '%s.ptx' % file_path.replace(os.sep, '_')

    @classmethod
    def get_abs_program_path(cls, file_path):
        if os.path.exists(file_path):
            return file_path
        else:

            abs_path = find_sub_path(file_path, cls._program_directories)