commotion_client.utils.extension_manager.ExtensionManager Class Reference
Inheritance diagram for commotion_client.utils.extension_manager.ExtensionManager:

Public Member Functions

def __init__
 
def get_user_settings
 
def reset_settings_group
 
def init_extension_libraries
 
def set_library_defaults
 
def init_libraries
 
def init_extension_config
 
def check_installed
 
def get_installed
 
def load_core
 
def install_loaded
 
def get_extension_from_property
 
def get_property
 
def load_user_interface
 
def get_config
 
def remove_extension_settings
 
def save_settings
 

Public Attributes

 log
 
 translate
 
 extensions
 
 libraries
 
 user_settings
 
 config_keys
 

Member Function Documentation

def commotion_client.utils.extension_manager.ExtensionManager.check_installed (   self,
  name = None 
)
Checks if and extension is installed.
    
Args:
  name (type): Name of a extension to check. If not specified will check if there are any extensions installed.
    
Returns:
  bool: True if named extension is installed, false, if not.

References commotion_client.utils.extension_manager.ExtensionManager.get_installed(), commotion_client.GUI.menu_bar.MenuBar.translate, commotion_client.extensions.config_editor.main.ViewPort.translate, commotion_client.GUI.main_window.MainWindow.translate, commotion_client.GUI.toolbar_builder.ToolBar.translate, commotion_client.GUI.extension_toolbar.ExtensionToolBar.translate, commotion_client.GUI.toolbar.ToolBar.translate, commotion_client.utils.extension_manager.ExtensionManager.translate, commotion_client.GUI.extension_toolbar.MenuItem.translate, and commotion_client.commotion_client.CommotionClientApplication.translate.

221  def check_installed(self, name=None):
222  """Checks if and extension is installed.
223 
224  Args:
225  name (type): Name of a extension to check. If not specified will check if there are any extensions installed.
226 
227  Returns:
228  bool: True if named extension is installed, false, if not.
229  """
230  installed_extensions = list(self.get_installed().keys())
231  if name and name in installed_extensions:
232  self.log.debug(self.translate("logs", "Extension {0} found in installed extensions.".format(name)))
233  return True
234  elif not name and installed_extensions:
235  self.log.debug(self.translate("logs", "Installed extensions found."))
236  return True
237  else:
238  self.log.debug(self.translate("logs", "Extension/s NOT found."))
239  return False
def get_installed
Definition: extension_manager.py:240
def check_installed
Definition: extension_manager.py:220
def commotion_client.utils.extension_manager.ExtensionManager.get_config (   self,
  name 
)
Returns a config from an installed extension.

Args:
  name (string): An extension name.

Returns:
  A config (dictionary)for an extension.

Raises:
  KeyError: If an installed extension of the specified name does not exist.

References commotion_client.GUI.menu_bar.MenuBar.translate, commotion_client.extensions.config_editor.main.ViewPort.translate, commotion_client.GUI.main_window.MainWindow.translate, commotion_client.GUI.toolbar_builder.ToolBar.translate, commotion_client.GUI.extension_toolbar.ExtensionToolBar.translate, commotion_client.GUI.toolbar.ToolBar.translate, commotion_client.utils.extension_manager.ExtensionManager.translate, commotion_client.GUI.extension_toolbar.MenuItem.translate, commotion_client.commotion_client.CommotionClientApplication.translate, and commotion_client.utils.extension_manager.ExtensionManager.user_settings.

Referenced by commotion_client.utils.extension_manager.ExtensionManager.load_user_interface().

444  def get_config(self, name):
445  """Returns a config from an installed extension.
446 
447  Args:
448  name (string): An extension name.
449 
450  Returns:
451  A config (dictionary)for an extension.
452 
453  Raises:
454  KeyError: If an installed extension of the specified name does not exist.
455  """
456  config = {}
457  _settings = self.user_settings
458  extensions = _settings.childGroups()
459  if name not in extensions:
460  raise KeyError(self.translate("logs", "No installed extension with the name {0} exists.".format(name)))
461  _settings.beginGroup(name)
462  extension_config = _settings.childKeys()
463  for key in extension_config:
464  config[key] = _settings.value(key)
465  _settings.endGroup()
466  return config
def get_config
Definition: extension_manager.py:443
user_settings
Definition: extension_manager.py:64
def commotion_client.utils.extension_manager.ExtensionManager.get_extension_from_property (   self,
  key,
  val 
)
Takes a property and returns all INSTALLED extensions who have the passed value set under the passed property.

Checks all installed extensions and returns the name of all extensions whose config contains the key:val pair passed to this function.

Args:
  key (string): The name of the property to be checked.
  val (string): The value that the property must have to be selected

Returns:
  A list of extension names that have the key:val property in their config if they exist.
    ['ext01', 'ext02', 'ext03']

Raises:
  KeyError: If the value requested is non-standard.

References commotion_client.utils.extension_manager.ExtensionManager.config_keys, commotion_client.GUI.menu_bar.MenuBar.translate, commotion_client.extensions.config_editor.main.ViewPort.translate, commotion_client.GUI.main_window.MainWindow.translate, commotion_client.GUI.toolbar_builder.ToolBar.translate, commotion_client.GUI.extension_toolbar.ExtensionToolBar.translate, commotion_client.GUI.toolbar.ToolBar.translate, commotion_client.utils.extension_manager.ExtensionManager.translate, commotion_client.GUI.extension_toolbar.MenuItem.translate, commotion_client.commotion_client.CommotionClientApplication.translate, and commotion_client.utils.extension_manager.ExtensionManager.user_settings.

