MCPcopy Index your code
hub / github.com/WebODM/WebODM / sync_plugin_db

Function sync_plugin_db

app/plugins/functions.py:45–76  ·  view source on GitHub ↗

Creates db entries for undiscovered plugins to keep track of enabled/disabled plugins

()

Source from the content-addressed store, hash-verified

43 register_plugins()
44
45def sync_plugin_db():
46 """
47 Creates db entries for undiscovered plugins to keep track
48 of enabled/disabled plugins
49 """
50 if settings.MIGRATING: return
51
52 # Erase cache
53 clear_plugins_cache()
54
55 db_plugins = Plugin.objects.all()
56 fs_plugins = get_plugins()
57
58 # Remove plugins that are in the database but not on the file system
59 for db_plugin in db_plugins:
60 fs_found = next((fs_plugin for fs_plugin in fs_plugins if db_plugin.name == fs_plugin.get_name()), None)
61 if not fs_found:
62 Plugin.objects.filter(name=db_plugin.name).delete()
63 logger.info("Cleaned [{}] plugin from database (not found in file system)".format(db_plugin.name))
64
65 # Add plugins found in the file system, but not yet in the database
66 for plugin in get_plugins():
67 # Plugins that have a "disabled" file are disabled
68 disabled_path = plugin.get_path("disabled")
69 disabled = os.path.isfile(disabled_path)
70
71 _, created = Plugin.objects.get_or_create(
72 name=plugin.get_name(),
73 defaults={'enabled': not disabled},
74 )
75 if created:
76 logger.info("Added [{}] plugin to database".format(plugin))
77
78
79def clear_plugins_cache():

Callers 3

urls.pyFile · 0.90
test_plugin_functionsMethod · 0.90
init_pluginsFunction · 0.85

Calls 6

clear_plugins_cacheFunction · 0.85
get_pluginsFunction · 0.85
get_nameMethod · 0.80
get_pathMethod · 0.80
deleteMethod · 0.45
formatMethod · 0.45

Tested by 1

test_plugin_functionsMethod · 0.72