Skip to content

Commit 9016fe4

Browse files
committed
Fixed loading errors for new plugin system. Still need to work on unloading.
Added missing comments and doc strings to plugin module. Fixed translation files still using instead of .
1 parent 7ff8e9f commit 9016fe4

File tree

5 files changed

+158
-139
lines changed

5 files changed

+158
-139
lines changed

addons/source-python/packages/source-python/auth/commands.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def call_command(self, args):
4545
'Missing Command'].get_string() + '\n'
4646

4747
# Print the auth help text
48-
self._print_auth_help(message)
48+
self.print_auth_help(message)
4949

5050
# No need to go further
5151
return
@@ -61,7 +61,7 @@ def call_command(self, args):
6161
'Invalid Sub-Command'].get_string(command=command) + '\n'
6262

6363
# Print the auth help text
64-
self._print_auth_help(message)
64+
self.print_auth_help(message)
6565

6666
# No need to go further
6767
return
@@ -78,22 +78,22 @@ def call_command(self, args):
7878
# Execute the command
7979
self[command]()
8080

81-
def _print_auth_help(self, message=''):
81+
def print_auth_help(self, message=''):
8282
'''Prints all "sp auth" sub-commands.'''
8383

8484
# Get header messages
8585
header = message + '[SP Auth] ' + _auth_strings[
8686
'Help'].get_string() + 'sp auth <command> [arguments]\n' + '=' * 78
8787

8888
# Print all "sp auth" sub-commands
89-
self._print_help(header, '=' * 78)
89+
self.print_help(header, '=' * 78)
9090

91-
def _print_help(self, pretext='', posttext=''):
91+
def print_help(self, pretext='', posttext=''):
9292
'''Prints all "sp auth" sub-commands'''
9393
AuthCommandsLogger.log_message(
94-
pretext + '\n' + self._get_help_text() + '\n' + posttext)
94+
pretext + '\n' + self.get_help_text() + '\n' + posttext)
9595

96-
def _get_help_text(self):
96+
def get_help_text(self):
9797
'''Returns the help text for auth commands'''
9898

9999
# Store the base message
@@ -206,4 +206,4 @@ def _print_auth_providers():
206206

207207
# Add all printing commands to the dictionary
208208
_AuthCommandsInstance['list'] = _print_auth_providers
209-
_AuthCommandsInstance['help'] = _AuthCommandsInstance._print_auth_help
209+
_AuthCommandsInstance['help'] = _AuthCommandsInstance.print_auth_help

addons/source-python/packages/source-python/plugins/command.py

Lines changed: 77 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@
3333
# =============================================================================
3434
@public
3535
class SubCommandManager(OrderedDict, AutoUnload):
36-
''''''
36+
'''Class used for executing sub-commands for the given console command'''
3737

3838
def __init__(self, command, description='', prefix=''):
39-
''''''
39+
'''Called on instance initialization'''
4040

41-
#
41+
# Re-call OrderedDict's __init__ to properly setup the object
4242
super(SubCommandManager, self).__init__()
4343

4444
# Does the class have a proper manager object assigned?
@@ -79,225 +79,233 @@ def __init__(self, command, description='', prefix=''):
7979
self.command, self.call_command, description, 0)
8080

8181
def _unload_instance(self):
82-
''''''
82+
'''Unregisters commands when the instance is unloaded'''
8383
ServerCommandManager.unregister_commands(
8484
self.command, self.call_command)
8585

8686
def call_command(self, CICommand):
87-
''''''
87+
'''Gets the provided sub-command and executes accordingly'''
8888

89-
#
89+
# Get the argument string
9090
arg_string = CICommand.get_arg_string()
91-
#
91+
92+
# Use try/except to split the argument string,
93+
# if it contains more than one argument
9294
try:
9395

94-
#
96+
# Split the argument string to get the sub-command
9597
command, args = arg_string.split(maxsplit=1)
9698

99+
# Were there not enough arguments to split?
97100
except ValueError:
98101

99-
#
102+
# Set the command to the entire string
100103
command = arg_string.strip()
101104

102-
#
105+
# Set args to nothing
103106
args = ''
104107

105-
#
108+
# Split the remaining args
106109
args = args.split()
107110

108-
#
111+
# Make the sub-command lower-case
109112
command = command.lower()
110113

111-
#
114+
# Is the sub-command in the dictionary?
112115
if not command in self:
113116

114-
#
117+
# Was a sub-command given?
115118
if command:
116119

117-
#
120+
# Print a message about the invalid sub-command
118121
message = self.prefix + _plugin_strings[
119122
'Invalid Command'].get_string(
120123
command=self.command, subcommand=command)
121124

122-
#
125+
# Was no sub-command given?
123126
else:
124127

125-
#
128+
# Print a message about the missing sub-command
126129
message = self.prefix + _plugin_strings[
127130
'No Command'].get_string(command=self.command)
128131

132+
# Print the help text for the console command
129133
self.print_help(message)
130134

131-
#
135+
# No need to go further
132136
return
133137

134-
#
138+
# Does the given sub-command's callable allow for arguments?
135139
if hasattr(self[command], 'args'):
136140

137-
#
141+
# Get the number of required arguments for the callable
138142
required = len([
139143
x for x in self[command].args if x.startswith('<')])
140144

141-
#
145+
# Get the number of arguments provided
142146
given = len(args)
143147

144-
#
148+
# Were enough arguments provided?
145149
if given < required:
146150

147-
#
151+
# Print a message about the invalid number of arguments given
148152
self.logger.log_message(
149153
self.prefix + _plugin_strings['Invalid Arguments'
150154
].get_string(command=self.command, subcommand=command) +
151155
' '.join(self[command].args))
152156

