@@ -239,6 +239,10 @@ def inventory(location, output, format, quiet, verbose): # NOQA
239239 type = click .Path (exists = True , file_okay = False , readable = True , resolve_path = True ),
240240 help = 'Path to a directory with reference license data and text files.' )
241241
242+ @click .option ('--worksheet' ,
243+ metavar = 'name' ,
244+ help = 'The worksheet name from the INPUT. (Default: the "active" worksheet)' )
245+
242246@click .option ('-q' , '--quiet' ,
243247 is_flag = True ,
244248 help = 'Do not print error or warning messages.' )
@@ -248,7 +252,7 @@ def inventory(location, output, format, quiet, verbose): # NOQA
248252 help = 'Show all error and warning messages.' )
249253
250254@click .help_option ('-h' , '--help' )
251- def gen (location , output , android , fetch_license , fetch_license_djc , reference , quiet , verbose ):
255+ def gen (location , output , android , fetch_license , fetch_license_djc , reference , worksheet , quiet , verbose ):
252256 """
253257Given a CSV/JSON/XLSX inventory, generate ABOUT files in the output location.
254258
@@ -264,13 +268,17 @@ def gen(location, output, android, fetch_license, fetch_license_djc, reference,
264268 if not location .endswith (('.csv' , '.json' , '.xlsx' )):
265269 raise click .UsageError ('ERROR: Invalid input file extension: must be one .csv or .json or .xlsx.' )
266270
271+ if worksheet and not location .endswith ('.xlsx' ):
272+ raise click .UsageError ('ERROR: --worksheet option only works with .xlsx input.' )
273+
267274 errors , abouts = generate_about_files (
268275 location = location ,
269276 base_dir = output ,
270277 android = android ,
271278 reference_dir = reference ,
272279 fetch_license = fetch_license ,
273280 fetch_license_djc = fetch_license_djc ,
281+ worksheet = worksheet
274282 )
275283
276284 errors_count = report_errors (errors , quiet , verbose , log_file_loc = output + '-error.log' )
@@ -309,12 +317,16 @@ def gen(location, output, android, fetch_license, fetch_license_djc, reference,
309317 is_flag = True ,
310318 help = 'Indicate the input JSON file is from scancode_toolkit.' )
311319
320+ @click .option ('--worksheet' ,
321+ metavar = 'name' ,
322+ help = 'The worksheet name from the INPUT. (Default: the "active" worksheet)' )
323+
312324@click .option ('--verbose' ,
313325 is_flag = True ,
314326 help = 'Show all error and warning messages.' )
315327
316328@click .help_option ('-h' , '--help' )
317- def gen_license (location , output , djc , scancode , verbose ):
329+ def gen_license (location , output , djc , scancode , worksheet , verbose ):
318330 """
319331Fetch licenses (Default: ScanCode LicenseDB) in the license_expression field and save to the output location.
320332
@@ -327,10 +339,13 @@ def gen_license(location, output, djc, scancode, verbose):
327339 api_key = ''
328340 errors = []
329341
342+ if worksheet and not location .endswith ('.xlsx' ):
343+ raise click .UsageError ('ERROR: --worksheet option only works with .xlsx input.' )
344+
330345 log_file_loc = os .path .join (output , 'error.log' )
331346
332347 if location .endswith ('.csv' ) or location .endswith ('.json' ) or location .endswith ('.xlsx' ):
333- errors , abouts = collect_inventory_license_expression (location = location , scancode = scancode )
348+ errors , abouts = collect_inventory_license_expression (location = location , scancode = scancode , worksheet = worksheet )
334349 if errors :
335350 severe_errors_count = report_errors (errors , quiet = False , verbose = verbose , log_file_loc = log_file_loc )
336351 sys .exit (severe_errors_count )
@@ -440,6 +455,10 @@ def validate_template(ctx, param, value):
440455 metavar = '<key>=<value>' ,
441456 help = 'Add variable text as key=value for use in a custom attribution template.' )
442457
458+ @click .option ('--worksheet' ,
459+ metavar = 'name' ,
460+ help = 'The worksheet name from the INPUT. (Default: the "active" worksheet)' )
461+
443462@click .option ('-q' , '--quiet' ,
444463 is_flag = True ,
445464 help = 'Do not print error or warning messages.' )
@@ -449,7 +468,7 @@ def validate_template(ctx, param, value):
449468 help = 'Show all error and warning messages.' )
450469
451470@click .help_option ('-h' , '--help' )
452- def attrib (input , output , api_url , api_key , scancode , min_license_score , reference , template , vartext , quiet , verbose ):
471+ def attrib (input , output , api_url , api_key , scancode , min_license_score , reference , template , vartext , worksheet , quiet , verbose ):
453472 """
454473Generate an attribution document at OUTPUT using JSON, CSV or XLSX or .ABOUT files at INPUT.
455474
@@ -464,6 +483,9 @@ def attrib(input, output, api_url, api_key, scancode, min_license_score, referen
464483 license_dict = {}
465484 errors = []
466485
486+ if worksheet and not input .endswith ('.xlsx' ):
487+ raise click .UsageError ('ERROR: --worksheet option only works with .xlsx input.' )
488+
467489 if not quiet :
468490 print_version ()
469491 click .echo ('Generating attribution...' )
@@ -501,7 +523,8 @@ def attrib(input, output, api_url, api_key, scancode, min_license_score, referen
501523 location = input ,
502524 from_attrib = from_attrib ,
503525 scancode = scancode ,
504- reference_dir = reference
526+ reference_dir = reference ,
527+ worksheet = worksheet
505528 )
506529
507530 else :
@@ -765,6 +788,10 @@ def print_config_help(ctx, param, value):
765788 help = 'Path to an optional YAML configuration file. See --help-format for '
766789 'format help.' )
767790
791+ @click .option ('--worksheet' ,
792+ metavar = 'name' ,
793+ help = 'The worksheet name from the INPUT. (Default: the "active" worksheet)' )
794+
768795@click .option ('--help-format' ,
769796 is_flag = True , is_eager = True , expose_value = False ,
770797 callback = print_config_help ,
@@ -779,7 +806,7 @@ def print_config_help(ctx, param, value):
779806 help = 'Show all error and warning messages.' )
780807
781808@click .help_option ('-h' , '--help' )
782- def transform (location , output , configuration , quiet , verbose ): # NOQA
809+ def transform (location , output , configuration , worksheet , quiet , verbose ): # NOQA
783810 """
784811Transform the CSV/JSON/XLSX file at LOCATION by applying renamings, filters and checks
785812and then write a new CSV/JSON/XLSX to OUTPUT.
@@ -788,6 +815,9 @@ def transform(location, output, configuration, quiet, verbose): # NOQA
788815
789816OUTPUT: Path to CSV/JSON/XLSX inventory file to create.
790817 """
818+ if worksheet and not location .endswith ('.xlsx' ):
819+ raise click .UsageError ('ERROR: --worksheet option only works with .xlsx input.' )
820+
791821 if not configuration :
792822 transformer = Transformer .default ()
793823 else :
@@ -807,11 +837,16 @@ def transform(location, output, configuration, quiet, verbose): # NOQA
807837 elif location .endswith ('.json' ):
808838 new_data , errors = transform_json (location )
809839 elif location .endswith ('.xlsx' ):
810- new_data , errors = transform_excel (location )
840+ new_data , errors = transform_excel (location , worksheet )
811841
812842 if not errors :
813843 updated_data , errors = transform_data (new_data , transformer )
814844
845+ if not updated_data :
846+ msg = 'The input is empty. Nothing is transformed.'
847+ click .echo (msg )
848+ sys .exit (0 )
849+
815850 if not errors :
816851 if output .endswith ('.csv' ):
817852 write_csv (output , updated_data )
0 commit comments