Skip to content

Commit

Permalink
allow to use file patters
Browse files Browse the repository at this point in the history
  • Loading branch information
jscotka committed May 4, 2021
1 parent a10e9a3 commit c0f184a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
11 changes: 10 additions & 1 deletion fmf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,16 @@ def grow(self, path):
fullpath, error)))
else:
plugin = get_plugin_for_file(fullpath)
data = plugin().get_data(fullpath)
log.debug("Used plugin {}".format(plugin))
if plugin.file_patters and any(filter(lambda x: re.search(x, fullpath), plugin.file_patters)):
log.info("Matched patters {}".format(plugin.file_patters))
data = plugin().get_data(fullpath)
# ignore results of output if there is None
if data is None:
continue
else:
log.debug("Does not match patters {}".format(plugin.file_patters))
continue
log.data(pretty(data))
# Handle main.fmf as data for self
if filename == MAIN:
Expand Down
7 changes: 7 additions & 0 deletions fmf/plugin_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,20 @@ class Plugin:
"""
# you have to define extension list as class attribute e.g. [".py"]
extensions = list()
file_patters = list()

def get_data(self, filename):
"""
return python dictionary representation of metadata inside file (FMF structure)
"""
raise NotImplementedError("Define own impementation")

def put_data(
self, filename, hierarchy, data, append_dict, modified_dict,
deleted_items):
"""
Write data in dictionary representation back to file
"""
raise NotImplementedError("Define own impementation")


Expand Down
1 change: 1 addition & 0 deletions fmf/plugins/bash.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

class Bash(Plugin):
extensions = [".sh"]
file_patters = ["test.*"]

@staticmethod
def update_data(filename, pattern="^#.*:FMF:"):
Expand Down
1 change: 1 addition & 0 deletions fmf/plugins/pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

class Pytest(Plugin):
extensions = [".py"]
file_patters=["test.*"]

@staticmethod
def update_data(store_dict, func, config):
Expand Down

0 comments on commit c0f184a

Please sign in to comment.