340  def get_extension_from_property(self, key, val):
341  """Takes a property and returns all INSTALLED extensions who have the passed value set under the passed property.
342 
343  Checks all installed extensions and returns the name of all extensions whose config contains the key:val pair passed to this function.
344 
345  Args:
346  key (string): The name of the property to be checked.
347  val (string): The value that the property must have to be selected
348 
349  Returns:
350  A list of extension names that have the key:val property in their config if they exist.
351  ['ext01', 'ext02', 'ext03']
352 
353  Raises:
354  KeyError: If the value requested is non-standard.
355  """
356  matching_extensions = []
357  if key not in self.config_keys:
358  _error = self.translate("logs", "{0} is not a valid extension config value.".format(key))
359  raise KeyError(_error)
360  _settings = self.user_settings
361  all_exts = _settings.childGroups()
362  for current_extension in all_exts:
363  #enter extension settings
364  _settings.beginGroup(current_extension)
365  if _settings.value(key) == val:
366  matching_extensions.append(current_extension)
367  #exit extension
368  _settings.endGroup()
369  if matching_extensions:
370  return matching_extensions
371  else:
372  self.log.info(self.translate("logs", "No extensions had the requested value."))
373  return []
def get_extension_from_property
Definition: extension_manager.py:339
config_keys
Definition: extension_manager.py:65
user_settings
Definition: extension_manager.py:64
def commotion_client.utils.extension_manager.ExtensionManager.get_installed (   self)
Get all installed extensions seperated by type.

Pulls the current installed extensions from the application settings and returns a dictionary with the lists of the two extension types.

Returns:
  A dictionary keyed by the names of all extensions with the values being if they are a user extension or a global extension.

  {'coreExtensionOne':"user", 'coreExtensionTwo':"global",
   'contribExtension':"global", 'anotherContrib':"global"}

References commotion_client.utils.extension_manager.ExtensionManager.libraries, commotion_client.GUI.menu_bar.MenuBar.translate, commotion_client.extensions.config_editor.main.ViewPort.translate, commotion_client.GUI.main_window.MainWindow.translate, commotion_client.GUI.toolbar_builder.ToolBar.translate, commotion_client.GUI.toolbar.ToolBar.translate, commotion_client.GUI.extension_toolbar.ExtensionToolBar.translate, commotion_client.utils.extension_manager.ExtensionManager.translate, commotion_client.GUI.extension_toolbar.MenuItem.translate, commotion_client.commotion_client.CommotionClientApplication.translate, and commotion_client.utils.extension_manager.ExtensionManager.user_settings.

Referenced by commotion_client.utils.extension_manager.ExtensionManager.check_installed().

241  def get_installed(self):
242  """Get all installed extensions seperated by type.
243 
244  Pulls the current installed extensions from the application settings and returns a dictionary with the lists of the two extension types.
245 
246  Returns:
247  A dictionary keyed by the names of all extensions with the values being if they are a user extension or a global extension.
248 
249  {'coreExtensionOne':"user", 'coreExtensionTwo':"global",
250  'contribExtension':"global", 'anotherContrib':"global"}
251 
252  """
253  self.log.debug(self.translate("logs", "Getting installed extensions."))
254  installed_extensions = {}
255  _settings = self.user_settings
256  extensions = _settings.childGroups()
257  for ext in extensions:
258  _type = _settings.value(ext+"/type")
259  ext_dir = QtCore.QDir(self.libraries[_type])
260  if ext_dir.exists(ext):
261  installed_extensions[ext] = _type
262  self.log.debug(self.translate("logs", "The following extensions are installed: [{0}].".format(extensions)))
263  return installed_extensions
def get_installed
Definition: extension_manager.py:240
user_settings
Definition: extension_manager.py:64
def commotion_client.utils.extension_manager.ExtensionManager.get_property (   self,
  name,
  key 
)
Get a property of an installed extension from the user settings.


Args:
  name (string): The extension's name.
  key (string): The key of the value you are requesting from the extension.

Returns:
  A the (string) value associated the extensions key in the applications saved extension settings.

Raises:
  KeyError: If the value requested is non-standard.

References commotion_client.utils.extension_manager.ExtensionManager.config_keys, commotion_client.GUI.menu_bar.MenuBar.translate, commotion_client.extensions.config_editor.main.ViewPort.translate, commotion_client.GUI.main_window.MainWindow.translate, commotion_client.GUI.toolbar_builder.ToolBar.translate, commotion_client.GUI.extension_toolbar.ExtensionToolBar.translate, commotion_client.GUI.toolbar.ToolBar.translate, commotion_client.utils.extension_manager.ExtensionManager.translate, commotion_client.GUI.extension_toolbar.MenuItem.translate, commotion_client.commotion_client.CommotionClientApplication.translate, and commotion_client.utils.extension_manager.ExtensionManager.user_settings.

Referenced by commotion_client.utils.extension_manager.ExtensionManager.load_user_interface().

