@@ -90,7 +90,8 @@ class bcolors:
9090 BOLD = bold
9191 UNDERLINE = underline
9292
93- def get_args (* args ):
93+ @staticmethod
94+ def get_args (* args : Any ) -> str :
9495 text = ""
9596 for item in args :
9697 if item is None :
@@ -99,43 +100,50 @@ def get_args(*args):
99100 return text
100101 #end define
101102
102- def magenta_text (* args ):
103+ @staticmethod
104+ def magenta_text (* args : Any ) -> str :
103105 text = bcolors .get_args (* args )
104106 text = bcolors .magenta + text + bcolors .endc
105107 return text
106108 #end define
107109
108- def blue_text (* args ):
110+ @staticmethod
111+ def blue_text (* args : Any ) -> str :
109112 text = bcolors .get_args (* args )
110113 text = bcolors .blue + text + bcolors .endc
111114 return text
112115 #end define
113116
114- def green_text (* args ):
117+ @staticmethod
118+ def green_text (* args : Any ) -> str :
115119 text = bcolors .get_args (* args )
116120 text = bcolors .green + text + bcolors .endc
117121 return text
118122 #end define
119123
120- def yellow_text (* args ):
124+ @staticmethod
125+ def yellow_text (* args : Any ) -> str :
121126 text = bcolors .get_args (* args )
122127 text = bcolors .yellow + text + bcolors .endc
123128 return text
124129 #end define
125130
126- def red_text (* args ):
131+ @staticmethod
132+ def red_text (* args : Any ) -> str :
127133 text = bcolors .get_args (* args )
128134 text = bcolors .red + text + bcolors .endc
129135 return text
130136 #end define
131137
132- def bold_text (* args ):
138+ @staticmethod
139+ def bold_text (* args : Any ) -> str :
133140 text = bcolors .get_args (* args )
134141 text = bcolors .bold + text + bcolors .endc
135142 return text
136143 #end define
137144
138- def underline_text (* args ):
145+ @staticmethod
146+ def underline_text (* args : Any ) -> str :
139147 text = bcolors .get_args (* args )
140148 text = bcolors .underline + text + bcolors .endc
141149 return text
@@ -725,9 +733,9 @@ def start_cycle(self, func: Callback, sec: float, args: Sequence[Any] | None = N
725733 def init_translator (self , file_path : str | None = None ) -> None :
726734 if file_path is None :
727735 file_path = self .db .translate_file_path
728- file = open ( file_path , encoding = "utf-8" )
729- text = file . read ()
730- file .close ()
736+ assert file_path is not None
737+ with open ( file_path , encoding = "utf-8" ) as file :
738+ text = file .read ()
731739 self .translate_dict = json .loads (text )
732740 #end define
733741
@@ -769,15 +777,6 @@ def parse(text: str | None, search: str | None, search2: str | None = None) -> s
769777 return text
770778#end define
771779
772- def ping (hostname : str ) -> bool :
773- process = subprocess .run (["ping" , "-c" , 1 , "-w" , 3 , hostname ], stdout = subprocess .DEVNULL , stderr = subprocess .DEVNULL )
774- if process .returncode == 0 :
775- result = True
776- else :
777- result = False
778- return result
779- #end define
780-
781780def get_request (url : str ) -> str :
782781 link = urlopen (url )
783782 data = link .read ()
@@ -875,18 +874,14 @@ def get_load_avg() -> list[float]:
875874 if m :
876875 loadavg_arr = [m .group (1 ), m .group (2 ), m .group (3 )]
877876 else :
878- loadavg_arr = [0.00 , 0.00 , 0.00 ]
877+ loadavg_arr = [" 0.00" , " 0.00" , " 0.00" ]
879878 else :
880879 file = open ("/proc/loadavg" )
881880 loadavg = file .read ()
882881 file .close ()
883882 loadavg_arr = loadavg .split (' ' )
884883
885- output = loadavg_arr [:3 ]
886- for i in range (len (output )):
887- output [i ] = float (output [i ])
888- return output
889- #end define
884+ return [float (item ) for item in loadavg_arr [:3 ]]
890885
891886def get_internet_interface_name () -> str :
892887 if platform .system () == "OpenBSD" :
@@ -927,6 +922,7 @@ def timeago(timestamp: int | date_time_library.datetime | Literal[False] = False
927922 'just now', etc
928923 """
929924 now = date_time_library .datetime .now ()
925+ diff = date_time_library .timedelta (0 )
930926 if type (timestamp ) is int :
931927 diff = now - date_time_library .datetime .fromtimestamp (timestamp )
932928 elif isinstance (timestamp , date_time_library .datetime ):
@@ -1217,7 +1213,7 @@ def get_git_branch(git_path: str) -> str | None:
12171213 output = process .stdout .decode ("utf-8" )
12181214 err = process .stderr .decode ("utf-8" )
12191215 if len (err ) > 0 :
1220- return
1216+ return None
12211217 lines = output .split ('\n ' )
12221218 branch = None
12231219 for line in lines :
@@ -1230,6 +1226,8 @@ def get_git_branch(git_path: str) -> str | None:
12301226
12311227def check_git_update (git_path : str ) -> bool | None :
12321228 branch = get_git_branch (git_path )
1229+ if branch is None :
1230+ return None
12331231 new_hash = get_git_last_remote_commit (git_path , branch )
12341232 old_hash = get_git_hash (git_path )
12351233 result = False
@@ -1255,14 +1253,3 @@ def write_config_to_file(config_path: str, data: Mapping[str, Any]) -> None:
12551253 file .write (text )
12561254 file .close ()
12571255#end define
1258-
1259- def get_own_ip () -> str :
1260- pat = re .compile (r"^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)(\.(?!$)|$)){4}$" )
1261- requests .packages .urllib3 .util .connection .HAS_IPV6 = False
1262- ip = requests .get ("https://ifconfig.me/ip" ).text
1263- if not pat .fullmatch (ip ):
1264- ip = requests .get ("https://ipinfo.io/ip" ).text
1265- if not pat .fullmatch (ip ):
1266- raise Exception ('Cannot get own IP address' )
1267- return ip
1268- #end define
0 commit comments