The base class from which all management commands ultimately derive.
Use this class if you want access to all of the mechanisms which parse the command-line arguments and work out what code to call in response; if you don’t need to change any of that behavior, consider using one of the subclasses defined in this file.
If you are interested in overriding/customizing various aspects of the command-parsing and -execution behavior, the normal flow works as follows:
Thus, the handle() method is typically the starting point for subclasses.
Several attributes affect behavior at various steps along the way:
A string listing the arguments accepted by the command, suitable for use in help messages; e.g., a command which takes a list of application names might set this to ‘<appname appname ...>’.
Create and return the OptionParser which will be used to parse the arguments to this command.
Try to execute this command, performing validations if needed (as controlled by the attributes. If the command raises a CommandError, intercept it and print it sensibly to stderr.
The actual logic of the command. Subclasses must implement this method.
Print the help message for this command, derived from self.usage().
Set up any environment changes requested (e.g., Python path, then run this command.
Return a brief description of how to use this command, by default from the attribute self.__doc__.
Validates the given command, raising CommandError for any errors.
Exception class indicating a problem while executing a command.
If this exception is raised during the execution of a management command, it will be caught and turned into a nicely-printed error message to the appropriate output stream (i.e., stderr); as a result, raising this exception (with a sensible description of the error) is the preferred way to indicate that something has gone wrong in the execution of a command.
Encapsulates the logic of the commander.
A ManagementUtility has a number of commands, which can be manipulated by editing the self.commands dictionary.
commands: python module path to commands module
Given the command-line arguments, this figures out which subcommand is being run, creates a parser appropriate to that command, and runs it.
Tries to fetch the given subcommand, printing a message with the appropriate command called from the command line if it can’t be found.
Returns the script’s main help text, as a string.
Abstract class representing user interface object for commander.
Commander Application can be provided with a custom implementation of the UserInterface so it can be used in different environments, i.e. console, gui, web application...
Every command will receive a UserInterface object in it’s constructor and can call all methods to provide user feedback.
Initialization method
Ask for user input
This method should ask the user for input, presenting to user a message and returning a string. Also if password is set to True, user should not be able to see what he types
Present an error message to the user
Present an information message to the user
Show just an ordinary message to the user
This is the central part of the user interface. Every command does some amount of work. This work can be represented in steps. Command should report to the user interface on every finished step so the user can have a live stream of information from the command. Every report contains three parts:
Parameters: |
|
---|
Present a warning message to the user
Simple implementation of the user interface intended for usage in console applications.
If no other UserInterface implementation is provided to commander it will use this user interface
The base class from which all management commands ultimately derive.
Use this class if you want access to all of the mechanisms which parse the command-line arguments and work out what code to call in response; if you don’t need to change any of that behavior, consider using one of the subclasses defined in this file.
If you are interested in overriding/customizing various aspects of the command-parsing and -execution behavior, the normal flow works as follows:
Thus, the handle() method is typically the starting point for subclasses.
Several attributes affect behavior at various steps along the way:
A string listing the arguments accepted by the command, suitable for use in help messages; e.g., a command which takes a list of application names might set this to ‘<appname appname ...>’.
Create and return the OptionParser which will be used to parse the arguments to this command.
Try to execute this command, performing validations if needed (as controlled by the attributes. If the command raises a CommandError, intercept it and print it sensibly to stderr.
The actual logic of the command. Subclasses must implement this method.
Print the help message for this command, derived from self.usage().
Set up any environment changes requested (e.g., Python path, then run this command.
Return a brief description of how to use this command, by default from the attribute self.__doc__.
Validates the given command, raising CommandError for any errors.
A management command which takes one or more arbitrary arguments (labels) on the command line, and does something with each of them.
Rather than implementing handle(), subclasses must implement handle_label(), which will be called once for each label.
Perform the command’s actions for label, which will be the string as given on the command line.
A command which takes no arguments on the command line.
Rather than implementing handle(), subclasses must implement handle_noargs(); handle() itself is overridden to ensure no arguments are passed to the command.
Attempting to pass arguments will raise CommandError.
Perform this command’s actions.
Exception class indicating a problem while executing a command.
If this exception is raised during the execution of a management command, it will be caught and turned into a nicely-printed error message to the appropriate output stream (i.e., stderr); as a result, raising this exception (with a sensible description of the error) is the preferred way to indicate that something has gone wrong in the execution of a command.
Simple implementation of the user interface intended for usage in console applications.
If no other UserInterface implementation is provided to commander it will use this user interface
Abstract class representing user interface object for commander.
Commander Application can be provided with a custom implementation of the UserInterface so it can be used in different environments, i.e. console, gui, web application...
Every command will receive a UserInterface object in it’s constructor and can call all methods to provide user feedback.
Initialization method
Ask for user input
This method should ask the user for input, presenting to user a message and returning a string. Also if password is set to True, user should not be able to see what he types
Present an error message to the user
Present an information message to the user
Show just an ordinary message to the user
This is the central part of the user interface. Every command does some amount of work. This work can be represented in steps. Command should report to the user interface on every finished step so the user can have a live stream of information from the command. Every report contains three parts:
Parameters: |
|
---|
Present a warning message to the user
Encapsulates the logic of the commander.
A ManagementUtility has a number of commands, which can be manipulated by editing the self.commands dictionary.
commands: python module path to commands module
Given the command-line arguments, this figures out which subcommand is being run, creates a parser appropriate to that command, and runs it.
Tries to fetch the given subcommand, printing a message with the appropriate command called from the command line if it can’t be found.
Returns the script’s main help text, as a string.
Create a options parser form configuration
Parameters: |
|
---|
Create a options parser form configuration and parse arguments
Parameters: |
|
---|