예제 #1
0
파일: node.py 프로젝트: GWhized/dexy
    def __init__(self, pattern, wrapper, inputs=None, **kwargs):
        self.key = os_to_posix(pattern)
        self.wrapper = wrapper
        self.args = kwargs
        if inputs:
            self.inputs = list(inputs)
        else:
            self.inputs = []

        self.initialize_settings(**kwargs)

        self.start_time = 0
        self.finish_time = 0
        self.elapsed_time = 0

        self.runtime_args = {}
        self.children = []
        self.additional_docs = []

        self.hashid = md5_hash(self.key)

        self.state = 'new'

        # Class-specific setup.
        self.setup()
예제 #2
0
    def __init__(self, pattern, wrapper, inputs=None, **kwargs):
        self.key = os_to_posix(pattern)
        self.wrapper = wrapper
        self.args = kwargs
        if inputs:
            self.inputs = list(inputs)
        else:
            self.inputs = []

        self.initialize_settings(**kwargs)

        self.start_time = 0
        self.finish_time = 0
        self.elapsed_time = 0

        self.runtime_args = {}
        self.children = []
        self.additional_docs = []

        self.hashid = md5_hash(self.key)

        self.state = 'new'

        # Class-specific setup.
        self.setup()
예제 #3
0
파일: filter.py 프로젝트: luisibanez/dexy
    def add_doc(self, doc_name, doc_contents=None, doc_args = None):
        """
        Creates a new Doc object for an on-the-fly document.
        """
        doc_name = os_to_posix(doc_name)
        if not posixpath.sep in doc_name:
            doc_name = posixpath.join(self.input_data.parent_dir(), doc_name)

        additional_doc_filters = self.setting('additional-doc-filters')
        self.log_debug("additional-doc-filters are %s" % additional_doc_filters)

        doc_ext = os.path.splitext(doc_name)[1]

        def create_doc(name, filters, contents, args=None):
            if filters:
                doc_key = "%s|%s" % (name, filters)
            else:
                doc_key = name

            if not args:
                args = {}

            doc = dexy.doc.Doc(
                    doc_key,
                    self.doc.wrapper,
                    [],
                    contents=contents,
                    **args
                    )
            self.doc.add_additional_doc(doc)
            return doc

        if isinstance(additional_doc_filters, dict):
            filters = additional_doc_filters.get(doc_ext, '')
        elif isinstance(additional_doc_filters, basestring):
            filters = additional_doc_filters
        elif isinstance(additional_doc_filters, list):
            for filters in additional_doc_filters:
                doc = create_doc(doc_name, filters, doc_contents)
            # make filters empty so we don't make more docs later
            filters = []
        else:
            msg = "received unexpected additional_doc_filters arg class %s"
            msgargs = additional_doc_filters.__class__.__name__
            raise dexy.exceptions.InternalDexyProblem(msg % msgargs)

        if len(filters) == 0 or self.setting('keep-originals'):
            doc = create_doc(doc_name, '', doc_contents, doc_args)

        if len(filters) > 0:
            doc = create_doc(doc_name, filters, doc_contents, doc_args)

        return doc
