Ejemplo n.º 1
0
    def map_files(self):
        """
        Generates a map of files present in the project directory.
        """
        exclude = self.exclude_dirs()
        filemap = {}

        for dirpath, dirnames, filenames in os.walk("."):
            for x in exclude:
                if x in dirnames and not x in self.include:
                    dirnames.remove(x)

            if ".nodexy" in filenames:
                dirnames[:] = []
            elif "pip-delete-this-directory.txt" in filenames:
                msg = s(
                    """pip left an old build/ file lying around,
                please remove this before running dexy"""
                )
                raise UserFeedback(msg)
            else:
                for filename in filenames:
                    filepath = posixpath.normpath(posixpath.join(dirpath, filename))
                    filemap[filepath] = {}
                    filemap[filepath]["stat"] = os.stat(os.path.join(dirpath, filename))
                    filemap[filepath]["ospath"] = os.path.normpath(os.path.join(dirpath, filename))
                    filemap[filepath]["dir"] = os.path.normpath(dirpath)

        return filemap
Ejemplo n.º 2
0
Archivo: wrapper.py Proyecto: dexy/dexy
    def map_files(self):
        """
        Generates a map of files present in the project directory.
        """
        exclude = self.exclude_dirs()
        filemap = {}

        for dirpath, dirnames, filenames in os.walk('.', followlinks=True):
            for x in exclude:
                if x in dirnames and not x in self.include:
                    dirnames.remove(x)

            if '.nodexy' in filenames:
                dirnames[:] = []
            elif 'pip-delete-this-directory.txt' in filenames:
                msg = s("""pip left an old build/ file lying around,
                please remove this before running dexy""")
                raise UserFeedback(msg)
            else:
                for filename in filenames:
                    filepath = posixpath.normpath(
                        posixpath.join(dirpath, filename))
                    filemap[filepath] = {}
                    filemap[filepath]['stat'] = os.stat(
                        os.path.join(dirpath, filename))
                    filemap[filepath]['ospath'] = os.path.normpath(
                        os.path.join(dirpath, filename))
                    filemap[filepath]['dir'] = os.path.normpath(dirpath)

        return filemap
Ejemplo n.º 3
0
    def validate(self):
        """
        Runs dexy and validates filter list.
        """
        for wrapper in self.dexy(False):
            filters_used = wrapper.batch.filters_used

            for f in self.__class__.filters_used:
                msg = "filter %s not used by %s" % (f, self.__class__.__name__)
                assert f in filters_used, msg

            for f in filters_used:
                if not f.startswith(
                        '-') and not f in self.__class__.filters_used:
                    msg = s("""filter %(filter)s used by %(template)s
                            but not listed in klass.filters_used,
                            adjust list to: filters_used = [%(list)s]""")
                    msgargs = {
                        'filter': f,
                        'template': self.__class__.__name__,
                        'list': ", ".join("'%s'" % f for f in filters_used)
                    }
                    print msg % msgargs

            return wrapper.state == 'ran'
Ejemplo n.º 4
0
    def iter_dexy_dirs(self):
        """
        Iterate over the required dirs (e.g. artifacts, logs)
        """
        for d in self.__class__._required_dirs:
            dirpath = self.__dict__[d]
            safety_filepath = os.path.join(dirpath, self.safety_filename)
            try:
                stat = os.stat(dirpath)
            except OSError:
                stat = None

            if stat:
                if not file_exists(safety_filepath):
                    msg = (
                        s(
                            """You need to manually delete the '%s' directory
                    and then run 'dexy setup' to create new directories. This
                    should just be a once-off issue due to a change in dexy to
                    prevent accidentally deleting directories which dexy does
                    not create.
                    """
                        )
                        % dirpath
                    )
                    raise UserFeedback(msg)

            yield (dirpath, safety_filepath, stat)
Ejemplo n.º 5
0
def test_s():
    text = """This is some text
    which goes onto
    many lines and has
    indents at the start."""
    assert s(
        text
    ) == 'This is some text which goes onto many lines and has indents at the start.'
Ejemplo n.º 6
0
 def __init__(self, filter_alias_or_instance):
     from dexy.utils import s
     if isinstance(filter_alias_or_instance, basestring):
         msg = """You are trying to use a filter '%s' which isn't active.
         Some additional software may need to be installed first."""
         self.message = s(msg % filter_alias_or_instance)
     else:
         self.message = "You are trying to use a filter '%s' which isn't active." % filter_alias_or_instance.alias
         executable = filter_alias_or_instance.setting('executable')
         if executable:
             self.message += " The software '%s' is required." % executable
         else:
             self.message += " Some additional software may need to be installed first."
Ejemplo n.º 7
0
 def __init__(self, filter_alias_or_instance):
     from dexy.utils import s
     if isinstance(filter_alias_or_instance, basestring):
         msg = """You are trying to use a filter '%s' which isn't active.
         Some additional software may need to be installed first."""
         self.message = s(msg % filter_alias_or_instance)
     else:
         self.message = "You are trying to use a filter '%s' which isn't active." % filter_alias_or_instance.alias
         executable = filter_alias_or_instance.setting('executable')
         if executable:
             self.message += " The software '%s' is required." % executable
         else:
             self.message += " Some additional software may need to be installed first."
