Python .reload() Examples

The following are 8 code examples of .reload(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module , or try the search function .
Example #1
Source File: test_login.py    From iguana with Creative Commons Attribution Share Alike 4.0 International 6 votes vote down vote up
def createTempViewURL():
    # add the TempView to the urlpatterns
    global urlpatterns
    urlpatterns += [
        url(r'^temp/?', TempView.as_view(), name='temp'),
    ]

    # reload the urlpatterns
    urlconf = settings.ROOT_URLCONF
    if urlconf in sys.modules:
        reload(sys.modules[urlconf])
    reloaded = import_module(urlconf)
    reloaded_urls = getattr(reloaded, 'urlpatterns')
    set_urlconf(tuple(reloaded_urls))

    # return the temporary URL
    return reverse('temp') 
Example #2
Source File: Pocket.py    From WebPocket with GNU General Public License v3.0 5 votes vote down vote up
def do_use(self, module_name, module_reload=False):
        """Chose a module"""
        module_file = module.name_convert(module_name)
        module_type = module_name.split("/")[0]

        if Path(module_file).is_file():
            self.module_name = module_name
            if module_reload:
                self.module_class = reload(self.module_class)
            else:
                self.module_class = import_module("modules.{module_name}".format(module_name=module_name.replace("/", ".")))
            self.module_instance = self.module_class.Exploit()
            self.set_prompt(module_type=module_type, module_name=module_name)
        else:
            self.poutput("Module/Exploit not found.") 
Example #3
Source File: Pocket.py    From WebPocket with GNU General Public License v3.0 5 votes vote down vote up
def do_reload(self, args):
        """reload the chose module"""
        self.do_use(self.module_name, module_reload=True) 
Example #4
Source File: ASRManager.py    From ProjectAlice with GNU General Public License v3.0 5 votes vote down vote up
def _startASREngine(self):
		userASR = self.ConfigManager.getAliceConfigByName(configName='asr').lower()
		keepASROffline = self.ConfigManager.getAliceConfigByName('keepASROffline')
		stayOffline = self.ConfigManager.getAliceConfigByName('stayCompletlyOffline')
		online = self.InternetManager.online

		self._asr = None

		if userASR == 'google':
			package = 'core.asr.model.GoogleASR'
		elif userASR == 'deepspeech':
			package = 'core.asr.model.DeepSpeechASR'
		else:
			package = 'core.asr.model.PocketSphinxASR'

		module = import_module(package)
		asr = getattr(module, package.rsplit('.', 1)[-1])
		self._asr = asr()

		if not self._asr.checkDependencies():
			if not self._asr.install():
				self._asr = None
			else:
				module = reload(module)
				asr = getattr(module, package.rsplit('.', 1)[-1])
				self._asr = asr()

		if self._asr is None:
			self.logFatal("Couldn't install ASR, going down")
			return

		if self._asr.isOnlineASR and (not online or keepASROffline or stayOffline):
			self._asr = None

		if self._asr is None:
			self.logWarning('ASR did not satisfy the user settings, falling back to Deepspeech')
			from core.asr.model.DeepSpeechASR import DeepSpeechASR

			self._asr = DeepSpeechASR()

		self._asr.onStart() 
Example #5
Source File: utils.py    From ika with GNU Affero General Public License v3.0 5 votes vote down vote up
def import_class_from_module(name):
    try:
        _module = reload_module(import_module(name))
    except ImportError:
        from ika.logger import logger
        logger.exception(f'Missing module!: {name}')
    else:
        _, cls = inspect.getmembers(_module, lambda member: inspect.isclass(member)
            and member.__module__ == name)[0]
        return cls


# modesdef: http://www.irc.org/tech_docs/005.html 
Example #6
Source File: loader.py    From bioforum with MIT License 4 votes vote down vote up
def load_disk(self):
        """Load the migrations from all INSTALLED_APPS from disk."""
        self.disk_migrations = {}
        self.unmigrated_apps = set()
        self.migrated_apps = set()
        for app_config in apps.get_app_configs():
            # Get the migrations module directory
            module_name, explicit = self.migrations_module(app_config.label)
            if module_name is None:
                self.unmigrated_apps.add(app_config.label)
                continue
            was_loaded = module_name in sys.modules
            try:
                module = import_module(module_name)
            except ImportError as e:
                # I hate doing this, but I don't want to squash other import errors.
                # Might be better to try a directory check directly.
                if ((explicit and self.ignore_no_migrations) or (
                        not explicit and "No module named" in str(e) and MIGRATIONS_MODULE_NAME in str(e))):
                    self.unmigrated_apps.add(app_config.label)
                    continue
                raise
            else:
                # PY3 will happily import empty dirs as namespaces.
                if not hasattr(module, '__file__'):
                    self.unmigrated_apps.add(app_config.label)
                    continue
                # Module is not a package (e.g. migrations.py).
                if not hasattr(module, '__path__'):
                    self.unmigrated_apps.add(app_config.label)
                    continue
                # Force a reload if it's already loaded (tests need this)
                if was_loaded:
                    reload(module)
            self.migrated_apps.add(app_config.label)
            directory = os.path.dirname(module.__file__)
            # Scan for .py files
            migration_names = set()
            for name in os.listdir(directory):
                if name.endswith(".py"):
                    import_name = name.rsplit(".", 1)[0]
                    if import_name[0] not in "_.~":
                        migration_names.add(import_name)
            # Load them
            for migration_name in migration_names:
                migration_module = import_module("%s.%s" % (module_name, migration_name))
                if not hasattr(migration_module, "Migration"):
                    raise BadMigrationError(
                        "Migration %s in app %s has no Migration class" % (migration_name, app_config.label)
                    )
                self.disk_migrations[app_config.label, migration_name] = migration_module.Migration(
                    migration_name,
                    app_config.label,
                ) 
Example #7
Source File: fd_text_editor.py    From Fluid-Designer with GNU General Public License v3.0 4 votes vote down vote up
def execute(self,context):
        from importlib import import_module, reload
        import sys
        wm = context.window_manager.cabinetlib
        for member in wm.module_members:
            wm.module_members.remove(0)
        
        active_module = bpy.context.edit_text.name.replace(".py","")
        
        mod = import_module(active_module)
        del sys.modules[active_module]
#         mod1 = import_module(active_module)
        mod = reload(mod)
        for name, obj in inspect.getmembers(mod):

            if inspect.isclass(obj) and "PRODUCT_" in name:
                mod_member = wm.module_members.add()
                mod_member.name = name
                
            elif inspect.isclass(obj) and "INSERT_" in name:    
                mod_member = wm.module_members.add()
                mod_member.name = name            
                
            elif "PROPERTIES" in name:    
                mod_member = wm.module_members.add()
                mod_member.name = name                                       
                
            elif "PROMPTS" in name:    
                mod_member = wm.module_members.add()
                mod_member.name = name     
                
            elif "Material_Pointers" in name:    
                mod_member = wm.module_members.add()
                mod_member.name = name 
                
            elif "Cutpart_Pointers" in name:    
                mod_member = wm.module_members.add()
                mod_member.name = name 
                
            elif "Edgepart_Pointers" in name:    
                mod_member = wm.module_members.add()
                mod_member.name = name                      
                
            elif "OPERATOR" in name:
                mod_member = wm.module_members.add()
                mod_member.name = name                                     
                
            elif inspect.isclass(obj) and "LM_" in obj.__module__:
                mod_member = wm.module_members.add()
                mod_member.name = name   

        return {'FINISHED'} 
Example #8
Source File: loader.py    From Hands-On-Application-Development-with-PyCharm with MIT License 4 votes vote down vote up
def load_disk(self):
        """Load the migrations from all INSTALLED_APPS from disk."""
        self.disk_migrations = {}
        self.unmigrated_apps = set()
        self.migrated_apps = set()
        for app_config in apps.get_app_configs():
            # Get the migrations module directory
            module_name, explicit = self.migrations_module(app_config.label)
            if module_name is None:
                self.unmigrated_apps.add(app_config.label)
                continue
            was_loaded = module_name in sys.modules
            try:
                module = import_module(module_name)
            except ImportError as e:
                # I hate doing this, but I don't want to squash other import errors.
                # Might be better to try a directory check directly.
                if ((explicit and self.ignore_no_migrations) or (
                        not explicit and "No module named" in str(e) and MIGRATIONS_MODULE_NAME in str(e))):
                    self.unmigrated_apps.add(app_config.label)
                    continue
                raise
            else:
                # Empty directories are namespaces.
                # getattr() needed on PY36 and older (replace w/attribute access).
                if getattr(module, '__file__', None) is None:
                    self.unmigrated_apps.add(app_config.label)
                    continue
                # Module is not a package (e.g. migrations.py).
                if not hasattr(module, '__path__'):
                    self.unmigrated_apps.add(app_config.label)
                    continue
                # Force a reload if it's already loaded (tests need this)
                if was_loaded:
                    reload(module)
            self.migrated_apps.add(app_config.label)
            migration_names = {
                name for _, name, is_pkg in pkgutil.iter_modules(module.__path__)
                if not is_pkg and name[0] not in '_~'
            }
            # Load migrations
            for migration_name in migration_names:
                migration_path = '%s.%s' % (module_name, migration_name)
                try:
                    migration_module = import_module(migration_path)
                except ImportError as e:
                    if 'bad magic number' in str(e):
                        raise ImportError(
                            "Couldn't import %r as it appears to be a stale "
                            ".pyc file." % migration_path
                        ) from e
                    else:
                        raise
                if not hasattr(migration_module, "Migration"):
                    raise BadMigrationError(
                        "Migration %s in app %s has no Migration class" % (migration_name, app_config.label)
                    )
                self.disk_migrations[app_config.label, migration_name] = migration_module.Migration(
                    migration_name,
                    app_config.label,
                )