예제 #4
0
파일: filter.py 프로젝트: dexy/dexy
    def add_doc(self, doc_name, doc_contents=None, doc_args=None):
        """
        Creates a new Doc object for an on-the-fly document.
        """
        self.log_debug("adding doc with contents type %s" %
                       doc_contents.__class__.__name__)
        doc_name = os_to_posix(doc_name)
        if not posixpath.sep in doc_name:
            doc_name = posixpath.join(self.input_data.parent_dir(), doc_name)

        doc_ext = os.path.splitext(doc_name)[1]

        additional_doc_filters = self.setting('additional-doc-filters')
        self.log_debug("additional-doc-filters are %s" %
                       additional_doc_filters)

        additional_doc_settings = self.setting('additional-doc-settings')

        settings = None
        if isinstance(additional_doc_settings, list):
            # figure out which settings to apply based on file extension
            for pattern, settings in additional_doc_settings:
                if doc_ext == pattern or pattern == ".*":
                    break
        elif isinstance(additional_doc_settings, dict):
            settings = additional_doc_settings

        else:
            raise Exception("Unexpected type %s" % type(settings))

        if doc_args:
            settings.update(doc_args)

        self.log_debug("additional-doc-settings are %s" % settings)

        def create_doc(name, filters, contents, args=None):
            if filters:
                doc_key = "%s|%s" % (name, filters)
            else:
                doc_key = name

            if not args:
                args = {}

            doc = dexy.doc.Doc(doc_key,
                               self.doc.wrapper, [],
                               contents=contents,
                               **args)

            doc.output_data().setup()
            doc.output_data().storage.connect()

            self.doc.add_additional_doc(doc)
            return doc

        doc = None

        if isinstance(additional_doc_filters, str):
            doc = create_doc(doc_name, additional_doc_filters, doc_contents,
                             settings)

        elif isinstance(additional_doc_filters, list):
            for f in reversed(additional_doc_filters):
                doc = create_doc(doc_name, f, doc_contents, settings)

        elif isinstance(additional_doc_filters, dict):
            filters = additional_doc_filters.get(doc_ext)
            if isinstance(filters, list):
                for f in filters:
                    doc = create_doc(doc_name, f, doc_contents, settings)
            elif isinstance(filters, str):
                doc = create_doc(doc_name, filters, doc_contents, settings)
            elif filters is None:
                pass
            else:
                msg = "additional_doc_filters values should be list of string. Received %s"
                msgargs = filters.__class__.__name__
                raise Exception(msg % msgargs)

        else:
            msg = "additional-doc-filters should be string, list or dict. Received %s"
            msgargs = additional_doc_filters.__class__.__name__
            raise dexy.exceptions.InternalDexyProblem(msg % msgargs)

        if self.setting('keep-originals') or doc is None:
            doc = create_doc(doc_name, '', doc_contents, settings)

        return doc
예제 #5
0
    def add_doc(self, doc_name, doc_contents=None, doc_args=None):
        """
        Creates a new Doc object for an on-the-fly document.
        """
        doc_name = os_to_posix(doc_name)
        if not posixpath.sep in doc_name:
            doc_name = posixpath.join(self.input_data.parent_dir(), doc_name)

        doc_ext = os.path.splitext(doc_name)[1]

        additional_doc_filters = self.setting("additional-doc-filters")
        self.log_debug("additional-doc-filters are %s" % additional_doc_filters)

        additional_doc_settings = self.setting("additional-doc-settings")

        settings = None
        if isinstance(additional_doc_settings, list):
            # figure out which settings to apply based on file extension
            for pattern, settings in additional_doc_settings:
                if doc_ext == pattern or pattern == ".*":
                    break
        elif isinstance(additional_doc_settings, dict):
            settings = additional_doc_settings

        else:
            raise Exception("Unexpected type %s" % type(settings))

        if doc_args:
            settings.update(doc_args)

        self.log_debug("additional-doc-settings are %s" % settings)

        def create_doc(name, filters, contents, args=None):
            if filters:
                doc_key = "%s|%s" % (name, filters)
            else:
                doc_key = name

            if not args:
                args = {}

            doc = dexy.doc.Doc(doc_key, self.doc.wrapper, [], contents=contents, **args)

            doc.output_data().setup()
            doc.output_data().storage.connect()

            self.doc.add_additional_doc(doc)
            return doc

        doc = None

        if isinstance(additional_doc_filters, basestring):
            doc = create_doc(doc_name, additional_doc_filters, doc_contents, settings)

        elif isinstance(additional_doc_filters, list):
            for f in reversed(additional_doc_filters):
                doc = create_doc(doc_name, f, doc_contents, settings)

        elif isinstance(additional_doc_filters, dict):
            filters = additional_doc_filters.get(doc_ext)
            if isinstance(filters, list):
                for f in filters:
                    doc = create_doc(doc_name, f, doc_contents, settings)
            elif isinstance(filters, basestring):
                doc = create_doc(doc_name, filters, doc_contents, settings)
            elif filters is None:
                pass
            else:
                msg = "additional_doc_filters values should be list of string. Received %s"
                msgargs = filters.__class__.__name__
                raise Exception(msg % msgargs)

        else:
            msg = "additional-doc-filters should be string, list or dict. Received %s"
            msgargs = additional_doc_filters.__class__.__name__
            raise dexy.exceptions.InternalDexyProblem(msg % msgargs)

        if self.setting("keep-originals") or doc is None:
            doc = create_doc(doc_name, "", doc_contents, settings)

        return doc