diff --git a/prismedia/cli.py b/prismedia/cli.py index c24814a..797b23c 100644 --- a/prismedia/cli.py +++ b/prismedia/cli.py @@ -4,22 +4,17 @@ import video as vid from yapsy.PluginManager import PluginManagerSingleton def helperFunctionnality(options): - optionName = "--list-plugins" - if options.get(optionName): - _listPlugins() - return True - else: - options.pop(optionName) + pluginManager = PluginManagerSingleton.get() optionName = "--hearthbeat" if options.get(optionName): - for plugin in manager.getPluginsOfCategory(pi.PluginTypes.PLATFORM): + for plugin in pluginManager.getPluginsOfCategory(pi.PluginTypes.PLATFORM): plugin.plugin_object.hearthbeat() - return True + return False else: options.pop(optionName) - return False + return True def parseOptions(options): @@ -46,7 +41,8 @@ def parseOptions(options): autoOriginalDate = _getOption(options, "--auto-original-date", False) if autoOriginalDate: - raise Exception("Unimplemented!") + # TODO: Implement + raise NotImplementedError("--auto-original-date functionnality is not yet implemented.") return video @@ -58,21 +54,3 @@ def _getOption(options, optionName, defaultValue = None): if value is None: return defaultValue return value - - -def _listPlugins(): - manager = PluginManagerSingleton.get() - - print("The plugins are stored in the following folders:", manager.getPluginLocator().plugins_places) - - print("Category:", pi.PluginTypes.INTERFACE.value) - for plugin in manager.getPluginsOfCategory(pi.PluginTypes.INTERFACE): - print("\t" + plugin.name) - - print("Category:", pi.PluginTypes.PLATFORM.value) - for plugin in manager.getPluginsOfCategory(pi.PluginTypes.PLATFORM): - print("\t" + plugin.name) - - print("Category:", pi.PluginTypes.CONSUMER.value) - for plugin in manager.getPluginsOfCategory(pi.PluginTypes.CONSUMER): - print("\t" + plugin.name) diff --git a/prismedia/core.py b/prismedia/core.py index 96350bb..fe68d07 100644 --- a/prismedia/core.py +++ b/prismedia/core.py @@ -2,18 +2,18 @@ # coding: utf-8 # NOTE: Since we use config file to set some defaults values, it is not possible to use the standard syntax with brackets, we use parenthesis instead. -# If we were to use them we would overide configuration file values with default values of cli. +# If we were to use them we would override configuration file values with default values of cli. # TODO: change `youtube-at` and `peertube-at` that are not easely expendable as options in my opinion """ prismedia - tool to upload videos to different platforms (historicaly Peertube and Youtube) Usage: - prismedia [options] --file= | - prismedia --list-plugins | --hearthbeat + prismedia [options] --file= | [ [...]] + prismedia --hearthbeat prismedia -h | --help | -V | --version Options: - -f, --file=STRING Path to the video file to upload in mp4. This is the only mandatory option. + -f, --file=STRING Path to the video file to upload in mp4. This is the only mandatory option except if you provide the name of a plugin interface (see ). --thumbnail=STRING Path to a file to use as a thumbnail for the video. --name=NAME Name of the video to upload. (default to video filename) -d, --description=STRING Description of the video. (default: default description) @@ -53,11 +53,11 @@ Options: --hearthbeat Use some credits to show some activity for you apikey so the platform know it is used and would not inactivate your keys. - -h, --help Show this help. + -h, --help Show this help. Note that calling `help` without the `--` calls a plugin showing a different help for the plugins. -V, --version Show the version. Plugins options: - Interface plugin to use. Select the interface you want to use. By default the interface is the command line. + Interface plugin to use to provide the video to upload. Select the interface you want to use. If `--file` is provided instead the interface will be the command line. --platform=STRING Platforms plugins to use. Usually one platform plugin upload to one platform website (comma separated list) (default: all) --consumer=STRING Consumers plugins to use. They are executed after an upload has been done (comma separated list) (default: all) --list-plugins List all the plugins currently installed by category. @@ -118,41 +118,46 @@ import logging VERSION = "prismedia v1.0.0-plugins-alpha" def loadPlugins(basePluginsPath): - manager = PluginManagerSingleton.get() - manager.setPluginPlaces(basePluginsPath) + pluginManager = PluginManagerSingleton.get() + pluginManager.setPluginPlaces(basePluginsPath) # Define the various categories corresponding to the different # kinds of plugins you have defined - manager.setCategoriesFilter({ + pluginManager.setCategoriesFilter({ + pi.PluginTypes.DEFAULT : pi.IPlugin, pi.PluginTypes.INTERFACE : pi.IInterfacePlugin, pi.PluginTypes.PLATFORM : pi.IPlatformPlugin, pi.PluginTypes.CONSUMER : pi.IConsumerPlugin, }) - manager.collectPlugins() + pluginManager.collectPlugins() def main(): basePluginsPath = [os.path.dirname(os.path.abspath(__file__)) + "/plugins"] loadPlugins(basePluginsPath) - manager = PluginManagerSingleton.get() + pluginManager = PluginManagerSingleton.get() # TODO: add the arguments’s verification (copy/adapt the Schema table) options = docopt(__doc__, version=VERSION) # Helper functionnalities help the user but do not upload anything - if cli.helperFunctionnality(options): - print(options) - exit(0) # TODO: Magic error code + if not cli.helperFunctionnality(options): + exit(0) # TODO: Magic exit code video = cli.parseOptions(options) + videos = [video] if options[""]: - pass # TODO: call the interface the user asked for + interface = pluginManager.getPluginByName(options[""], pi.PluginTypes.INTERFACE) + if not interface.plugin_object.prepareOptions(videos, options): + exit(0) # TODO: Magic exit code - if video.path is None: - # TODO: log instead to error ? critical ? - print("No valid path to a video file has been provided.") - exit(1) # TODO: Magic error code + # TODO: Loop through videos and platforms + for v in videos: + if v.path == "": + # TODO: log instead to error ? critical ? + print("No valid path to a video file has been provided.") + continue print(options) @@ -161,10 +166,10 @@ def main(): #def test_loadPlugins(arg): # Loop round the plugins and print their names. print("debug") - print(manager.getAllPlugins()) + print(pluginManager.getAllPlugins()) print("all plugins") - for plugin in manager.getAllPlugins(): + for plugin in pluginManager.getAllPlugins(): print(plugin.name) # plugin.plugin_object.print_name() diff --git a/prismedia/pluginInterfaces.py b/prismedia/pluginInterfaces.py index 9bf134d..b22458c 100644 --- a/prismedia/pluginInterfaces.py +++ b/prismedia/pluginInterfaces.py @@ -3,6 +3,7 @@ from yapsy.IPlugin import IPlugin class PluginTypes(Enum): """Plugin Types possibles to instantiate in this program.""" + DEFAULT = "Default" INTERFACE = "Interface" PLATFORM = "Platform" CONSUMER = "Consumer" @@ -16,10 +17,11 @@ class IInterfacePlugin(IPlugin): Interface for the Interface plugin category. """ - def getOptions(self, args): + def prepareOptions(self, videos, options): """ - Returns the options user has set. - - `args` the command line arguments passed to Prismedia + Return a falsy value to exit the program. + - `videos`: list of videos to be uploaded + - `options`: a dictionary of options to be used by Prismedia and other plugins """ raise NotImplementedError("`getOptions` must be reimplemented by %s" % self) diff --git a/prismedia/plugins/interfaces/help.py b/prismedia/plugins/interfaces/help.py new file mode 100644 index 0000000..dbd9625 --- /dev/null +++ b/prismedia/plugins/interfaces/help.py @@ -0,0 +1,43 @@ +import pluginInterfaces as pi + +from yapsy.PluginManager import PluginManagerSingleton + +class Help(pi.IInterfacePlugin): + """ + The help plugin print the usage informations of prismedia’s plugins. + Use it by simply caling `prismedia help `. + For example `prismedia help help` bring this help. + """ + + def prepareOptions(self, videos, options): + pluginManager = PluginManagerSingleton.get() + + if options[""]: + parameters = options[""] + else: + parameters = ["help"] + + for p in parameters: + plugin = pluginManager.getPluginByName(p, pi.PluginTypes.DEFAULT) + print(plugin.name + "\t" + plugin.description) + print("Usage:", plugin.plugin_object.__doc__) + + if p == "help": + print("The plugins are stored in the following folders:", pluginManager.getPluginLocator().plugins_places) + + print("Category:", pi.PluginTypes.INTERFACE.value) + for plugin in pluginManager.getPluginsOfCategory(pi.PluginTypes.INTERFACE): + print("\t" + plugin.name) + + print("Category:", pi.PluginTypes.PLATFORM.value) + for plugin in pluginManager.getPluginsOfCategory(pi.PluginTypes.PLATFORM): + print("\t" + plugin.name) + + print("Category:", pi.PluginTypes.CONSUMER.value) + for plugin in pluginManager.getPluginsOfCategory(pi.PluginTypes.CONSUMER): + print("\t" + plugin.name) + + # Print a line breack between each plugin help. + print() + + return False diff --git a/prismedia/plugins/interfaces/help.yapsy-plugin b/prismedia/plugins/interfaces/help.yapsy-plugin new file mode 100644 index 0000000..63d47bb --- /dev/null +++ b/prismedia/plugins/interfaces/help.yapsy-plugin @@ -0,0 +1,9 @@ +[Core] +Name = help +Module = help + +[Documentation] +Author = Zykino +Version = 0.1 +Website = https://git.lecygnenoir.info/LecygneNoir/prismedia +Description = Give informations about plugins usage by using the syntax `prismedia help [...]`. diff --git a/prismedia/plugins/platforms/peertube.py b/prismedia/plugins/platforms/peertube.py index 3788098..89d6ce0 100644 --- a/prismedia/plugins/platforms/peertube.py +++ b/prismedia/plugins/platforms/peertube.py @@ -65,7 +65,11 @@ LANGUAGE = { } class Peertube(pi.IPlatformPlugin): - """docstring for Peertube.""" + """ + Plugin to upload to the Peertube platform. + The connetions files should be set as # TODO: EXPLAIN HOW TO SETUP THE SECRET FILES + You can provide the option `publish-at-peertube=DATE` in a configuraiton file to override the default `publish-at=DATE` for this platform. + """ def get_authenticated_service(secret): peertube_url = str(secret.get('peertube', 'peertube_url')).rstrip("/") diff --git a/prismedia/plugins/platforms/peertube.yapsy-plugin b/prismedia/plugins/platforms/peertube.yapsy-plugin index a07437d..bc5698f 100644 --- a/prismedia/plugins/platforms/peertube.yapsy-plugin +++ b/prismedia/plugins/platforms/peertube.yapsy-plugin @@ -1,5 +1,5 @@ [Core] -Name = Peertube +Name = peertube Module = peertube [Documentation]