375  def get_property(self, name, key):
376  """
377  Get a property of an installed extension from the user settings.
378 
379 
380  Args:
381  name (string): The extension's name.
382  key (string): The key of the value you are requesting from the extension.
383 
384  Returns:
385  A the (string) value associated the extensions key in the applications saved extension settings.
386 
387  Raises:
388  KeyError: If the value requested is non-standard.
389  """
390  if key not in self.config_keys:
391  _error = self.translate("logs", "That is not a valid extension config value.")
392  raise KeyError(_error)
393  _settings = self.user_settings
394  _settings.beginGroup(name)
395  setting_value = _settings.value(key)
396  if not setting_value:
397  _error = self.translate("logs", "The extension config does not contain that value.")
398  _settings.endGroup()
399  raise KeyError(_error)
400  else:
401  _settings.endGroup()
402  return setting_value
def get_property
Definition: extension_manager.py:374
config_keys
Definition: extension_manager.py:65
user_settings
Definition: extension_manager.py:64
def commotion_client.utils.extension_manager.ExtensionManager.get_user_settings (   self)
Get the currently logged in user settings object.

References commotion_client.GUI.menu_bar.MenuBar.translate, commotion_client.extensions.config_editor.main.ViewPort.translate, commotion_client.GUI.main_window.MainWindow.translate, commotion_client.GUI.toolbar_builder.ToolBar.translate, commotion_client.GUI.toolbar.ToolBar.translate, commotion_client.GUI.extension_toolbar.ExtensionToolBar.translate, commotion_client.utils.extension_manager.ExtensionManager.translate, commotion_client.GUI.extension_toolbar.MenuItem.translate, and commotion_client.commotion_client.CommotionClientApplication.translate.

76 
77  def get_user_settings(self):
78  """Get the currently logged in user settings object."""
79  settings_manager = settings.UserSettingsManager()
80  _settings = settings_manager.get()
81  if _settings.Scope() == 0:
82  _settings.beginGroup("extensions")
83  return _settings
84  else:
85  raise TypeError(self.translate("logs", "User settings has a global scope and will not be loaded. Because, security."))
def get_user_settings
Definition: extension_manager.py:76
def commotion_client.utils.extension_manager.ExtensionManager.init_extension_config (   self,
  ext_type = None 
)
Initializes config objects for the path of extensions.

Args:
  ext_type (string): A specific extension type to load/reload a config object from. [global, user, or core]. If not provided, defaults to all.

Raises:
  ValueError: If the extension type passed is not either [core, global, or user]

References commotion_client.utils.extension_manager.ExtensionManager.extensions, commotion_client.utils.extension_manager.ExtensionManager.libraries, commotion_client.GUI.menu_bar.MenuBar.translate, commotion_client.extensions.config_editor.main.ViewPort.translate, commotion_client.GUI.main_window.MainWindow.translate, commotion_client.GUI.toolbar_builder.ToolBar.translate, commotion_client.GUI.toolbar.ToolBar.translate, commotion_client.GUI.extension_toolbar.ExtensionToolBar.translate, commotion_client.utils.extension_manager.ExtensionManager.translate, commotion_client.GUI.extension_toolbar.MenuItem.translate, and commotion_client.commotion_client.CommotionClientApplication.translate.

Referenced by commotion_client.utils.extension_manager.ExtensionManager.init_extension_libraries(), and commotion_client.utils.extension_manager.ExtensionManager.load_core().

193  def init_extension_config(self, ext_type=None):
194  """ Initializes config objects for the path of extensions.
195 
196  Args:
197  ext_type (string): A specific extension type to load/reload a config object from. [global, user, or core]. If not provided, defaults to all.
198 
199  Raises:
200  ValueError: If the extension type passed is not either [core, global, or user]
201  """
202  self.log.debug(self.translate("logs", "Initializing {0} extension configs..".format(ext_type)))
203  extension_types = ['user', 'global', 'core']
204  if ext_type:
205  if str(ext_type) in extension_types:
206  extension_types = [ext_type]
207  else:
208  raise ValueError(self.translate("logs", "{0} is not an acceptable extension type.".format(ext_type)))
209  for type_ in extension_types:
210  try:
211  self.log.debug(self.translate("logs", "Creating {0} config manager".format(type_)))
212  self.extensions[type_] = ConfigManager(self.libraries[type_])
213  except ValueError:
214  self.log.debug(self.translate("logs", "There were no extensions found for the {0} library.".format(type_)))
215  continue
216  except KeyError:
217  self.log.debug(self.translate("logs", "There were no library path found for the {0} library.".format(type_)))
218  continue
219  self.log.debug(self.translate("logs", "Configs for {0} extension library loaded..".format(type_)))
def init_extension_config
Definition: extension_manager.py:192
Definition: extension_manager.py:616
def commotion_client.utils.extension_manager.ExtensionManager.init_extension_libraries (   self)
This function bootstraps the Commotion client when the settings are not populated on first boot or due to error. It iterates through all extensions in the core client and loads them.

References commotion_client.utils.extension_manager.ExtensionManager.init_extension_config(), commotion_client.utils.extension_manager.ExtensionManager.init_libraries(), commotion_client.utils.extension_manager.ExtensionManager.install_loaded(), commotion_client.utils.extension_manager.ExtensionManager.libraries, and commotion_client.utils.extension_manager.ExtensionManager.load_core().

