src/eric7/PipInterface/piplicenses.py

branch
eric7
changeset 9310
8ab45a4a6d96
parent 9218
71cf3979a6c9
child 9590
8fad82cb88ab
--- a/src/eric7/PipInterface/piplicenses.py	Sat Sep 03 17:16:33 2022 +0200
+++ b/src/eric7/PipInterface/piplicenses.py	Sun Sep 04 16:11:32 2022 +0200
@@ -32,6 +32,16 @@
 #
 # Copyright (c) 2022 Detlev Offenbach <detlev@die-offenbachs.de>
 #
+# Modifications:
+#   - removed dependency to prettytable
+#   - removed some not needed code
+#   - changed 'create_licenses_table' to 'create_licenses_list'
+#   - changed 'create_summary_table' to 'create_summary_list'
+#   - added 'create_summary_by_license_list' together with the
+#     '--summary-by-license' switch to count each individual
+#     license used
+#   - changed 'create_output_string' to return a JSON string
+#
 
 import argparse
 import codecs
@@ -313,6 +323,23 @@
     return licenses
 
 
+def create_summary_by_license_list(args: "CustomNamespace"):
+    licenses_list = []
+    for pkg in get_packages(args):
+        licenses_list.extend(select_license_by_source(
+            args.from_, pkg['license_classifier'], pkg['license']))
+    counts = Counter(licenses_list)
+
+    licenses = []
+    for license, count in counts.items():
+        licenses.append({
+            "Count": count,
+            "License": license,
+        })
+    
+    return licenses
+
+
 def find_license_from_classifier(message):
     licenses = []
     for k, v in message.items():
@@ -375,6 +402,8 @@
 
     if args.summary:
         licenses = create_summary_list(args)
+    elif args.summary_by_license:
+        licenses = create_summary_by_license_list(args)
     else:
         licenses = create_licenses_list(args, output_fields)
     
@@ -423,6 +452,7 @@
     from_: "FromArg"
     order: "OrderArg"
     summary: bool
+    summary_by_license: bool
     local_only: bool
     user_only:bool
     output_file: str
@@ -558,6 +588,11 @@
         default=False,
         help='dump summary of each license')
     common_options.add_argument(
+        '--summary-by-license',
+        action='store_true',
+        default=False,
+        help='dump summary of each individual license')
+    common_options.add_argument(
         '--output-file',
         action='store', type=str,
         help='save license list to file')

eric ide

mercurial