Ejemplo n.º 8
0
Archivo: wrapper.py Proyecto: dexy/dexy
    def iter_dexy_dirs(self):
        """
        Iterate over the required dirs (e.g. artifacts, logs)
        """
        for d in self.__class__._required_dirs:
            dirpath = self.__dict__[d]
            safety_filepath = os.path.join(dirpath, self.safety_filename)
            try:
                stat = os.stat(dirpath)
            except OSError:
                stat = None

            if stat:
                if not file_exists(safety_filepath):
                    msg = s("""You need to manually delete the '%s' directory
                    and then run 'dexy setup' to create new directories. This
                    should just be a once-off issue due to a change in dexy to
                    prevent accidentally deleting directories which dexy does
                    not create.
                    """) % dirpath
                    raise UserFeedback(msg)

            yield (dirpath, safety_filepath, stat)
Ejemplo n.º 9
0
    def validate(self):
        """
        Runs dexy and validates filter list.
        """
        for wrapper in self.dexy(False):
            filters_used = wrapper.batch.filters_used

            for f in self.__class__.filters_used:
                msg = "filter %s not used by %s" % (f, self.__class__.__name__)
                assert f in filters_used, msg
    
            for f in filters_used:
                if not f.startswith('-') and not f in self.__class__.filters_used:
                    msg = s("""filter %(filter)s used by %(template)s
                            but not listed in klass.filters_used,
                            adjust list to: filters_used = [%(list)s]""")
                    msgargs = {
                            'filter' : f,
                            'template' : self.__class__.__name__,
                            'list'  : ", ".join("'%s'" % f for f in filters_used)
                            }
                    print msg % msgargs

            return wrapper.state == 'ran'
Ejemplo n.º 10
0
def filters_text(
    alias="",  # If a filter alias is specified, more detailed help for that filter is printed.
    example=False,  # Whether to run examples
    nocolor=False,  # When source = True, whether to omit syntax highlighting
    showall=False,  # Whether to show all filters, including those which need missing software, implies versions=True
    showmissing=False,  # Whether to just show filters missing external software, implies versions=True
    space=False,  # Whether to add extra spacing to the output for extra readability
    source=False,  # Whether to include syntax-highlighted source code when displaying an indvidual filter
    versions=False  # Whether to check the installed version of external software required by filters, slower
):

    SETTING_STRING = "  %s: %s (default value: %s)"
    if len(alias) > 0:
        # We want help on a particular filter
        instance = dexy.filter.Filter.create_instance(alias)
        text = []
        text.append("aliases: %s" % ", ".join(instance.aliases))
        text.append("")
        text.append(inspect.getdoc(instance.__class__))
        text.append("")
        text.append("dexy-level settings:")
        for k in sorted(instance._instance_settings):
            if not k in dexy.filter.Filter.nodoc_settings and k in dexy.filter.Filter._settings:
                tup = instance._instance_settings[k]
                text.append(SETTING_STRING % (k, tup[0], tup[1]))

        text.append("")
        text.append("filter-specific settings:")
        for k in sorted(instance.filter_specific_settings()):
            tup = instance._instance_settings[k]
            text.append(SETTING_STRING % (k, tup[0], tup[1]))

        examples = instance.setting('examples')
        if len(examples) > 0:
            text.append("")
            text.append("Examples for this filter:")
            for alias in examples:
                template = dexy.template.Template.create_instance(alias)
                text.append("")
                text.append("  %s" % alias)
                text.append("            %s" %
                            dexy.utils.getdoc(template.__class__))

            if example:
                for alias in examples:
                    template = dexy.template.Template.create_instance(alias)
                    text.append('')
                    text.append("Running example: %s" % s(template.__doc__))
                    text.append('')
                    text.append('')
                    text.append(template_text(alias=alias))
                    text.append('')

        text.append("")
        text.append("For online docs see http://dexy.it/docs/filters/%s" %
                    alias)
        if source:
            text.append("")
            source_code = inspect.getsource(instance.__class__)
            if nocolor:
                text.append(source_code)
            else:
                formatter = TerminalFormatter()
                lexer = PythonLexer()
                text.append(highlight(source_code, lexer, formatter))
        return "\n".join(text)

    else:
        text = []

        text.append("Available filters:")
        for filter_instance in dexy.filter.Filter:
            if showall:
                skip = False
            else:
                no_aliases = not filter_instance.setting('aliases')
                no_doc = filter_instance.setting('nodoc')
                not_dexy = not filter_instance.__class__.__module__.startswith(
                    "dexy.")
                exclude = filter_instance.alias in ('-')
                skip = no_aliases or no_doc or not_dexy or exclude

            if (versions or showmissing or showall) and not skip:
                if hasattr(filter_instance, 'version'):
                    version = filter_instance.version()
                else:
                    version = None
                no_version_info_available = (version is None)
                if no_version_info_available:
                    version_message = ""
                    if showmissing:
                        skip = True
                elif version:
                    version_message = "Installed version: %s" % version
                    if showmissing:
                        skip = True
                else:
                    if not (showmissing or showall):
                        skip = True
                    version_message = "'%s' failed, filter may not be available." % filter_instance.version_command(
                    )

            if not skip:
                filter_help = "  " + filter_instance.alias + " : " + filter_instance.setting(
                    'help').splitlines()[0]
                if (versions or showmissing or (showall and not version)):
                    filter_help += " %s" % version_message
                text.append(filter_help)

        text.append(
            "\nFor more information about a particular filter, use the -alias flag and specify the filter alias."
        )
        if space:
            sep = "\n\n"
        else:
            sep = "\n"
        return sep.join(text)
