1
- class BugCounter ():
1
+ class BugCounter :
2
+ """Class to count the number of bugs in bugs.md file and update the number
3
+ of bugs, confirmed and fixed bugs in the file.
4
+ """
5
+
2
6
def __init__ (self ):
3
7
self .num_bugs = 0
4
8
self .num_confirmed = 0
@@ -7,38 +11,54 @@ def __init__(self):
7
11
self .num_by_confirmed = 0
8
12
self .num_by_fixed = 0
9
13
self .by_flag = False
10
-
11
- def read_file (self , path : str ) -> list :
12
- with open (path , 'r' ) as f :
14
+
15
+ def read_file (self , path : str ) -> list [str ]:
16
+ """Read the file and return the data as a list of strings."""
17
+ with open (path , "r" , encoding = "utf-8" ) as f :
13
18
data = f .readlines ()
14
19
return data
15
-
20
+
16
21
def write_data (self , data : list , path : str ):
17
- with open (path , 'w' ) as f :
22
+ """Write the data to the file."""
23
+ with open (path , "w" , encoding = "utf-8" ) as f :
18
24
f .writelines (data )
19
-
20
- def update_number (self ) -> list :
21
- data = self .read_file ('./bugs.md' )
25
+
26
+ def update_number (self ):
27
+ """Update the number of bugs, confirmed and fixed bugs in the file."""
28
+ data = self .read_file ("./bugs.md" )
22
29
for line in data :
23
- if ' # Byproduct bugs' in line :
30
+ if " # Byproduct bugs" in line :
24
31
self .by_flag = True
25
32
if not self .by_flag :
26
- self .num_bugs += line .count ('](' )
27
- self .num_confirmed += line .count (' confirmed' )
28
- self .num_fixed += line .count (' fixed' )
33
+ self .num_bugs += line .count ("](" )
34
+ self .num_confirmed += line .count (" confirmed" )
35
+ self .num_fixed += line .count (" fixed" )
29
36
else :
30
- self .num_by_bugs += line .count ('](' )
31
- self .num_by_confirmed += line .count (' confirmed' )
32
- self .num_by_fixed += line .count (' fixed' )
33
-
37
+ self .num_by_bugs += line .count ("](" )
38
+ self .num_by_confirmed += line .count (" confirmed" )
39
+ self .num_by_fixed += line .count (" fixed" )
40
+
34
41
self .num_confirmed += self .num_fixed
35
42
self .num_by_confirmed += self .num_by_fixed
36
- if '(Byproduct bugs included)' not in data [1 ]:
37
- raise Exception ("The first line of bugs.md should start with '(Byproduct bugs included)'" )
38
- data [1 ] = '(Byproduct bugs included) Total bugs: **{}**, confirmed: **{}**, Fixed: **{}**.<br/>\n ' .format (self .num_bugs + self .num_by_bugs , self .num_confirmed + self .num_by_confirmed , self .num_fixed + self .num_by_fixed )
39
- data [3 ] = '(Byproduct bugs excluded) Total bugs: **{}**, confirmed: **{}**, Fixed: **{}**.<br/>\n ' .format (self .num_bugs , self .num_confirmed , self .num_fixed )
40
- self .write_data (data , './bugs.md' )
41
-
42
- if __name__ == '__main__' :
43
+ if not data [2 ].startswith ("(Byproduct bugs included)" ):
44
+ raise RuntimeError (
45
+ "The first line of bugs.md should start with '(Byproduct bugs included)'"
46
+ )
47
+ data [2 ] = (
48
+ "(Byproduct bugs included) "
49
+ f"Total bugs: **{ self .num_bugs + self .num_by_bugs } **, "
50
+ f"confirmed: **{ self .num_confirmed + self .num_by_confirmed } **, "
51
+ f"Fixed: **{ self .num_fixed + self .num_by_fixed } **.<br/>\n "
52
+ )
53
+ data [4 ] = (
54
+ f"(Byproduct bugs excluded) "
55
+ f"Total bugs: **{ self .num_bugs } **, "
56
+ f"confirmed: **{ self .num_confirmed } **, "
57
+ f"Fixed: **{ self .num_fixed } **.<br/>\n "
58
+ )
59
+ self .write_data (data , "./bugs.md" )
60
+
61
+
62
+ if __name__ == "__main__" :
43
63
bug_counter = BugCounter ()
44
64
bug_counter .update_number ()
0 commit comments