# Path: gtool/core/types/core.py
# class FunctionType(object):
#     """
#     Use as the base class for method plugins
#     """
# 
#     @abstractmethod
#     def __init__(self, obj, config=str(), defer=False):
#         """
#         Based class for method plugins
# 
#         :param obj: the DynamicType Object that the function will operate one
#         :param config: instructions on how the plugin should work. May be a list, dict or string
#         """
# 
#         self.targetobject = obj
#         self.config = config
#         self.computable = False
#         self.__result__ = None
#         self.__context__ = obj.__context__
#         self.__defer__ = defer
# 
#     # TODO implement an  attribute getter for method plugins
#     def __getname__(self, attrname, nativetypes = [], singletononly=False):
#         raise NotImplemented
# 
#     @abstractmethod
#     def compute(self):
#         """
#         processes any instructions in config, determine if required input exists.
#         If required input exists, sets self.computable to true, computes and stores result
#         :return:  None
#         """
#         # process config or do something
# 
#         if True: #determine if result can be computed
#             self.computable = True
# 
#         if self.computable:
#             self.__result__ = 'some result' #set result
#             raise NotImplemented('compute must be overridden')
#         else:
#             pass
#             # if not computable don't set result
#         #TODO look at returning True or False is compute completes
# 
#     @property
#     def context(self):
#         return self.__context__
# 
#     def result(self, force=False):
# 
#         if not self.__defer__ or force:
#             self.compute() #TODO look at making this an if statement
#             return self.__result__
#         else:
#             raise NotComputed('Computation deferred')
# 
#     def __repr__(self):
#         return '<%s>:()' % (self.__class__, self.config)
# 
#     def __str__(self):
#         self.compute() #TODO look at making this an if statement
#         return self.__result__
# 
# Path: gtool/core/utils/misc.py
# def striptoclassname(fullclassstring):
#     return '{0}'.format(fullclassstring)[7:-2].split('.')[-1]


from gtool.core.types.core import FunctionType
from gtool.core.utils.misc import striptoclassname
from distutils.util import strtobool
import os

FILEONLY = 'fileonly'

class Artefacts(FunctionType):
    """
    Will return a list of artefacts (relative path) inside directories starting with !
    If fileonly == True is passed in then only filenames will be listed
    """

    def __init__(self, obj, config=None):

        _config = {FILEONLY: False}

        if config is not None:
            _configlist = [c.strip().lower() for c in config.split('=')]

            if len(_configlist) == 2 and _configlist[0] == FILEONLY:
                _config[FILEONLY] = strtobool(_configlist[1])
            else:
                raise ValueError('Artefact method plugin (used in user defined class %s) accepts a single argument of either '
                                 '"fileonly = True" or "fileonly = False". By default fileonly mode is False '

# Path: gtool/core/types/core.py
# class FunctionType(object):
#     """
#     Use as the base class for method plugins
#     """
# 
#     @abstractmethod
#     def __init__(self, obj, config=str(), defer=False):
#         """
#         Based class for method plugins
# 
#         :param obj: the DynamicType Object that the function will operate one
#         :param config: instructions on how the plugin should work. May be a list, dict or string
#         """
# 
#         self.targetobject = obj
#         self.config = config
#         self.computable = False
#         self.__result__ = None
#         self.__context__ = obj.__context__
#         self.__defer__ = defer
# 
#     # TODO implement an  attribute getter for method plugins
#     def __getname__(self, attrname, nativetypes = [], singletononly=False):
#         raise NotImplemented
# 
#     @abstractmethod
#     def compute(self):
#         """
#         processes any instructions in config, determine if required input exists.
#         If required input exists, sets self.computable to true, computes and stores result
#         :return:  None
#         """
#         # process config or do something
# 
#         if True: #determine if result can be computed
#             self.computable = True
# 
#         if self.computable:
#             self.__result__ = 'some result' #set result
#             raise NotImplemented('compute must be overridden')
#         else:
#             pass
#             # if not computable don't set result
#         #TODO look at returning True or False is compute completes
# 
#     @property
#     def context(self):
#         return self.__context__
# 
#     def result(self, force=False):
# 
#         if not self.__defer__ or force:
#             self.compute() #TODO look at making this an if statement
#             return self.__result__
#         else:
#             raise NotComputed('Computation deferred')
# 
#     def __repr__(self):
#         return '<%s>:()' % (self.__class__, self.config)
# 
#     def __str__(self):
#         self.compute() #TODO look at making this an if statement
#         return self.__result__
# 
# Path: gtool/core/utils/misc.py
# def striptoclassname(fullclassstring):
#     return '{0}'.format(fullclassstring)[7:-2].split('.')[-1]


# Path: gtool/plugins/artefacts.py
from gtool.core.types.core import FunctionType
from gtool.core.utils.misc import striptoclassname
from distutils.util import strtobool
import os


FILEONLY = 'fileonly'

class Artefacts(FunctionType):
    """
    Will return a list of artefacts (relative path) inside directories starting with !
    If fileonly == True is passed in then only filenames will be listed
    """

    def __init__(self, obj, config=None):

        _config = {FILEONLY: False}

        if config is not None:
            _configlist = [c.strip().lower() for c in config.split('=')]

            if len(_configlist) == 2 and _configlist[0] == FILEONLY:
                _config[FILEONLY] = strtobool(_configlist[1])
            else:
                raise ValueError('Artefact method plugin (used in user defined class %s) accepts a single argument of either '
                                 '"fileonly = True" or "fileonly = False". By default fileonly mode is False '

                                 'and does not need to be specified' % striptoclassname(type(obj)))