Skip to content

Commit e093253

Browse files
committed
black code style
1 parent 31b0b50 commit e093253

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ help:
1111
@echo - make venv ------- Create virtual environment
1212

1313
black:
14-
black -S cstruct tests setup.py
14+
black -S cstruct tests examples setup.py
1515

1616
clean:
1717
-rm -rf build dist

examples/fdisk.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
3-
#*****************************************************************************
3+
# *****************************************************************************
44
#
55
# Copyright (c) 2013 Andrea Bonomi <andrea.bonomi@gmail.com>
66
#
@@ -24,20 +24,22 @@
2424
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
2525
# IN THE SOFTWARE.
2626
#
27-
#*****************************************************************************
27+
# *****************************************************************************
2828

2929
import cstruct
3030
import sys
3131

32-
class Position(cstruct.CStruct):
32+
33+
class Position(cstruct.MemCStruct):
3334
__byte_order__ = cstruct.LITTLE_ENDIAN
3435
__struct__ = """
3536
unsigned char head;
3637
unsigned char sector;
3738
unsigned char cyl;
3839
"""
3940

40-
class Partition(cstruct.CStruct):
41+
42+
class Partition(cstruct.MemCStruct):
4143
__byte_order__ = cstruct.LITTLE_ENDIAN
4244
__struct__ = """
4345
unsigned char status; /* 0x80 - active */
@@ -56,7 +58,8 @@ def print_info(self):
5658
print("starting sector: %08X" % self.start_sect)
5759
print("size MB: %s" % (self.sectors / 2 / 1024))
5860

59-
class MBR(cstruct.CStruct):
61+
62+
class MBR(cstruct.MemCStruct):
6063
__byte_order__ = cstruct.LITTLE_ENDIAN
6164
__struct__ = """
6265
char unused[440];
@@ -74,6 +77,7 @@ def print_info(self):
7477
print("partition: %s" % i)
7578
partition.print_info()
7679

80+
7781
def main():
7882
if len(sys.argv) != 2:
7983
print("usage: %s disk" % sys.argv[0])
@@ -84,6 +88,6 @@ def main():
8488
mbr.unpack(data)
8589
mbr.print_info()
8690

87-
if __name__ == "__main__":
88-
main()
8991

92+
if __name__ == "__main__":
93+
main()

examples/who.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
3-
#*****************************************************************************
3+
# *****************************************************************************
44
#
55
# Copyright (c) 2013 Andrea Bonomi <andrea.bonomi@gmail.com>
66
#
@@ -24,7 +24,7 @@
2424
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
2525
# IN THE SOFTWARE.
2626
#
27-
#*****************************************************************************
27+
# *****************************************************************************
2828

2929
# pts/1 2013-06-06 18:09 23120 id=ts/1 term=0 exit=0
3030
# system boot 2013-05-20 21:27
@@ -45,7 +45,7 @@
4545
# pts/30 2013-07-24 14:40 19054 id=s/30 term=0 exit=0
4646
# pts/28 2013-07-30 20:49 24942 id=s/28 term=0 exit=0
4747
# pts/27 2013-08-02 17:59 31326 id=s/27 term=0 exit=0
48-
#012345678901234567890123456789012345678901234567890123456789012345678901234567890
48+
# 012345678901234567890123456789012345678901234567890123456789012345678901234567890
4949
from cstruct import define, typedef, MemCStruct, NATIVE_ORDER
5050
import sys
5151
import time
@@ -57,21 +57,26 @@
5757
typedef("int", "pid_t")
5858
typedef("long", "time_t")
5959

60+
6061
class ExitStatus(MemCStruct):
6162
__struct__ = """
6263
short e_termination; /* Process termination status. */
6364
short e_exit; /* Process exit status. */
6465
"""
66+
67+
6568
class Timeval(MemCStruct):
6669
__struct__ = """
6770
int32_t tv_sec; /* Seconds. */
6871
int32_t tv_usec; /* Microseconds. */
6972
"""
7073

74+
7175
def str_from_c(string):
72-
#return str(string.split("\0")[0])
76+
# return str(string.split("\0")[0])
7377
return string.decode().split("\0")[0]
7478

79+
7580
class Utmp(MemCStruct):
7681
__byte_order__ = NATIVE_ORDER
7782
__struct__ = """
@@ -94,13 +99,22 @@ class Utmp(MemCStruct):
9499
def print_info(self, all_):
95100
"andreax + pts/0 2013-08-21 08:58 . 32341 (l26.box)"
96101
" pts/34 2013-06-12 15:04 26396 id=s/34 term=0 exit=0"
97-
if all_ or self.ut_type in [6,7]:
98-
print("%-10s %-12s %15s %15s %-8s" % (
102+
if all_ or self.ut_type in [6, 7]:
103+
print(
104+
"%-10s %-12s %15s %15s %-8s"
105+
% (
99106
str_from_c(self.ut_user),
100107
str_from_c(self.ut_line),
101108
time.strftime("%Y-%m-%d %H:%M", time.gmtime(self.ut_tv.tv_sec)),
102109
self.ut_pid,
103-
str_from_c(self.ut_host) and "(%s)" % str_from_c(self.ut_host) or str_from_c(self.ut_id) and "id=%s" % str_from_c(self.ut_id) or ""))
110+
str_from_c(self.ut_host)
111+
and "(%s)" % str_from_c(self.ut_host)
112+
or str_from_c(self.ut_id)
113+
and "id=%s" % str_from_c(self.ut_id)
114+
or "",
115+
)
116+
)
117+
104118

105119
def main():
106120
utmp = len(sys.argv) > 1 and sys.argv[1] or "/var/run/utmp"
@@ -110,6 +124,6 @@ def main():
110124
while utmp.unpack(f):
111125
utmp.print_info(all_)
112126

127+
113128
if __name__ == "__main__":
114129
main()
115-

0 commit comments

Comments
 (0)