コード例 #1
0
 def load(self):
     """Load the repository permission file"""
     self.update({
         "roles": {
             "default": [],
             "admin": []
         },
         "files": {},
         "general": {
             "users_remove_locks": [],
             "roles_remove_locks": ["default", "admin"],
             "users_add_locks": [],
             "roles_add_locks": ["default", "admin"],
             "users_write": [],
             "roles_write": ["default", "admin"],
             "users_grant": [],
             "roles_grant": ["default", "admin"],
             "users_modify_roles": [],
             "roles_modify_roles": ["default", "admin"]
         }
     })
     try:
         self.update(json.load(open(self.__path)))
     except FileNotFoundError:
         # Log that loading the configuration failed
         Logger.info('MEG PERMISSIONS: Could not load permissions file <' +
                     self.__path + '>, using default permissions')
コード例 #2
0
 def _update(plugin_path, force=False):
     """Create plugin information from plugin path"""
     # Get the plugin path and load plugin information
     plugin = Plugin(plugin_path)
     # If forcing do not bother checking new version
     if not force:
         # Check the plugin does not already exist by name
         current_plugin = PluginManager.get(plugin.name())
         if current_plugin is not None:
             # Determine higher version and keep that plugin
             comparison = Plugin.compare_versions(plugin, current_plugin)
             # The versions were equal so check if there are additional version fields
             if comparison == 0:
                 # This plugin appears to be the same version so skip this one
                 Logger.info(
                     f'Plugin "{plugin.name()}" with version {plugin.version()} ignored because the same version already exists'
                 )
                 plugin = None
             elif comparison < 0:
                 # This plugin is older version than the previously loaded plugin so skip this one
                 raise PluginException(
                     f'Plugin "{plugin.name()}" with version {plugin.version()} ignored because newer version {current_plugin.version()} already exists'
                 )
             else:
                 # This plugin is newer version than the previously loaded plugin so replace with this one
                 Logger.info(
                     f'MEG Plugins: Plugin "{plugin.name()}" with version {current_plugin.version()} replaced with newer version {plugin.version()}'
                 )
     # Return the created plugin information
     return plugin
コード例 #3
0
 def _generateLockFile(self):
     """If the lock file doesn't exist, generate the directory tree and create the file
     """
     if not os.path.isfile(self.__path):
         Logger.info("MEG LOCKING: GENERATING LOCK FILE")
         os.makedirs(os.path.dirname(self.__path), exist_ok=True)
         open(self.__path, 'w+').close()
コード例 #4
0
 def on_start(self):
     """On application start"""
     # Log information about version
     Logger.info(f'MEG: {App.NAME} Version {App.VERSION}')
     # Log debug information about home directory
     Logger.debug(f'MEG: Home <{Config.get("path/home")}>')
     # Load configuration
     Config.load()
     # Log debug information about cache and plugin directories
     Logger.debug(f'MEG: Cache <{Config.get("path/cache")}>')
     Logger.debug(f'MEG: Plugins <{Config.get("path/plugins")}>')
     # Update plugins information
     PluginManager.update()
     # Load enabled plugins
     PluginManager.load_enabled()
コード例 #5
0
    def load(self):
        """Loads this object with the current data in the locks file
        Discards the any currently held locks

        Args:
            filepath (string): path to the lockfile
        Returns:
            (bool): False if lockfile cannot be read
        """
        self.__lockData = {}
        data = None
        try:
            with open(self.__path, 'r') as lockfile:
                data = json.load(lockfile)
                lockfile.close()
        except json.decoder.JSONDecodeError:
            Logger.warning("MEG Locking: Unable to read contents of lock file at {0}".format(self.__path))
            return False
        except FileNotFoundError:
            Logger.info("MEG Locking: Lock file doesn't yet exist at {0}".format(self.__path))
            return True
        if data is not None:
            self.__lockData = data
        return True