OSDir


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Python-Dev] SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python


Dear Python Experts Team,

As am newbie to python development, I am trying to use the below function
to get verify the filesystem type of the SD card parition using bash
command in python using subprocess module, I ma seeing the below Error
"SyntaxError: can't assign to literal"

*CODE:*
*====*

import helper
from os import path
import subprocess
import os
import otg_ni


class emmc(object):
    """
        emmc getters and setters
        info:
https://www.kernel.org/doc/Documentation/cpu-freq/user-guide.txt
    """

    def __init__(self):
        self._helper = helper.helper()
        self._otg_ni = otg_ni.otg_ni()


*def get_fstype_of_mounted_partition(self, fs):*
        """
            Get the filesystem type of the mounted partition.

            :partition_name : Partition path as string (e.g. /dev/mmcblk0p1)
            :return: filesystem type as string or None if not found
        """

*        cmd = "blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)*
        *return self._helper.execute_cmd_output_string(cmd)*



*def execute_cmd_output_string(self, cmd, enable_shell=False):*
        """
            Execute a command and return its output as a string.

            :param cmd: abs path of the command with arguments
            :param enable_shell : force the cmd to be run as shell script
            :return: a string.
        """

        try:
            result = subprocess.check_output(split(cmd),
                                             stderr=subprocess.STDOUT,
                                             shell=enable_shell)

        except subprocess.CalledProcessError as e:
            s = """While executing '{}' something went wrong.
                Return code == '{}'
                Return output:\n'{}'
                """.format(cmd, e.returncode, e.output, shell=enable_shell)
            raise AssertionError(s)

        return result.strip().decode("utf-8")
*if __name__ == "__main__":*
    m = emmc()
*    m.get_fstype_of_mounted_partition("/dev/mmcblk0p1")*
*Error:*
*======*

root:~/qa/test_library# python3 sd.py
  File "sd.py", line 99
*    cmd = "blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)*
*         ^*
*SyntaxError: can't assign to literal*
root:~/qa/test_library#

Kindly do the needful as early as possible, as am stuck with this issue
from past 2 days no clues yet, please redirect me to the correct forum if
this is not the right place for pasting python related queries

Many Thanks in advance,
Srini
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20181106/5c4b2d58/attachment.html>