Skip to content

Commit 641996c

Browse files
committed
Add the option for --extract_license
Add text for the usage. Add code for the command line that use '--extract_license" Add code to check the required api field for the --extract_license
1 parent 6d054b1 commit 641996c

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

about_code_tool/genabout.py

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,15 @@ def option_usage():
393393
<path>
394394
Project path
395395
--mapping Activate the MAPPING.CONFIG
396+
--extract_license <3 args required> Extract License text and create <license_key>.LICENSE
397+
side-by-side with the .ABOUT from DJE License Library
398+
<--api_url='URL'> - URL to the DJE License Library
399+
<--api_username='user_api'> - The regular DJE username
400+
<--api_key='user_api_key'> - Hash attached to your username which is used
401+
to Authenticate yourself in the API. Contact
402+
us to get the hash key.
403+
Example syntax:
404+
genabout.py --extract_license --api_url='https://enterprise.dejacode.com/api/v1/license_text/' --api_username='<user_api>' --api_key='<user_api_key>'
396405
""")
397406

398407

@@ -402,6 +411,10 @@ def main(args, opts):
402411
all_in_one = False
403412
project_path = ''
404413
mapping_config = False
414+
gen_license = False
415+
api_url = ''
416+
api_username = ''
417+
api_key = ''
405418

406419
for opt, opt_arg in opts:
407420
invalid_opt = True
@@ -462,9 +475,48 @@ def main(args, opts):
462475
else:
463476
mapping_config = True
464477

478+
if opt in ('--extract_license'):
479+
invalid_opt = False
480+
gen_license = True
481+
482+
483+
if opt in ('--api_url'):
484+
invalid_opt = False
485+
if not opt_arg or not 'http' in opt_arg.lower():
486+
print("Invalid option argument.")
487+
option_usage()
488+
sys.exit(errno.EINVAL)
489+
else:
490+
api_url = opt_arg
491+
492+
if opt in ('--api_username'):
493+
invalid_opt = False
494+
if not opt_arg or '/' in opt_arg or '\\' in opt_arg:
495+
print("Invalid option argument.")
496+
option_usage()
497+
sys.exit(errno.EINVAL)
498+
else:
499+
api_username = opt_arg
500+
501+
if opt in ('--api_key'):
502+
invalid_opt = False
503+
if not opt_arg or '/' in opt_arg or '\\' in opt_arg:
504+
print("Invalid option argument.")
505+
option_usage()
506+
sys.exit(errno.EINVAL)
507+
else:
508+
api_key = opt_arg
509+
465510
if invalid_opt:
466511
assert False, 'Unsupported option.'
467512

513+
# Check do we have all the required arguments: api_url, api_username, api_key
514+
if gen_license:
515+
if not api_url or not api_username or not api_key:
516+
print("Missing argument for --extract_license")
517+
option_usage()
518+
sys.exit(errno.EINVAL)
519+
468520
if not len(args) == 2:
469521
print('Input file and generated location parameters are mandatory.')
470522
syntax()
@@ -499,7 +551,8 @@ def main(args, opts):
499551
gen.warnings_errors_summary(gen_location, verb_arg_num)
500552

501553
if __name__ == "__main__":
502-
longopts = ['help', 'version', 'action=', 'verbosity=', 'all-in-one=', 'copy_license=', 'mapping']
554+
longopts = ['help', 'version', 'action=', 'verbosity=', 'all-in-one=', 'copy_license=', 'mapping', 'extract_license', 'api_url='
555+
, 'api_username=', 'api_key=']
503556
try:
504557
opts, args = getopt.getopt(sys.argv[1:], 'hv', longopts)
505558
except Exception as e:

0 commit comments

Comments
 (0)