97 
98  def init_extension_libraries(self):
99  """This function bootstraps the Commotion client when the settings are not populated on first boot or due to error. It iterates through all extensions in the core client and loads them."""
100 
101  #create directory structures if needed
102  self.init_libraries()
103  #load core and move to global if needed
104  self.log.debug(self.libraries)
105  self.load_core()
106  #Load all extension configs found in libraries
107  for name, path in self.libraries.items():
108  if QtCore.QDir(path).entryInfoList() != []:
109  self.init_extension_config(name)
110  #install all loaded config's with the existing settings
111  self.install_loaded()
def init_extension_libraries
Definition: extension_manager.py:97
def init_extension_config
Definition: extension_manager.py:192
def load_core
Definition: extension_manager.py:264
def install_loaded
Definition: extension_manager.py:299
def init_libraries
Definition: extension_manager.py:172
def commotion_client.utils.extension_manager.ExtensionManager.init_libraries (   self)
Creates a library folder, if it does not exit, in the directories specified for the current user and for the global application. 

References commotion_client.utils.extension_manager.ExtensionManager.libraries, commotion_client.GUI.menu_bar.MenuBar.translate, commotion_client.extensions.config_editor.main.ViewPort.translate, commotion_client.GUI.main_window.MainWindow.translate, commotion_client.GUI.toolbar_builder.ToolBar.translate, commotion_client.GUI.extension_toolbar.ExtensionToolBar.translate, commotion_client.GUI.toolbar.ToolBar.translate, commotion_client.utils.extension_manager.ExtensionManager.translate, commotion_client.GUI.extension_toolbar.MenuItem.translate, and commotion_client.commotion_client.CommotionClientApplication.translate.

Referenced by commotion_client.utils.extension_manager.ExtensionManager.init_extension_libraries().

173  def init_libraries(self):
174  """Creates a library folder, if it does not exit, in the directories specified for the current user and for the global application. """
175  #==== USER & GLOBAL =====#
176  for path_type in ['user', 'global']:
177  try:
178  ext_dir = QtCore.QDir(self.libraries[path_type])
179  except KeyError:
180  self.log.warning(self.translate("logs", "No directory is specified for the {0} library. Try running set_library_defaults to initalize the default libraries.".format(path_type)))
181  #If the directories are not yet created. We are not going to have this fail.
182  continue
183  if not ext_dir.exists():
184  if ext_dir.mkpath(ext_dir.absolutePath()):
185  self.log.debug(self.translate("logs", "Created the {0} extension library at {1}".format(path_type, str(ext_dir.absolutePath()))))
186  else:
187  self.log.debug(ext_dir.mkpath(ext_dir.absolutePath()))
188  self.log.debug(ext_dir.exists(ext_dir.absolutePath()))
189  raise IOError(self.translate("logs", "Could not create the extension library for {0}.".format(path_type)))
190  else:
191  self.log.debug(self.translate("logs", "The extension library at {0} already existed for {1}".format(str(ext_dir.absolutePath()), path_type)))
def init_libraries
Definition: extension_manager.py:172
def commotion_client.utils.extension_manager.ExtensionManager.install_loaded (   self,
  ext_type = None 
)
Installs loaded libraries by saving their settings into the application settings.

This function will install all loaded libraries into the users settings. It will add any missing configs and values that are not found. If a value exists install loaded will not change it.

Args:
  ext_type (string): A specific extension type [global or user] to load extensions from. If not provided, defaults to both.

Returns:
  List of names (strings) of extensions loaded  on success. Returns and empty list [] on failure.

Note on validation: Relies on save_settings to validate all fields.
Note on core: Core extensions are never "installed" they are used to populate the global library and then installed under global settings.

References commotion_client.utils.extension_manager.ExtensionManager.extensions, commotion_client.GUI.main_window.MainWindow.save_settings(), commotion_client.utils.extension_manager.ExtensionManager.save_settings(), commotion_client.GUI.menu_bar.MenuBar.translate, commotion_client.extensions.config_editor.main.ViewPort.translate, commotion_client.GUI.main_window.MainWindow.translate, commotion_client.GUI.toolbar_builder.ToolBar.translate, commotion_client.GUI.toolbar.ToolBar.translate, commotion_client.GUI.extension_toolbar.ExtensionToolBar.translate, commotion_client.utils.extension_manager.ExtensionManager.translate, commotion_client.GUI.extension_toolbar.MenuItem.translate, commotion_client.commotion_client.CommotionClientApplication.translate, and commotion_client.utils.extension_manager.ExtensionManager.user_settings.

Referenced by commotion_client.utils.extension_manager.ExtensionManager.init_extension_libraries().

300  def install_loaded(self, ext_type=None):
301  """Installs loaded libraries by saving their settings into the application settings.
302 
303  This function will install all loaded libraries into the users settings. It will add any missing configs and values that are not found. If a value exists install loaded will not change it.
304 
305  Args:
306  ext_type (string): A specific extension type [global or user] to load extensions from. If not provided, defaults to both.
307 
308  Returns:
309  List of names (strings) of extensions loaded on success. Returns and empty list [] on failure.
310 
311  Note on validation: Relies on save_settings to validate all fields.
312  Note on core: Core extensions are never "installed" they are used to populate the global library and then installed under global settings.
313 
314  """
315  _settings = self.user_settings
316  _keys = _settings.childKeys()
317  extension_types = ['user', 'global']
318  if ext_type and str(ext_type) in extension_types:
319  extension_types = [ext_type]
320  saved = []
321  for type_ in extension_types:
322  try:
323  ext_configs = self.extensions[type_].configs
324  except KeyError: #Check if type has not been set yet
325  self.log.info(self.translate("logs", "No extensions of type {0} are currently loaded.".format(type_)))
326  continue
327  if not ext_configs: #Check if the type has been created and then emptied
328  self.log.info(self.translate("logs", "No extensions of type {0} are currently loaded.".format(type_)))
329  continue
330  for _config in ext_configs:
331  #Only install if not already installed in this section.
332  if _config['name'] not in _keys:
333  #Attempt to save the extension.
334  if not self.save_settings(_config, type_):
335  self.log.warning(self.translate("logs", "Extension {0} could not be saved.".format(_config['name'])))
336  else:
337  saved.append(_config['name'])
338  return saved
def save_settings
Definition: extension_manager.py:492
def install_loaded
Definition: extension_manager.py:299
user_settings
Definition: extension_manager.py:64
def commotion_client.utils.extension_manager.ExtensionManager.load_core (   self)
Loads all core extensions into the globals library and re-initialized the global config.