153-
#
157+
# No need to go further
154158
return
155159

156-
#
160+
# Are all of the arguments required?
157161
if required == len(self[command].args):
158162

159-
#
163+
# Were the correct number of arguments given?
160164
if given != required:
161165

162-
#
166+
# Print a message about the invalid
167+
# number of arguments given
163168
self.logger.log_message(
164169
self.prefix + _plugin_strings['Invalid Arguments'
165170
].get_string(command=self.command, subcommand=command
166171
) + ' '.join(self[command].args))
167172

168-
#
173+
# No need to go further
169174
return
170175

171-
#
176+
# Call the sub-command's callable with the given arguments
172177
self[command](*args)
173178

174-
#
179+
# No need to go further
175180
return
176181

177-
#
182+
# Does the current item have its own call_command method?
178183
if hasattr(self[command], 'call_command'):
179184

180-
#
185+
# Call the instance's call_command method with the arguments
181186
self[command].call_command(args)
182187

183-
#
188+
# No need to go further
184189
return
185190

186-
#
191+
# Call the callable without the arguments
187192
self[command]()
188193

189194
def print_help(self, message=''):
190-
''''''
195+
'''Prints all sub-commands for the console command'''
191196

192-
#
197+
# Add a header message
193198
message += '\n' + self.prefix + _plugin_strings[
194199
'Help'].get_string(command=self.command) + '\n' + '=' * 78
195200

196-
#
201+
# Loop through all registered sub-commands
197202
for item in self:
198203

199-
#
204+
# Set the text
200205
text = str(item)
201206

202-
#
207+
# Does the current sub-command have its own print_help method?
203208
if hasattr(self[item], 'print_help'):
204209

205-
#
206-
message += '\n' + self[item]._get_help_text()
210+
# Get the instance's help text
211+
message += '\n' + self[item].get_help_text()
207212

208-
#
213+
# Continue to the next item
209214
continue
210215

211-
#
216+
# Does the current command have any arguments?
212217
if hasattr(self[item], 'args'):
213218

214-
#
219+
# Add the arguments to the text
215220
text += ' ' + ' '.join(self[item].args)
216221

217-
#
222+
# Add a message for the current command
218223
message += '\n' + text + self[
219224
item].__doc__.rjust(78 - len(text))
220225

221-
#
226+
# Send the message
222227
self.logger.log_message(message + '\n' + '=' * 78)
223228

224229
def load_plugin(self, plugin_name):
225-
''''''
230+
'''Loads a plugin by name'''
226231

227-
#
232+
# Is the plugin already loaded?
228233
if plugin_name in self.manager:
229234

230-
#
235+
# Send a message that the plugin is already loaded
231236
self.logger.log_message(self.prefix + _plugin_strings[
232237
'Already Loaded'].get_string(plugin=plugin_name))
233238

234-
#
239+
# No need to go further
235240
return
236241

237-
#
242+
# Load the plugin and get its instance
238243
plugin = self.manager[plugin_name]
239244

240-
#
245+
# Was the plugin unable to be loaded?
241246
if plugin is None:
242247

243-
#
248+
# Send a message that the plugin was not loaded
244249
self.logger.log_message(self.prefix + _plugin_strings[
245250
'Unable to Load'].get_string(plugin=plugin_name))
246251

247-
#
252+
# No need to go further
248253
return
249254

250-
#
255+
# Send a message that the plugin was loaded
251256
self.logger.log_message(self.prefix + _plugin_strings[
252257
'Successful Load'].get_string(plugin=plugin_name))
253258

259+
# Set the method's required arguments
254260
load_plugin.args = ['<plugin>']
255261

256262
def unload_plugin(self, plugin_name):
257-
''''''
263+
'''Unloads a plugin by name'''
258264

259-
#
265+
# Is the plugin loaded?
260266
if not plugin_name in self.manager:
261267

262-
#
268+
# Send a message that the plugin is not loaded
263269
self.logger.log_message(self.prefix + _plugin_strings[
264270
'Not Loaded'].get_string(plugin=plugin_name))
265271

266-
#
272+
# No need to go further
267273
return
268274

269-
#
275+
# Unload the plugin
270276
del self.manager[plugin_name]
271277

272-
#
278+
# Send a message that the plugin was unloaded
273279
self.logger.log_message(self.prefix + _plugin_strings[
274280
'Successful Unload'].get_string(plugin=plugin_name))
275281

282+
# Set the method's required arguments
276283
unload_plugin.args = ['<plugin>']
277284

278285
def reload_plugin(self, plugin_name):
279-
''''''
286+
'''Reloads a plugin by name'''
280287

281-
#
288+
# Unload the plugin
282289
self.unload_plugin(plugin_name)
283290

284-
#
291+
# Load the plugin
285292
self.load_plugin(plugin_name)
286293

294+
# Set the method's required arguments
287295
reload_plugin.args = ['<plugin>']
288296

289297
def print_plugins(self):
290-
''''''
298+
'''Prints all currently loaded plugins'''
291299

292-
#
300+
# Get the header message
293301
message = self.prefix + _plugin_strings[
294302
'Plugins'].get_string() + '\n' + '=' * 61 + '\n\n\t'
295303

296-
#
304+
# Add all loaded plugins to the message
297305
message += '\n\t'.join(self.manager)
298306

299-
#
307+
# Add a breaker at the end of the message
300308
message += '\n' + '=' * 61
301309

302-
#
310+
# Send the message
303311
self.logger.log_message(message)

0 commit comments

Comments
 (0)