コード例 #1
0
    def upgrade_db(self):
        """
		Call C{specturm --check-db-version} to see if the schema version
		of the database is up to date. If not, call C{spectrum
		--upgrade-db} and try to upgrade the schema.

		@raise RuntimeError: If any of the launched commands fail.
		"""
        path = os.path.abspath(self.config_path)

        # fork and drop privileges:
        pid = os.fork()
        if pid:
            # we are the parent!
            pid, status = os.waitpid(pid, 0)
            status = (status & 0xff00) >> 8
            if status == 0:
                return
            elif status == 1:
                raise RuntimeError("db_version table does not exist", 1)
            elif status == 3:
                raise RuntimeError("Error connecting to the database", 1)
            elif status == 100:
                raise RuntimeError("Could not find spectrum binary", 1)
            elif status == 101:
                raise RuntimeError(
                    "Exception thrown, please contact the maintainers", 1)
            elif status == 102:
                raise RuntimeError("Username does not exist", 1)
            else:
                raise RuntimeError("Child exited with unknown exit status", 1)
        else:
            exit_code = 0
            try:
                # drop privileges:
                try:
                    env.drop_privs(env.get_uid(), env.get_gid())
                except RuntimeError, e:
                    os._exit(102)

                check_cmd = [self.get_binary(), '--check-db-version', path]
                process = Popen(check_cmd, stdout=PIPE)
                process.communicate()

                if process.returncode == 2:
                    update_cmd = ['spectrum', '--upgrade-db', path]
                    process = Popen(update_cmd, stdout=PIPE)
                    process.communicate()
                    os._exit(process.returncode)

                else:
                    os._exit(process.returncode)
            except OSError, e:
                os._exit(100)  # spectrum wasn't found
コード例 #2
0
ファイル: spectrum.py プロジェクト: bochi/spectrum-gw
    def upgrade_db(self):
        """
		Call C{specturm --check-db-version} to see if the schema version
		of the database is up to date. If not, call C{spectrum
		--upgrade-db} and try to upgrade the schema.

		@raise RuntimeError: If any of the launched commands fail.
		"""
        path = os.path.abspath(self.config_path)

        # fork and drop privileges:
        pid = os.fork()
        if pid:
            # we are the parent!
            pid, status = os.waitpid(pid, 0)
            status = (status & 0xFF00) >> 8
            if status == 0:
                return
            elif status == 1:
                raise RuntimeError("db_version table does not exist", 1)
            elif status == 3:
                raise RuntimeError("Error connecting to the database", 1)
            elif status == 100:
                raise RuntimeError("Could not find spectrum binary", 1)
            elif status == 101:
                raise RuntimeError("Exception thrown, please contact the maintainers", 1)
            elif status == 102:
                raise RuntimeError("Username does not exist", 1)
            else:
                raise RuntimeError("Child exited with unknown exit status", 1)
        else:
            exit_code = 0
            try:
                # drop privileges:
                try:
                    env.drop_privs(env.get_uid(), env.get_gid())
                except RuntimeError, e:
                    os._exit(102)

                check_cmd = [self.get_binary(), "--check-db-version", path]
                process = subprocess.Popen(check_cmd, stdout=subprocess.PIPE)
                process.communicate()

                if process.returncode == 2:
                    update_cmd = ["spectrum", "--upgrade-db", path]
                    process = subprocess.Popen(update_cmd, stdout=subprocess.PIPE)
                    process.communicate()
                    os._exit(process.returncode)

                else:
                    os._exit(process.returncode)
            except OSError, e:
                os._exit(100)  # spectrum wasn't found
コード例 #3
0
                raise RuntimeError("Error connecting to the database", 1)
            elif status == 100:
                raise RuntimeError("Could not find spectrum binary", 1)
            elif status == 101:
                raise RuntimeError(
                    "Exception thrown, please contact the maintainers", 1)
            elif status == 102:
                raise RuntimeError("Username does not exist", 1)
            else:
                raise RuntimeError("Child exited with unknown exit status", 1)
        else:
            exit_code = 0
            try:
                # we are the child
                try:
                    env.drop_privs(env.get_uid(), env.get_gid())
                except RuntimeError, e:
                    os._exit(102)

                # get the absolute path of the config file
                path = os.path.abspath(self.config_path)

                # check if database is at current version:
                check_cmd = [self.get_binary(), '--check-db-version', path]
                process = Popen(check_cmd, stdout=PIPE)
                process.communicate()
                if process.returncode != 0:
                    os._exit(process.returncode)

                # finally start spectrum:
                cmd = [self.get_binary()]
コード例 #4
0
ファイル: spectrum.py プロジェクト: bochi/spectrum-gw
            elif status == 3:
                raise RuntimeError("Error connecting to the database", 1)
            elif status == 100:
                raise RuntimeError("Could not find spectrum binary", 1)
            elif status == 101:
                raise RuntimeError("Exception thrown, please contact the maintainers", 1)
            elif status == 102:
                raise RuntimeError("Username does not exist", 1)
            else:
                raise RuntimeError("Child exited with unknown exit status", 1)
        else:
            exit_code = 0
            try:
                # we are the child
                try:
                    env.drop_privs(env.get_uid(), env.get_gid())
                except RuntimeError, e:
                    os._exit(102)

                    # get the absolute path of the config file
                path = os.path.abspath(self.config_path)

                # check if database is at current version:
                check_cmd = [self.get_binary(), "--check-db-version", path]
                process = subprocess.Popen(check_cmd, stdout=subprocess.PIPE)
                process.communicate()
                if process.returncode != 0:
                    os._exit(process.returncode)

                    # finally start spectrum:
                cmd = [self.get_binary()]