@commands.command_add('agentupdate')
    def update_cmd(self, data):

        if isinstance(data, basestring):
            (url, md5sum) = data.split(',', 1)
        elif isinstance(data, dict):
            try:
                url = data['url']
                md5sum = data['md5sum']
            except KeyError:
                return (500,
                        "Missing URL or MD5 sum in dictionary arguments")
        else:
            return (500, "Invalid arguments")

        try:
            local_filename = self._get_to_local_file(url, md5sum)
        except AgentUpdateError, e:
            return (500, str(e))

        ext = local_filename[local_filename.rindex('.') + 1:]

        if ext != ".tar":
            dest_filename = "%s.%s" % (
                    DEST_FILE,
                    ext)
        else:
            dest_filename = "%s"

        try:
            t = tarfile.open(local_filename, 'r:*')
        except tarfile.TarError, e:
            os.unlink(local_filename)
            return (500, "%s: %s" % (local_filename, str(e)))

        found_installer = None
        for tarinfo in t.getmembers():
            name = tarinfo.name
            while name.startswith('../') or name.startswith('./') \
                    or name.startswith('/'):
                name = name[1:]
            # Check for 'installer.sh' in root of the tar or in a
            # subdirectory off of the root
            if name == "installer.sh" or (name.count('/') == 1 and
                    name.split('/')[1] == "installer.sh"):
                found_installer = name
                break

        pipe = subprocess.PIPE

        if found_installer:
            dest_path = "%s.%d" % (DEST_PATH, os.getpid())

            try:
                t.extractall(dest_path)
                t.close()
            except tarfile.TarError, e:
                os.unlink(local_filename)
                return (500, str(e))

            os.unlink(local_filename)

            p = subprocess.Popen(["%s/%s" % (dest_path, found_installer)],
                    stdin=pipe, stdout=pipe, stderr=pipe, env={})
            p.communicate(None)
            retcode = p.returncode

            shutil.rmtree(dest_path, ignore_errors=True)

            if retcode != 0:
                return (500, "Agent installer script failed: %d" % retcode)
        else:
            #
            # Old way, no installer
            #

            t.close()

            # Using shutil.move instead of os.rename() because we might be
            # moving across filesystems.
            shutil.move(local_filename, dest_filename)

        init_script = None
        for script in INIT_SCRIPTS:
            if os.path.exists(script):
                init_script = script
                break

        if not init_script:
            return(404, "No init script found to restart")

        try:
            p = subprocess.Popen(["sh", init_script, "restart"],
                    stdin=pipe, stdout=pipe, stderr=pipe, env={})
            p.communicate(None)
            retcode = p.returncode
        except OSError, e:
            return (500, str(e) % "Couldn't restart the agent: %s")

        if retcode != 0:
            return (500, "Couldn't restart the agent: %d" % retcode)

        return (0, "")
dataset/ETHPy150Open rackerlabs/openstack-guest-agents-unix/commands/update.py/UpdateCommand.update_cmd/swapped operands of `%`