4
4
5
5
Module that handles command-line argument parsing and common validation.
6
6
"""
7
+ import os
7
8
import java .io .File as JFile
8
9
import java .lang .IllegalArgumentException as JIllegalArgumentException
9
10
import java .net .URI as JURI
@@ -94,11 +95,12 @@ def __init__(self, program_name, required_args, optional_args):
94
95
self ._optional_result = {}
95
96
return
96
97
97
- def process_args (self , args ):
98
+ def process_args (self , args , for_domain_create = False ):
98
99
"""
99
100
This method parses the command-line arguments and returns dictionaries of the required and optional args.
100
101
101
102
:param args: sys.argv
103
+ :param for_domain_create: true if validating for domain creation
102
104
:return: the required and optional argument dictionaries
103
105
:raises CLAException: if argument processing encounters a usage or validation exception
104
106
"""
@@ -147,7 +149,10 @@ def process_args(self, args):
147
149
elif self .is_domain_home_key (key ):
148
150
idx += 1
149
151
if idx < args_len :
150
- full_path = self ._validate_domain_home_arg (args [idx ])
152
+ if for_domain_create :
153
+ full_path = self ._validate_domain_home_arg_for_create (args [idx ])
154
+ else :
155
+ full_path = self ._validate_domain_home_arg (args [idx ])
151
156
self ._add_arg (key , full_path , True )
152
157
else :
153
158
ex = self ._get_out_of_args_exception (key )
@@ -450,8 +455,7 @@ def is_domain_home_key(self, key):
450
455
return self .DOMAIN_HOME_SWITCH == key
451
456
452
457
#
453
- # The domain home arg is only used by discover and deploy so it must be a valid domain home.
454
- # The create domain operation should use the domain parent arg.
458
+ # The domain home arg used by discover and deploy must be a valid domain home.
455
459
#
456
460
def _validate_domain_home_arg (self , value ):
457
461
method_name = '_validate_domain_home_arg'
@@ -477,6 +481,24 @@ def _validate_domain_home_arg(self, value):
477
481
478
482
return dh .getAbsolutePath ()
479
483
484
+ #
485
+ # The domain home arg used by create must be the child of a valid, writable directory.
486
+ #
487
+ def _validate_domain_home_arg_for_create (self , value ):
488
+ method_name = '_validate_domain_home_arg_for_create'
489
+
490
+ try :
491
+ parent_dir = os .path .dirname (value )
492
+ JFileUtils .validateWritableDirectory (parent_dir )
493
+ except JIllegalArgumentException , iae :
494
+ ex = exception_helper .create_cla_exception ('WLSDPLY-01606' , value , iae .getLocalizedMessage (), error = iae )
495
+ ex .setExitCode (self .ARG_VALIDATION_ERROR_EXIT_CODE )
496
+ self ._logger .throwing (ex , class_name = self ._class_name , method_name = method_name )
497
+ raise ex
498
+
499
+ home_dir = JFile (value )
500
+ return home_dir .getAbsolutePath ()
501
+
480
502
def get_domain_parent_key (self ):
481
503
return self .DOMAIN_PARENT_SWITCH
482
504
0 commit comments