3131from rich .console import Console
3232from rich .table import Table
3333
34- from licensecheck .types import PackageInfo
34+ from licensecheck .types import License , PackageInfo , printLicense
3535
36- INFO = {"program" : "licensecheck" , "version" : "2022.2.0 " }
36+ INFO = {"program" : "licensecheck" , "version" : "2023.1.3" , "license" : "mit " }
3737
3838
3939def stripAnsi (string : str ) -> str :
@@ -48,30 +48,39 @@ def stripAnsi(string: str) -> str:
4848 return re .compile (r"\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])" ).sub ("" , string )
4949
5050
51- def ansi (packages : list [PackageInfo ]) -> str :
51+ def ansi (myLice : License , packages : list [PackageInfo ]) -> str :
5252 """Format to ansi
5353
5454 Args:
55+ myLice (License): project license
5556 packages (list[PackageInfo]): list of PackageCompats to format.
5657
5758 Returns:
5859 str: string to send to specified output in ansi format
5960 """
60- if len (packages ) == 0 :
61- return "No packages"
62-
6361 string = StringIO ()
6462
6563 console = Console (file = string , color_system = "truecolor" )
6664
65+ table = Table (title = "\n Info" )
66+ table .add_column ("Item" , style = "cyan" )
67+ table .add_column ("Value" , style = "magenta" )
68+ _ = [table .add_row (k , v ) for k , v in INFO .items ()]
69+ table .add_row ("project_license" , printLicense (myLice ))
70+
71+ console .print (table )
72+
73+ if len (packages ) == 0 :
74+ return f"{ string .getvalue ()} \n No packages"
75+
6776 errors = [x for x in packages if x .errorCode > 0 ]
6877 if len (errors ) > 0 :
69- table = Table (title = "\n list of errors " )
78+ table = Table (title = "\n List Of Errors " )
7079 table .add_column ("Package" , style = "magenta" )
7180 _ = [table .add_row (x .name ) for x in errors ]
7281 console .print (table )
7382
74- table = Table (title = "\n list of packages " )
83+ table = Table (title = "\n List Of Packages " )
7584 table .add_column ("Compatible" , style = "cyan" )
7685 table .add_column ("Package" , style = "magenta" )
7786 table .add_column ("License(s)" , style = "magenta" )
@@ -84,43 +93,48 @@ def ansi(packages: list[PackageInfo]) -> str:
8493 return string .getvalue ()
8594
8695
87- def plainText (packages : list [PackageInfo ]) -> str :
88- """Format to plain text
96+ def plainText (myLice : License , packages : list [PackageInfo ]) -> str :
97+ """Format to ansi
8998
9099 Args:
100+ myLice (License): project license
91101 packages (list[PackageInfo]): list of PackageCompats to format.
92102
93103 Returns:
94104 str: string to send to specified output in plain text format
95105 """
96- return stripAnsi (ansi (packages ))
106+ return stripAnsi (ansi (myLice , packages ))
97107
98108
99- def markdown (packages : list [PackageInfo ]) -> str :
109+ def markdown (myLice : License , packages : list [PackageInfo ]) -> str :
100110 """Format to markdown
101111
102112 Args:
113+ myLice (License): project license
103114 packages (list[PackageInfo]): list of PackageCompats to format.
104115
105116 Returns:
106117 str: string to send to specified output in markdown format
107118 """
119+ info = "\n " .join (f"- **{ k } **: { v } " for k , v in INFO .items ())
120+ strBuf = [f"## Info\n \n { info } \n \n ## Project License\n \n { printLicense (myLice )} \n " ]
121+
108122 if len (packages ) == 0 :
109- return "No packages"
123+ return f" { strBuf [ 0 ] } \n No packages"
110124
111- strBuf = [ " \n # Packages\n Find a list of packages below\n "]
125+ strBuf . append ( "## Packages\n \ n Find a list of packages below\n ")
112126 packages = sorted (packages , key = lambda i : i .name )
113127
114128 # Summary Table
115129 strBuf .append ("|Compatible|Package|\n |:--|:--|" )
116130 for pkg in packages :
117- strBuf .append (f"|{ pkg .licenseCompat } |{ pkg .name } |" )
131+ strBuf .append (f"|{ '✔' if pkg .licenseCompat else '✖' } |{ pkg .name } |" )
118132
119133 # Details
120134 for pkg in packages :
121135 strBuf .extend (
122136 [
123- f"\n ## { pkg .namever } " ,
137+ f"\n ### { pkg .namever } " ,
124138 f"\n - HomePage: { pkg .homePage } " ,
125139 f"- Author: { pkg .author } " ,
126140 f"- License: { pkg .license } " ,
@@ -131,27 +145,37 @@ def markdown(packages: list[PackageInfo]) -> str:
131145 return "\n " .join (strBuf ) + "\n "
132146
133147
134- def raw (packages : list [PackageInfo ]) -> str :
135- """Format to raw json
148+ def raw (myLice : License , packages : list [PackageInfo ]) -> str :
149+ """Format to json
136150
137151 Args:
152+ myLice (License): project license
138153 packages (list[PackageInfo]): list of PackageCompats to format.
139154
140155 Returns:
141156 str: string to send to specified output in raw json format
142157 """
143- return json .dumps ({"info" : INFO , "packages" : [x .__dict__ for x in packages ]}, indent = "\t " )
158+ return json .dumps (
159+ {
160+ "info" : INFO ,
161+ "project_license" : printLicense (myLice ),
162+ "packages" : [x .__dict__ for x in packages ],
163+ },
164+ indent = "\t " ,
165+ )
144166
145167
146- def rawCsv (packages : list [PackageInfo ]) -> str :
147- """Format to raw csv
168+ def rawCsv (myLice : License , packages : list [PackageInfo ]) -> str :
169+ """Format to csv
148170
149171 Args:
172+ myLice (License): project license
150173 packages (list[PackageInfo]): list of PackageCompats to format.
151174
152175 Returns:
153176 str: string to send to specified output in raw csv format
154177 """
178+ _ = myLice
155179 string = StringIO ()
156180 writer = csv .DictWriter (string , fieldnames = list (packages [0 ].__dict__ ), lineterminator = "\n " )
157181 writer .writeheader ()
0 commit comments