This function bootstraps global library from the core library. It iterates through all extensions in the core library and populates the global config with any extensions it does not already contain and then loads them into the global config.

References commotion_client.utils.extension_manager.ExtensionManager.extensions, commotion_client.utils.extension_manager.ExtensionManager.init_extension_config(), commotion_client.utils.extension_manager.ExtensionManager.libraries, commotion_client.GUI.menu_bar.MenuBar.translate, commotion_client.extensions.config_editor.main.ViewPort.translate, commotion_client.GUI.main_window.MainWindow.translate, commotion_client.GUI.toolbar_builder.ToolBar.translate, commotion_client.GUI.toolbar.ToolBar.translate, commotion_client.GUI.extension_toolbar.ExtensionToolBar.translate, commotion_client.utils.extension_manager.ExtensionManager.translate, commotion_client.GUI.extension_toolbar.MenuItem.translate, and commotion_client.commotion_client.CommotionClientApplication.translate.

Referenced by commotion_client.utils.extension_manager.ExtensionManager.init_extension_libraries().

265  def load_core(self):
266  """Loads all core extensions into the globals library and re-initialized the global config.
267 
268  This function bootstraps global library from the core library. It iterates through all extensions in the core library and populates the global config with any extensions it does not already contain and then loads them into the global config.
269 
270  """
271  #Core extensions are loaded from the global directory.
272  #If a core extension has been deleted from the global directory it will be replaced from the core directory.
273  self.init_extension_config('core')
274  _core_dir = QtCore.QDir(self.libraries['core'])
275  _global_dir = QtCore.QDir(self.libraries['global'])
276  _reload_globals = False
277  for ext in self.extensions['core'].configs:
278  try:
279  #Check if the extension is in the globals
280  global_extensions = list(self.extensions['global'].configs.keys())
281  if ext['name'] in global_extensions:
282  self.log.debug(self.translate("logs", "Core extension {0} was found in the global extension list.".format(ext['name'])))
283  if not _global_dir.exists(ext['name']):
284  raise KeyError(self.translate("Extension {0} was found in the extension list, but it did not exist in the actual library. Loading it to global.".format(ext['name'])))
285  continue
286  except KeyError:
287  #If extension not loaded in globals it will raise a KeyError
288  _core_ext_path = _core_dir.absoluteFilePath(ext['name'])
289  _global_ext_path = _global_dir.absoluteFilePath(ext['name'])
290  self.log.info(self.translate("logs", "Core extension {0} was missing from the global extension directory. Copying it into the global extension directory from the core now.".format(ext['name'])))
291  #Copy extension into global directory
292  if QtCore.QFile(_core_ext_path).copy(_global_ext_path):
293  self.log.debug(self.translate("logs", "Extension successfully copied."))
294  else:
295  self.log.debug(self.translate("logs", "Extension was not copied."))
296  _reload_globals = True
297  if _reload_globals == True:
298  self.init_extension_config("global")
def init_extension_config
Definition: extension_manager.py:192
def load_core
Definition: extension_manager.py:264
def commotion_client.utils.extension_manager.ExtensionManager.load_user_interface (   self,
  extension_name,
  gui 
)
Return the graphical user interface (settings, main, toolbar) from an initialized extension.

Args:
  extension_name (string): The extension to load
  gui (string): Name of a objects sub-section. (settings, main, or toolbar)

Returns:
  The ( <UI Type> class) contained within the <extension_name> module.
Raise:
  AttributeError: If an invalid gui type is requested or an uninitialized extension gui is requested.

References commotion_client.utils.extension_manager.ExtensionManager.get_config(), commotion_client.utils.extension_manager.ExtensionManager.get_property(), commotion_client.utils.extension_manager.ExtensionManager.libraries, commotion_client.GUI.menu_bar.MenuBar.translate, commotion_client.extensions.config_editor.main.ViewPort.translate, commotion_client.GUI.main_window.MainWindow.translate, commotion_client.GUI.toolbar_builder.ToolBar.translate, commotion_client.GUI.toolbar.ToolBar.translate, commotion_client.GUI.extension_toolbar.ExtensionToolBar.translate, commotion_client.utils.extension_manager.ExtensionManager.translate, commotion_client.GUI.extension_toolbar.MenuItem.translate, and commotion_client.commotion_client.CommotionClientApplication.translate.

