Пример #1
0
    def commit_changes(self):
        if self.boundaries is not None:
            module_source = inspect.getsourcelines(self._module)[0]
            new_source = module_source[: self.boundaries[0] - 1]
            new_source.extend(self.generate_code())
            new_source.extend(module_source[self.boundaries[1] :])

            imports_line = self._remove_imports(new_source)
            self._cleanup_imports(new_source)
            new_imports = self._generate_imports()
            for no, imprt in enumerate(new_imports):
                new_source.insert(imports_line + no, imprt)

            modulefilename = self._module.__file__
            if modulefilename[-1] in ["c", "o"]:
                modulefilename = modulefilename[:-1]

            modfile = open(modulefilename, "w")
            modfile.writelines(new_source)
            modfile.close()

            # we must reload the class module
            misc.reload_module(self._module)
            # reload module in multi-processing enviroments
            services.notify(("RELOAD_MODULE", self._module.__name__))
Пример #2
0
    def commit_changes(self):
        if self.boundaries is not None:
            module_source = inspect.getsourcelines(self._module)[0]
            new_source = module_source[:self.boundaries[0] - 1]
            new_source.extend(self.generate_code())
            new_source.extend(module_source[self.boundaries[1]:])

            imports_line = self._remove_imports(new_source)
            self._cleanup_imports(new_source)
            new_imports = self._generate_imports()
            for no, imprt in enumerate(new_imports):
                new_source.insert(imports_line + no, imprt)

            modulefilename = self._module.__file__
            if modulefilename[-1] in ['c', 'o']:
                modulefilename = modulefilename[:-1]

            modfile = open(modulefilename, 'w')
            modfile.writelines(new_source)
            modfile.close()

            # we must reload the class module
            misc.reload_module(self._module)
            # reload module in multi-processing enviroments
            services.notify(('RELOAD_MODULE', self._module.__name__))
        def _manage(self):
            while True:
                command = self.connection.recv()
                if command == self.sentinel:
                    break
                if isinstance(command, (list, tuple)):
                    command, params = command
                if command == "DB_LOCK":
                    self.lock_db()
                elif command == "DB_UNLOCK":
                    self.unlock_db()
                elif command == "DB_OPEN":
                    self.add_runtime_service("db")
                elif command == "DB_CLOSE":
                    self.remove_runtime_service("db")
                elif command == "NEW_MASTER":
                    from porcupine.db import _db

                    _db.get_replication_manager().master = params
                elif command == "RELOAD_PACKAGE":
                    try:
                        mod = sys.modules[params]
                        misc.reload_module_tree(mod)
                    except KeyError:
                        pass
                elif command == "RELOAD_MODULE":
                    try:
                        mod = sys.modules[params]
                        misc.reload_module(mod)
                    except KeyError:
                        pass
                elif command == "ADD_PUBDIR":
                    from porcupine.config import pubdirs

                    dir_name, dir = params
                    pubdirs.dirs[dir_name] = dir
                elif command == "REMOVE_PUBDIR":
                    from porcupine.config import pubdirs

                    try:
                        del pubdirs.dirs[params]
                    except KeyError:
                        pass

                self.connection.send(True)

            self.connection.send(None)
            self.is_alive = False
Пример #4
0
        def _manage(self):
            while True:
                command = self.connection.recv()
                if command == self.sentinel:
                    break
                if isinstance(command, (list, tuple)):
                    command, params = command

                if command == 'DB_LOCK':
                    self.lock_db()
                elif command == 'DB_UNLOCK':
                    self.unlock_db()
                elif command == 'DB_OPEN':
                    self.add_runtime_service('db')
                elif command == 'DB_CLOSE':
                    self.remove_runtime_service('db')
                elif command == 'NEW_MASTER':
                    from porcupine.db import _db
                    _db.get_replication_manager().master = params
                elif command == 'RELOAD_PACKAGE':
                    try:
                        mod = sys.modules[params]
                        misc.reload_module_tree(mod)
                    except KeyError:
                        pass
                elif command == 'RELOAD_MODULE':
                    try:
                        mod = sys.modules[params]
                        misc.reload_module(mod)
                    except KeyError:
                        pass
                elif command == 'ADD_PUBDIR':
                    from porcupine.config import pubdirs
                    dir_name, dir = params
                    pubdirs.dirs[dir_name] = dir
                elif command == 'REMOVE_PUBDIR':
                    from porcupine.config import pubdirs
                    try:
                        del pubdirs.dirs[params]
                    except KeyError:
                        pass

                self.connection.send(True)

            self.connection.send(None)
            self.is_alive = False