1
- #!/bin/python3
1
+ #!/usr/ bin/env python3
2
2
# -*- coding: utf-8 -*-
3
3
4
+ r""" Package initialization for `core`.
5
+
6
+ This module initializes the `core` package by defining essential functions and variables,
7
+ such as `get_config()` for loading configurations and `initialize_logger()` for setting up logging.
8
+ It ensures that the core components are ready for use when the package is imported.
9
+
10
+ Constants:
11
+ - INFO: Contains application information such as version, git commit hash, and other metadata.
12
+ - REGEX_ARGS: A regular expression pattern used to parse and split argument strings into lists.
13
+ - UNITS: Units of measurement for bytes, including KB, MB, GB, TB, etc., to facilitate size conversions.
14
+
15
+ """
16
+
4
17
from time import sleep
5
18
from traceback import format_exc
6
19
10
23
from core .tool import Tool
11
24
12
25
INFO = dict [str , str ]({
26
+ "author" : "Florian Cardinal" ,
27
+ "github" : "https://github.com/Tracks12/toolsManager.py" ,
13
28
"name" : "toolsManager.py" ,
14
- "version" : "0.1"
29
+ "version" : "0.2" ,
15
30
})
16
31
17
32
REGEX_ARGS = str ("\\ s(?=(?:[^\" '`]*[\" '`][^\" '`]*[\" '`])*[^\" '`]*$)" )
18
33
UNITS = tuple [str ](("o" , "ko" , "Mo" , "Go" , "To" ))
19
34
20
35
def helper (commands : tuple ) -> None :
21
36
colors = tuple [str ]((Colors .cyan , Colors .yellow , Colors .red ))
22
- screen = list [str ]([ " List of commands:\n " ])
37
+ screen = list [str ]([ "List of commands:\n " ])
23
38
24
39
for i , command in enumerate (commands ):
25
40
c = int (1 if (i in range ((len (commands )- 4 ), (len (commands )- 1 ))) else 0 )
26
41
c = int (2 if (i in range ((len (commands )- 1 ), (len (commands )))) else c )
27
42
sep = str ('\n ' if (i in (len (commands )- 5 , len (commands )- 2 )) else '' )
28
43
29
- command = str (f" { colors [c ]} { command [1 ]} { Colors .end } { sep } " )
44
+ command = str (f"{ colors [c ]} { command [1 ]} { Colors .end } { sep } " )
30
45
31
46
screen .append (command )
32
47
33
- print (("\n " ).join (screen ), end = "\n \n " )
48
+ print (("\n " ).join ([ f" { s } " for s in screen ] ), end = "\n \n " )
34
49
35
50
def launch (tool : Tool , args : list [str ]) -> bool :
36
51
try :
37
52
print (f'{ Icons .play } Starting "{ tool .name } " ...' )
38
53
tool (args )
39
-
40
- except Exception :
41
- print (f"{ Icons .warn } { format_exc ()} " )
54
+
55
+ except ( Exception ) :
56
+ print (f"{ Icons .err } { format_exc ()} " )
42
57
43
58
finally :
44
59
print ()
45
60
return (True )
46
61
47
62
def sortTools (tools : list [Tool ]) -> list [Tool ]:
48
- print ( f" \n { ' ' * 1 } * Name{ ' ' * (12 - len ('Name' ))} Command{ ' ' * (16 - len ('Command' ))} Path" )
63
+ table = list [ str ]([ f" * Name{ ' ' * (14 - len ('Name' ))} Command{ ' ' * (16 - len ('Command' ))} Path" ] )
49
64
for i , tool in enumerate (tools , start = 1 ):
50
- print (f" { ' ' * (2 - len (str (i )))} { i } . { tool .name } { ' ' * (12 - len (tool .name ))} { tool .command [1 ]} { ' ' * (16 - len (tool .command [1 ]))} { tool .path } " , end = " \n " * ( 2 if ( i == len ( tools )) else 1 ) )
65
+ table . append (f"{ ' ' * (2 - len (str (i )))} { Colors . green } { i } { Colors . end } . { tool .name } { ' ' * (14 - len (tool .name ))} { Colors . cyan } { tool .command [1 ]} { Colors . end } { ' ' * (16 - len (tool .command [1 ]))} { Colors . yellow } { tool .path } { Colors . end } " )
51
66
67
+ print (f"\n { '\n ' .join ([f" { t } " for t in table ])} " , end = "\n " * 2 )
52
68
return (tools )
53
69
54
70
def splash (spacing : int = 2 ) -> None :
@@ -64,6 +80,17 @@ def splash(spacing: int = 2) -> None:
64
80
print (f"{ ' ' * spacing } { row } " , end = "\n " * (2 if (i == 6 ) else 1 ))
65
81
sleep (.025 )
66
82
83
+ def stringSize (size : int ) -> str :
84
+ size = [size , UNITS [0 ]]
85
+
86
+ for i in range (1 , len (UNITS )):
87
+ size [0 ] /= 1000
88
+ size [1 ] = UNITS [i ]
89
+ if (size [0 ] < 1024 ):
90
+ break
91
+
92
+ return (f"{ round (size [0 ], 2 )} { size [1 ]} " )
93
+
67
94
def version () -> dict [str , str ]:
68
95
print (f" { INFO ['name' ]} { INFO ['version' ]} " , end = "\n " * 2 )
69
96
return (INFO )
0 commit comments