404  def load_user_interface(self, extension_name, gui):
405  """Return the graphical user interface (settings, main, toolbar) from an initialized extension.
406 
407  Args:
408  extension_name (string): The extension to load
409  gui (string): Name of a objects sub-section. (settings, main, or toolbar)
410 
411  Returns:
412  The ( <UI Type> class) contained within the <extension_name> module.
413  Raise:
414  AttributeError: If an invalid gui type is requested or an uninitialized extension gui is requested.
415  """
416  if str(gui) not in ["settings", "main", "toolbar"]:
417  self.log.debug(self.translate("logs", "{0} is not a supported user interface type.".format(str(gui))))
418  raise AttributeError(self.translate("logs", "Attempted to get a user interface of an invalid type."))
419  _config = self.get_config(extension_name)
420  try:
421  if _config['initialized'] != 'true':
422  self.log.debug(self.translate("logs", "Extension manager attempted to load a user interface from uninitalized extension {0}. Uninitialized extensions cannot be loaded. Try installing/initalizing the extension first.".format(extension_name)))
423  raise AttributeError(self.translate("logs", "Attempted to load a user interface from an uninitialized extension."))
424  except KeyError:
425  self.log.debug(self.translate("logs", "Extension manager attempted to load a user interface from uninitalized extension {0}. Uninitialized extensions cannot be loaded. Try installing/initalizing the extension first.".format(extension_name)))
426  raise AttributeError(self.translate("logs", "Attempted to load a user interface from an uninitialized extension."))
427  #Get ui file name and location of the extension from the settings.
428  ui_file = _config[gui]
429  _type = self.get_property(extension_name, "type")
430  extension_path = os.path.join(self.libraries[_type], extension_name)
431  self.log.debug(extension_path)
432  #Get the extension
433  extension = zipimport.zipimporter(extension_path)
434  #add extension to sys path so imported modules can access other modules in the extension.
435  sys.path.append(extension_path)
436  user_interface = extension.load_module(ui_file)
437  if gui == "toolbar":
438  return user_interface.ToolBar
439  elif gui == "main":
440  return user_interface.ViewPort
441  elif gui == "settings":
442  return user_interface.SettingsMenu
def get_property
Definition: extension_manager.py:374
def load_user_interface
Definition: extension_manager.py:403
def get_config
Definition: extension_manager.py:443
def commotion_client.utils.extension_manager.ExtensionManager.remove_extension_settings (   self,
  name 
)
Removes an extension and its core properties from the applications extension settings.

long description

Args:
  name (str): the name of an extension to remove from the extension settings.

Returns:
  bool: True if extension is removed, false if it is not.

Raises:
  ValueError: When an empty string is passed as an argument.

References commotion_client.utils.extension_manager.ExtensionManager.reset_settings_group(), commotion_client.GUI.menu_bar.MenuBar.translate, commotion_client.extensions.config_editor.main.ViewPort.translate, commotion_client.GUI.main_window.MainWindow.translate, commotion_client.GUI.toolbar_builder.ToolBar.translate, commotion_client.GUI.toolbar.ToolBar.translate, commotion_client.GUI.extension_toolbar.ExtensionToolBar.translate, commotion_client.utils.extension_manager.ExtensionManager.translate, commotion_client.GUI.extension_toolbar.MenuItem.translate, commotion_client.commotion_client.CommotionClientApplication.translate, and commotion_client.utils.extension_manager.ExtensionManager.user_settings.

468  def remove_extension_settings(self, name):
469  """Removes an extension and its core properties from the applications extension settings.
470 
471  long description
472 
473  Args:
474  name (str): the name of an extension to remove from the extension settings.
475 
476  Returns:
477  bool: True if extension is removed, false if it is not.
478 
479  Raises:
480  ValueError: When an empty string is passed as an argument.
481  """
482  #make sure that a string of "" is not passed to this function because that would remove all keys.
483  self.reset_settings_group()
484  if len(str(name)) > 0:
485  _settings = self.user_settings
486  _settings.remove(str(name))
487  return True
488  else:
489  self.log.debug(self.translate("logs", "A zero length string was passed as the name of an extension to be removed. This would delete all the extensions if it was allowed to succeed."))
490  raise ValueError(self.translate("logs", "You must specify an extension name greater than 1 char."))
491  return False
def remove_extension_settings
Definition: extension_manager.py:467
def reset_settings_group
Definition: extension_manager.py:86
user_settings
Definition: extension_manager.py:64
def commotion_client.utils.extension_manager.ExtensionManager.reset_settings_group (   self)
Resets the user_settings group to be at the top of the extensions group.

Some functions modify the user_settings location to point at indiviudal extensions or other sub-groups. This function resets the settings to point at the top of the extensions group.

NOTE: This should not be seen as a way to avoid doing clean up on functions you initiate. It is merely a way to ensure that on critical functions (deletions or modifications of existing settings) that errors do not cause data loss for users..

Referenced by commotion_client.utils.extension_manager.ExtensionManager.remove_extension_settings().

86 
87  def reset_settings_group(self):
88  """Resets the user_settings group to be at the top of the extensions group.
89 
90  Some functions modify the user_settings location to point at indiviudal extensions or other sub-groups. This function resets the settings to point at the top of the extensions group.
91 
92  NOTE: This should not be seen as a way to avoid doing clean up on functions you initiate. It is merely a way to ensure that on critical functions (deletions or modifications of existing settings) that errors do not cause data loss for users..
93  """
94  while self.user_settings.group():
95  self.user_settings.endGroup()
96  self.user_settings.beginGroup("extensions")
def reset_settings_group
Definition: extension_manager.py:86
def commotion_client.utils.extension_manager.ExtensionManager.save_settings (   self,
  extension_config,
  extension_type = "global" 
)
Saves an extensions core properties into the applications extension settings.