Ejemplo n.º 11
0
def test_s():
    text = """This is some text
    which goes onto
    many lines and has
    indents at the start."""
    assert s(text) == 'This is some text which goes onto many lines and has indents at the start.'
Ejemplo n.º 12
0
def filters_text(
        alias="", # If a filter alias is specified, more detailed help for that filter is printed.
        example=False, # Whether to run examples
        nocolor=False, # When source = True, whether to omit syntax highlighting
        showall=False, # Whether to show all filters, including those which need missing software, implies versions=True
        showmissing=False, # Whether to just show filters missing external software, implies versions=True
        space=False, # Whether to add extra spacing to the output for extra readability
        source=False, # Whether to include syntax-highlighted source code when displaying an indvidual filter
        versions=False # Whether to check the installed version of external software required by filters, slower
        ):

    SETTING_STRING = "  %s: %s (default value: %s)"
    if len(alias) > 0:
        # We want help on a particular filter
        instance = dexy.filter.Filter.create_instance(alias)
        text = []
        text.append("aliases: %s" % ", ".join(instance.aliases))
        text.append("")
        text.append(inspect.getdoc(instance.__class__))
        text.append("")
        text.append("dexy-level settings:")
        for k in sorted(instance._instance_settings):
            if not k in dexy.filter.Filter.nodoc_settings and k in dexy.filter.Filter._settings:
                tup = instance._instance_settings[k]
                text.append(SETTING_STRING % (k, tup[0], tup[1]))

        text.append("")
        text.append("filter-specific settings:")
        for k in sorted(instance.filter_specific_settings()):
            tup = instance._instance_settings[k]
            text.append(SETTING_STRING % (k, tup[0], tup[1]))

        examples = instance.setting('examples')
        if len(examples) > 0:
            text.append("")
            text.append("Examples for this filter:")
            for alias in examples:
                template = dexy.template.Template.create_instance(alias)
                text.append("")
                text.append("  %s" % alias)
                text.append("            %s" % dexy.utils.getdoc(template.__class__))

            if example:
                for alias in examples:
                    template = dexy.template.Template.create_instance(alias)
                    text.append('')
                    text.append("Running example: %s" % s(template.__doc__))
                    text.append('')
                    text.append('')
                    text.append(template_text(alias=alias))
                    text.append('')

        text.append("")
        text.append("For online docs see http://dexy.it/docs/filters/%s" % alias)
        if source:
            text.append("")
            source_code = inspect.getsource(instance.__class__)
            if nocolor:
                text.append(source_code)
            else:
                formatter = TerminalFormatter()
                lexer = PythonLexer()
                text.append(highlight(source_code, lexer, formatter))
        return "\n".join(text)

    else:
        text = []

        text.append("Available filters:")
        for filter_instance in dexy.filter.Filter:
            if showall:
                skip = False
            else:
                no_aliases = not filter_instance.setting('aliases')
                no_doc = filter_instance.setting('nodoc')
                not_dexy = not filter_instance.__class__.__module__.startswith("dexy.")
                exclude = filter_instance.alias in ('-')
                skip = no_aliases or no_doc or not_dexy or exclude

            if (versions or showmissing or showall) and not skip:
                if hasattr(filter_instance, 'version'):
                    version = filter_instance.version()
                else:
                    version = None
                no_version_info_available = (version is None)
                if no_version_info_available:
                    version_message = ""
                    if showmissing:
                        skip = True
                elif version:
                    version_message = "Installed version: %s" % version
                    if showmissing:
                        skip = True
                else:
                    if not (showmissing or showall):
                        skip = True
                    version_message = "'%s' failed, filter may not be available." % filter_instance.version_command()

            if not skip:
                filter_help = "  " + filter_instance.alias + " : " + filter_instance.setting('help').splitlines()[0]
                if (versions or showmissing or (showall and not version)):
                    filter_help += " %s" % version_message
                text.append(filter_help)

        text.append("\nFor more information about a particular filter, use the -alias flag and specify the filter alias.")
        if space:
            sep = "\n\n"
        else:
            sep = "\n"
        return sep.join(text)