Having a code style makes the code easier to read.

As for which code style to use, the code style defined by the
PEP 8 [1] is used in the python standard library and in the main
Python distribution.

Its official nature (it's standardized by python) probably makes it
the most well known and used code style adopted by python programmers.

In it we have a section about string quotes:
    String Quotes
    -------------
    In Python, single-quoted strings and double-quoted strings are the
    same. This PEP does not make a recommendation for this. Pick a rule
    and stick to it. When a string contains single or double quote
    characters, however, use the other one to avoid backslashes in the
    string. It improves readability.

    For triple-quoted strings, always use double quote characters to be
    consistent with the docstring convention in PEP 257.

Since "if __name__ == '__main__':" is widely used, we choose to use the
single quotes.

[1]https://www.python.org/dev/peps/pep-0008/

Signed-off-by: Denis 'GNUtoo' Carikli <gnu...@cyberdimension.org>
---
 samsung-ipc/tests/libsamsung-ipc-test.py |  6 +--
 tools/ipc-modem.py                       | 14 +++---
 tools/nv_data-imei.py                    | 58 ++++++++++++------------
 tools/nv_data-md5.py                     | 10 ++--
 4 files changed, 44 insertions(+), 44 deletions(-)

diff --git a/samsung-ipc/tests/libsamsung-ipc-test.py 
b/samsung-ipc/tests/libsamsung-ipc-test.py
index 328f4f0..7e819aa 100755
--- a/samsung-ipc/tests/libsamsung-ipc-test.py
+++ b/samsung-ipc/tests/libsamsung-ipc-test.py
@@ -30,10 +30,10 @@ class libsamsung_ipc_test(object):
         if not srcdir:
             srcdir = os.path.dirname(sys.argv[0])
 
-        self.run = sh.Command(srcdir + os.sep + "libsamsung-ipc-test")
+        self.run = sh.Command(srcdir + os.sep + 'libsamsung-ipc-test')
 
     def run_all_tests(self):
-        output = str(self.run("list-tests")).split(os.linesep)
+        output = str(self.run('list-tests')).split(os.linesep)
         # Remove the last line break from the output
         output.remove('')
 
@@ -44,7 +44,7 @@ class libsamsung_ipc_test(object):
         output.pop(0)
 
         for test_name in output:
-            self.run("test", test_name.replace(' ', ''))
+            self.run('test', test_name.replace(' ', ''))
 
 def main():
     tests = libsamsung_ipc_test()
diff --git a/tools/ipc-modem.py b/tools/ipc-modem.py
index b1d28b4..0fcd1fc 100755
--- a/tools/ipc-modem.py
+++ b/tools/ipc-modem.py
@@ -23,11 +23,11 @@ import sys
 import sh
 
 def usage(progname):
-    print("{} [test]".format(progname))
+    print('{} [test]'.format(progname))
     sys.exit(1)
 
 def get_output(data):
-    return str(data).replace(os.linesep, "")
+    return str(data).replace(os.linesep, '')
 
 class IpcModem(object):
     def __init__(self):
@@ -36,7 +36,7 @@ class IpcModem(object):
         if not srcdir:
             srcdir = os.path.dirname(sys.argv[0])
 
-        ipc_modem = sh.Command(srcdir + os.sep + "ipc-modem")
+        ipc_modem = sh.Command(srcdir + os.sep + 'ipc-modem')
         self.ipc_modem = ipc_modem.bake('--dry-run')
 
     def test_help(self):
@@ -48,17 +48,17 @@ class IpcModem(object):
             raise Exception()
 
     def test_boot(self, timeout=2):
-        self.ipc_modem("boot",  _timeout=timeout)
+        self.ipc_modem('boot',  _timeout=timeout)
 
     def test_power_on(self, timeout=2):
-        self.ipc_modem("power-on",  _timeout=timeout)
+        self.ipc_modem('power-on',  _timeout=timeout)
 
     def test_power_off(self, timeout=2):
-        self.ipc_modem("power-off", _timeout=timeout)
+        self.ipc_modem('power-off', _timeout=timeout)
 
     def test_start(self, timeout=3):
         try:
-            self.ipc_modem("start",  _timeout=timeout)
+            self.ipc_modem('start',  _timeout=timeout)
         except sh.TimeoutException:
             pass
         else:
diff --git a/tools/nv_data-imei.py b/tools/nv_data-imei.py
index da58a50..dbe9cfb 100755
--- a/tools/nv_data-imei.py
+++ b/tools/nv_data-imei.py
@@ -30,18 +30,18 @@ class SysExit(object):
     EX_NOINPUT = sh.ErrorReturnCode_66
 
 def usage(progname):
-    print("{} [test]".format(progname))
+    print('{} [test]'.format(progname))
     sys.exit(1)
 
 commands = [
-    "list-supported",
-    "read-imei",
-    "write-imei",
-    "bruteforce-imei",
+    'list-supported',
+    'read-imei',
+    'write-imei',
+    'bruteforce-imei',
 ]
 
 def get_output(data):
-    return str(data).replace(os.linesep, "")
+    return str(data).replace(os.linesep, '')
 
 class NvDataImei(object):
     def __init__(self):
@@ -50,64 +50,64 @@ class NvDataImei(object):
         if not srcdir:
             srcdir = os.path.dirname(sys.argv[0])
 
-        self.nv_data_imei = sh.Command(srcdir + os.sep + "nv_data-imei")
+        self.nv_data_imei = sh.Command(srcdir + os.sep + 'nv_data-imei')
     def test_help(self):
         try:
-            self.nv_data_imei("")
+            self.nv_data_imei('')
         except SysExit.EX_USAGE:
             pass
         else:
             raise Exception()
 
-        for help_arg in ["-h", "--help"]:
+        for help_arg in ['-h', '--help']:
             self.nv_data_imei(help_arg)
             for command in commands:
                 self.nv_data_imei(command, help_arg)
                 try:
-                    self.nv_data_imei("file", command, help_arg)
+                    self.nv_data_imei('file', command, help_arg)
                 except SysExit.EX_USAGE:
                     pass
                 else:
                     raise Exception()
 
-        self.nv_data_imei("list-supported")
+        self.nv_data_imei('list-supported')
 
     def test_commands(self):
         # Create nv_data.bin
-        valid_imei = "123456789012345"
+        valid_imei = '123456789012345'
         offset = 0x100
         XMM616_NV_DATA_SIZE = 0x200000
         nv_data_bin = get_output(sh.mktemp())
-        sh.ddrescue("/dev/zero", nv_data_bin, "-s", str(XMM616_NV_DATA_SIZE))
+        sh.ddrescue('/dev/zero', nv_data_bin, '-s', str(XMM616_NV_DATA_SIZE))
 
-        self.nv_data_imei(nv_data_bin, "write-imei", "-o", str(hex(offset)),
-                          "-i", valid_imei)
-        output = get_output(self.nv_data_imei(nv_data_bin, "read-imei", "-o",
+        self.nv_data_imei(nv_data_bin, 'write-imei', '-o', str(hex(offset)),
+                          '-i', valid_imei)
+        output = get_output(self.nv_data_imei(nv_data_bin, 'read-imei', '-o',
                                               str(hex(offset))))
         print(output)
-        expect = "IMEI: " + valid_imei
+        expect = 'IMEI: ' + valid_imei
         if output != expect:
             raise Exception()
 
-        output = get_output(self.nv_data_imei(nv_data_bin, "bruteforce-imei",
-                                              "-i", valid_imei))
+        output = get_output(self.nv_data_imei(nv_data_bin, 'bruteforce-imei',
+                                              '-i', valid_imei))
         print(output)
-        expect = re.escape("Found IMEI at {} ({})".format(str(hex(offset)),
+        expect = re.escape('Found IMEI at {} ({})'.format(str(hex(offset)),
                                                           offset))
         if not re.search(expect, output):
             raise Exception()
 
-        inaccessible_nv_data_bin = str(sh.mktemp("-u")).replace(os.linesep,"")
-        sh.ddrescue("/dev/zero", inaccessible_nv_data_bin, "-s",
+        inaccessible_nv_data_bin = str(sh.mktemp('-u')).replace(os.linesep,'')
+        sh.ddrescue('/dev/zero', inaccessible_nv_data_bin, '-s',
                     str(XMM616_NV_DATA_SIZE))
-        sh.chmod("000", inaccessible_nv_data_bin);
+        sh.chmod('000', inaccessible_nv_data_bin);
         try:
-            self.nv_data_imei(inaccessible_nv_data_bin, "write-imei",
-                              "-o", "0x0", "-i", valid_imei)
-            self.nv_data_imei(inaccessible_nv_data_bin, "read-imei",
-                              "-o", "0x0")
-            self.nv_data_imei(inaccessible_nv_data_bin, "bruteforce-imei",
-                              "-i", valid_imei)
+            self.nv_data_imei(inaccessible_nv_data_bin, 'write-imei',
+                              '-o', '0x0', '-i', valid_imei)
+            self.nv_data_imei(inaccessible_nv_data_bin, 'read-imei',
+                              '-o', '0x0')
+            self.nv_data_imei(inaccessible_nv_data_bin, 'bruteforce-imei',
+                              '-i', valid_imei)
         except SysExit.EX_NOINPUT:
             pass
         else:
diff --git a/tools/nv_data-md5.py b/tools/nv_data-md5.py
index 2897f18..2dc98ab 100755
--- a/tools/nv_data-md5.py
+++ b/tools/nv_data-md5.py
@@ -23,11 +23,11 @@ import sys
 import sh
 
 def usage(progname):
-    print("{} [test]".format(progname))
+    print('{} [test]'.format(progname))
     sys.exit(1)
 
 def get_output(data):
-    return str(data).replace(os.linesep, "")
+    return str(data).replace(os.linesep, '')
 
 class NvDataMD5(object):
     def __init__(self):
@@ -36,7 +36,7 @@ class NvDataMD5(object):
         if not srcdir:
             srcdir = os.path.dirname(sys.argv[0])
 
-        self.nv_data_md5 = sh.Command(srcdir + os.sep + "nv_data-md5")
+        self.nv_data_md5 = sh.Command(srcdir + os.sep + 'nv_data-md5')
     def test_help(self):
         try:
             self.nv_data_md5()
@@ -46,12 +46,12 @@ class NvDataMD5(object):
             raise Exception()
 
     def test_commands(self):
-        expected_md5 = "5293814414abb3831e3fc1a1b35e69bc"
+        expected_md5 = '5293814414abb3831e3fc1a1b35e69bc'
         NV_DATA_SIZE = 0x200000
         nv_data_bin = get_output(sh.mktemp())
 
         # Create nv_data.bin
-        sh.ddrescue("/dev/zero", nv_data_bin, "-s", str(NV_DATA_SIZE))
+        sh.ddrescue('/dev/zero', nv_data_bin, '-s', str(NV_DATA_SIZE))
 
         output = get_output(self.nv_data_md5(nv_data_bin))
 
-- 
2.34.1

_______________________________________________
Replicant mailing list
Replicant@osuosl.org
https://lists.osuosl.org/mailman/listinfo/replicant

Reply via email to