long description

Args:
  extension_config (dict) An extension config in dictionary format.
  extension_type (string): Type of extension "user" or "global". Defaults to global.

Returns:
  bool: True if successful, False on any failures

References commotion_client.utils.extension_manager.ExtensionManager.libraries, commotion_client.GUI.menu_bar.MenuBar.translate, commotion_client.extensions.config_editor.main.ViewPort.translate, commotion_client.GUI.main_window.MainWindow.translate, commotion_client.GUI.toolbar_builder.ToolBar.translate, commotion_client.GUI.toolbar.ToolBar.translate, commotion_client.GUI.extension_toolbar.ExtensionToolBar.translate, commotion_client.utils.extension_manager.ExtensionManager.translate, commotion_client.GUI.extension_toolbar.MenuItem.translate, commotion_client.commotion_client.CommotionClientApplication.translate, and commotion_client.utils.extension_manager.ExtensionManager.user_settings.

Referenced by commotion_client.utils.extension_manager.ExtensionManager.install_loaded().

493  def save_settings(self, extension_config, extension_type="global"):
494  """Saves an extensions core properties into the applications extension settings.
495 
496  long description
497 
498  Args:
499  extension_config (dict) An extension config in dictionary format.
500  extension_type (string): Type of extension "user" or "global". Defaults to global.
501 
502  Returns:
503  bool: True if successful, False on any failures
504  """
505  _settings = self.user_settings
506  #get extension dir
507  try:
508  extension_dir = self.libraries[extension_type]
509  except KeyError:
510  self.log.warning(self.translate("logs", "Invalid extension type. Please check the extension type and try again."))
511  return False
512  #create validator
513  try:
514  config_validator = validate.ClientConfig(extension_config, extension_dir)
515  except KeyError as _excp:
516  self.log.warning(self.translate("logs", "The extension is missing a name value which is required."))
517  self.log.debug(_excp)
518  return False
519  except FileNotFoundError as _excp:
520  self.log.warning(self.translate("logs", "The extension was not found on the system and therefore cannot be saved."))
521  self.log.debug(_excp)
522  return False
523  #Extension Name
524  try:
525  extension_name = extension_config['name']
526  if config_validator.name():
527  _settings.beginGroup(extension_name)
528  _settings.setValue("name", extension_name)
529  else:
530  _error = self.translate("logs", "The extension's name is invalid and cannot be saved.")
531  self.log.error(_error)
532  return False
533  except KeyError:
534  _error = self.translate("logs", "The extension is missing a name value which is required.")
535  self.log.error(_error)
536  return False
537  #Extension Main
538  try:
539  _main = extension_config['main']
540  if not config_validator.gui(_main):
541  _error = self.translate("logs", "The config's main value is invalid and cannot be saved.")
542  self.log.error(_error)
543  return False
544  except KeyError:
545  _main = "main" #Set this for later default values
546  if not config_validator.gui(_main):
547  _settings.setValue("main", _main)
548  else:
549  _settings.setValue("main", _main)
550  #Extension Settings & Toolbar
551  for val in ["settings", "toolbar"]:
552  try:
553  _config_value = extension_config[val]
554  if not config_validator.gui(val):
555  _error = self.translate("logs", "The config's {0} value is invalid and cannot be saved.".format(val))
556  self.log.error(_error)
557  return False
558  except KeyError:
559  #Defaults to main, which was checked and set before
560  _settings.setValue(val, _main)
561  else:
562  _settings.setValue(val, _config_value)
563  #Extension Parent
564  try:
565  _parent = extension_config["parent"]
566  if config_validator.parent():
567  _settings.setValue("parent", _parent)
568  else:
569  _error = self.translate("logs", "The config's parent value is invalid and cannot be saved.")
570  self.log.error(_error)
571  return False
572  except KeyError:
573  self.log.debug(self.translate("logs", "Config for {0} does not contain a {1} value. Setting {1} to default value.".format(extension_name, "parent")))
574  _settings.setValue("parent", "Extensions")
575  #Extension Menu Item
576  try:
577  _menu_item = extension_config["menu_item"]
578  if config_validator.menu_item():
579  _settings.setValue("menu_item", _menu_item)
580  else:
581  _error = self.translate("logs", "The config's menu_item value is invalid and cannot be saved.")
582  self.log.error(_error)
583  return False
584  except KeyError:
585  self.log.debug(self.translate("logs", "Config for {0} does not contain a {1} value. Setting {1} to default value.".format(extension_name, "menu_item")))
586  _settings.setValue("menu_item", extension_name)
587  #Extension Menu Level
588  try:
589  _menu_level = extension_config["menu_level"]
590  if config_validator.menu_level():
591  _settings.setValue("menu_level", _menu_level)
592  else:
593  _error = self.translate("logs", "The config's menu_level value is invalid and cannot be saved.")
594  self.log.error(_error)
595  return False
596  except KeyError:
597  self.log.debug(self.translate("logs", "Config for {0} does not contain a {1} value. Setting {1} to default value.".format(extension_name, "menu_level")))
598  _settings.setValue("menu_level", 10)
599  #Extension Tests
600  try:
601  _tests = extension_config['tests']
602  if config_validator.tests():
603  _settings.setValue("tests", _tests)
604  else:
605  _error = self.translate("logs", "Extension {0} does not contain the {1} file listed in the config for its tests. Please either remove the listing to allow for the default value, or add the appropriate file.".format(extension_name, _config_value))
606  self.log.error(_error)
607  return False
608  except KeyError:
609  self.log.debug(self.translate("logs", "Config for {0} does not contain a {1} value. Setting {1} to default value.".format(extension_name, "tests")))
610  _settings.setValue("tests", "tests")
611  #Write extension type
612  _settings.setValue("type", extension_type)
613  _settings.setValue("initialized", 'true')
614  _settings.endGroup()
615  return True
def save_settings
Definition: extension_manager.py:492
user_settings
Definition: extension_manager.py:64
def commotion_client.utils.extension_manager.ExtensionManager.set_library_defaults (   self)
Sets the default directories for core, user, and global extensions.

