src/eric7/PipInterface/piplicenses.py

branch
eric7
changeset 9310
8ab45a4a6d96
parent 9218
71cf3979a6c9
child 9590
8fad82cb88ab
equal deleted inserted replaced
9309:60ee3f038f52 9310:8ab45a4a6d96
29 29
30 # 30 #
31 # Modified to be used within the eric-ide project. 31 # Modified to be used within the eric-ide project.
32 # 32 #
33 # Copyright (c) 2022 Detlev Offenbach <detlev@die-offenbachs.de> 33 # Copyright (c) 2022 Detlev Offenbach <detlev@die-offenbachs.de>
34 #
35 # Modifications:
36 # - removed dependency to prettytable
37 # - removed some not needed code
38 # - changed 'create_licenses_table' to 'create_licenses_list'
39 # - changed 'create_summary_table' to 'create_summary_list'
40 # - added 'create_summary_by_license_list' together with the
41 # '--summary-by-license' switch to count each individual
42 # license used
43 # - changed 'create_output_string' to return a JSON string
34 # 44 #
35 45
36 import argparse 46 import argparse
37 import codecs 47 import codecs
38 import glob 48 import glob
311 }) 321 })
312 322
313 return licenses 323 return licenses
314 324
315 325
326 def create_summary_by_license_list(args: "CustomNamespace"):
327 licenses_list = []
328 for pkg in get_packages(args):
329 licenses_list.extend(select_license_by_source(
330 args.from_, pkg['license_classifier'], pkg['license']))
331 counts = Counter(licenses_list)
332
333 licenses = []
334 for license, count in counts.items():
335 licenses.append({
336 "Count": count,
337 "License": license,
338 })
339
340 return licenses
341
342
316 def find_license_from_classifier(message): 343 def find_license_from_classifier(message):
317 licenses = [] 344 licenses = []
318 for k, v in message.items(): 345 for k, v in message.items():
319 if k == 'Classifier' and v.startswith('License'): 346 if k == 'Classifier' and v.startswith('License'):
320 license = v.split(' :: ')[-1] 347 license = v.split(' :: ')[-1]
373 def create_output_string(args: "CustomNamespace"): 400 def create_output_string(args: "CustomNamespace"):
374 output_fields = get_output_fields(args) 401 output_fields = get_output_fields(args)
375 402
376 if args.summary: 403 if args.summary:
377 licenses = create_summary_list(args) 404 licenses = create_summary_list(args)
405 elif args.summary_by_license:
406 licenses = create_summary_by_license_list(args)
378 else: 407 else:
379 licenses = create_licenses_list(args, output_fields) 408 licenses = create_licenses_list(args, output_fields)
380 409
381 return json.dumps(licenses) 410 return json.dumps(licenses)
382 411
421 450
422 class CustomNamespace(argparse.Namespace): 451 class CustomNamespace(argparse.Namespace):
423 from_: "FromArg" 452 from_: "FromArg"
424 order: "OrderArg" 453 order: "OrderArg"
425 summary: bool 454 summary: bool
455 summary_by_license: bool
426 local_only: bool 456 local_only: bool
427 user_only:bool 457 user_only:bool
428 output_file: str 458 output_file: str
429 ignore_packages: List[str] 459 ignore_packages: List[str]
430 packages: List[str] 460 packages: List[str]
556 '--summary', 586 '--summary',
557 action='store_true', 587 action='store_true',
558 default=False, 588 default=False,
559 help='dump summary of each license') 589 help='dump summary of each license')
560 common_options.add_argument( 590 common_options.add_argument(
591 '--summary-by-license',
592 action='store_true',
593 default=False,
594 help='dump summary of each individual license')
595 common_options.add_argument(
561 '--output-file', 596 '--output-file',
562 action='store', type=str, 597 action='store', type=str,
563 help='save license list to file') 598 help='save license list to file')
564 common_options.add_argument( 599 common_options.add_argument(
565 '-i', '--ignore-packages', 600 '-i', '--ignore-packages',

eric ide

mercurial