Add plugin_asset_util.PluginDirectory that returns plugin's logdir.
Change: 155354289
This commit is contained in:
parent
3c02d11007
commit
d592502460
@ -30,6 +30,11 @@ def _IsDirectory(parent, item):
|
|||||||
return gfile.IsDirectory(os.path.join(parent, item))
|
return gfile.IsDirectory(os.path.join(parent, item))
|
||||||
|
|
||||||
|
|
||||||
|
def PluginDirectory(logdir, plugin_name):
|
||||||
|
"""Returns the plugin directory for plugin_name."""
|
||||||
|
return os.path.join(logdir, _PLUGINS_DIR, plugin_name)
|
||||||
|
|
||||||
|
|
||||||
def ListPlugins(logdir):
|
def ListPlugins(logdir):
|
||||||
"""List all the plugins that have registered assets in logdir.
|
"""List all the plugins that have registered assets in logdir.
|
||||||
|
|
||||||
@ -61,7 +66,7 @@ def ListAssets(logdir, plugin_name):
|
|||||||
not exist (either because the logdir doesn't exist, or because the plugin
|
not exist (either because the logdir doesn't exist, or because the plugin
|
||||||
didn't register) an empty list is returned.
|
didn't register) an empty list is returned.
|
||||||
"""
|
"""
|
||||||
plugin_dir = os.path.join(logdir, _PLUGINS_DIR, plugin_name)
|
plugin_dir = PluginDirectory(logdir, plugin_name)
|
||||||
if not gfile.IsDirectory(plugin_dir):
|
if not gfile.IsDirectory(plugin_dir):
|
||||||
return []
|
return []
|
||||||
entries = gfile.ListDirectory(plugin_dir)
|
entries = gfile.ListDirectory(plugin_dir)
|
||||||
@ -83,7 +88,7 @@ def RetrieveAsset(logdir, plugin_name, asset_name):
|
|||||||
KeyError: if the asset does not exist.
|
KeyError: if the asset does not exist.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
asset_path = os.path.join(logdir, _PLUGINS_DIR, plugin_name, asset_name)
|
asset_path = os.path.join(PluginDirectory(logdir, plugin_name), asset_name)
|
||||||
try:
|
try:
|
||||||
with gfile.Open(asset_path, "r") as f:
|
with gfile.Open(asset_path, "r") as f:
|
||||||
return f.read()
|
return f.read()
|
||||||
|
@ -50,6 +50,11 @@ class PluginGamma(GenericContentPlugin):
|
|||||||
|
|
||||||
class PluginAssetUtilitiesTest(test.TestCase):
|
class PluginAssetUtilitiesTest(test.TestCase):
|
||||||
|
|
||||||
|
def testGetPluginDirectory(self):
|
||||||
|
self.assertEqual(
|
||||||
|
os.path.join("logdir", "plugins", "x"),
|
||||||
|
plugin_asset_util.PluginDirectory("logdir", "x"))
|
||||||
|
|
||||||
def testNonExistentDirectory(self):
|
def testNonExistentDirectory(self):
|
||||||
tempdir = self.get_temp_dir()
|
tempdir = self.get_temp_dir()
|
||||||
fake_dir = os.path.join(tempdir, "nonexistent_dir")
|
fake_dir = os.path.join(tempdir, "nonexistent_dir")
|
||||||
|
Loading…
Reference in New Issue
Block a user