OS Defaults:

  OSX:
    user: $HOME/Library/Commotion/extension_data/
    global: /Library/Application Support /Commotion/extension_data/

  Windows:
    user: %APPDATA%\\Local\\Commotion\\extension_data\\.
    global: %COMMON_APPDATA%\\Local\\Commotion\extension_data\\.
    The %APPDATA% path is usually C:\\Documents and Settings\\User Name\\Application Data; the %COMMON_APPDATA% path is usually C:\\Documents and Settings\\All Users\\Application Data.

  Linux:
    user: $HOME/.Commotion/extension_data/
    global: /usr/share/Commotion/extension_data/

Raises:
  IOError: If the application does not have permission to create ANY of the extension directories.

References commotion_client.utils.extension_manager.ExtensionManager.libraries, commotion_client.GUI.menu_bar.MenuBar.translate, commotion_client.extensions.config_editor.main.ViewPort.translate, commotion_client.GUI.main_window.MainWindow.translate, commotion_client.GUI.toolbar_builder.ToolBar.translate, commotion_client.GUI.extension_toolbar.ExtensionToolBar.translate, commotion_client.GUI.toolbar.ToolBar.translate, commotion_client.utils.extension_manager.ExtensionManager.translate, commotion_client.GUI.extension_toolbar.MenuItem.translate, and commotion_client.commotion_client.CommotionClientApplication.translate.

113  def set_library_defaults(self):
114  """Sets the default directories for core, user, and global extensions.
115 
116  OS Defaults:
117 
118  OSX:
119  user: $HOME/Library/Commotion/extension_data/
120  global: /Library/Application Support /Commotion/extension_data/
121 
122  Windows:
123  user: %APPDATA%\\Local\\Commotion\\extension_data\\.
124  global: %COMMON_APPDATA%\\Local\\Commotion\extension_data\\.
125  The %APPDATA% path is usually C:\\Documents and Settings\\User Name\\Application Data; the %COMMON_APPDATA% path is usually C:\\Documents and Settings\\All Users\\Application Data.
126 
127  Linux:
128  user: $HOME/.Commotion/extension_data/
129  global: /usr/share/Commotion/extension_data/
130 
131  Raises:
132  IOError: If the application does not have permission to create ANY of the extension directories.
133  """
134  #==== Core ====#
135  _app_path = QtCore.QDir(QtCore.QCoreApplication.applicationDirPath())
136  _app_path.cd("extensions")
137  _app_path.cd("core")
138  #set the core extension directory
139  self.libraries['core'] = _app_path.absolutePath()
140  self.log.debug(self.translate("logs", "Core extension directory succesfully set."))
141 
142  #==== SYSTEM DEFAULTS =====#
143  self.log.debug(self.translate("logs", "Setting the default extension directory defaults."))
144  platform = sys.platform
145  #Default global and user extension directories per platform.
146  #win23, darwin, and linux supported.
147  platform_dirs = {
148  'darwin': {
149  'user' : os.path.join("Library", "Commotion", "extension_data"),
150  'user_root': QtCore.QDir.home(),
151  'global' : os.path.join("Library", "Application Support", "Commotion", "extension_data"),
152  'global_root' : QtCore.QDir.root()},
153  'win32' : {
154  'user':os.path.join("Local", "Commotion", "extension_data"),
155  'user_root': QtCore.QDir(os.getenv('APPDATA')),
156  'global':os.path.join("Local", "Commotion", "extension_data"),
157  'global_root' : QtCore.QDir(os.getenv('COMMON_APPDATA'))},
158  'linux': {
159  'user':os.path.join(".Commotion", "extension_data"),
160  'user_root': QtCore.QDir.home(),
161  'global':os.path.join("extensions", "global"),
162  'global_root' : QtCore.QDir(QtCore.QCoreApplication.applicationDirPath())}}
163  for path_type in ['user', 'global']:
164  ext_dir = platform_dirs[platform][path_type+'_root']
165  ext_path = platform_dirs[platform][path_type]
166  self.log.debug(self.translate("logs", "The root directory of {0} is {1}.".format(path_type, ext_dir.path())))
167  #move the root directory to the correct sub-path.
168  lib_path = ext_dir.filePath(ext_path)
169  self.log.debug(self.translate("logs", "The extension directory has been set to {0}..".format(lib_path)))
170  #Set the extension directory.
171  self.libraries[path_type] = lib_path
def set_library_defaults
Definition: extension_manager.py:112

The documentation for this class was generated from the following file: