There is a shell command, I am trying to convert the logic into python. But I don't know what to do, I need some help with that.
shell command is this :
cd ../../../tests/src/main/test
ls
find . -name '*.vrlp' | while read FILENAME
do
TEST_CASE=`echo $FILENAME | sed s/"\.\/"//g | sed s/"\.vrlp"//g | rev | cut -f1 -d"/" | rev`
CLASS=`echo $FILENAME | sed s/"\.\/"//g | sed s/"\/$TEST_CASE"//g | sed s/"\.vrlp"//g`
The logic is inside a directory, filter all exists file by using find . -name '*.vrlp', includes all sub-folders
Then retrieve the data into parameters.
TEST_CASE=`echo $FILENAME | sed s/"\.\/"//g | sed s/"\.vrlp"//g | rev | cut -f1 -d"/" | rev`
CLASS=`echo $FILENAME | sed s/"\.\/"//g | sed s/"\/$TEST_CASE"//g | sed s/"\.vrlp"//g`
I tried something like follows, but I don't know the sed command exactly doing and how to convert it into python script. for example
For retrieve the data send to parameter CLASS and TESTCASE , I did the cut (
cut -f1 -d"/"
) but I don't know how to do the sed and rev to retrieve the value for TEST_CASE and CLASS
for root, dirs, files in os.walk(../../../tests/src/main/test):
for file in files:
file_name = os.path.basename(file)
file = os.path.splitext(file_name)
if '.vrlp' in file:
FILENAME = file[0] + file[1]
TEST_CASE = FILENAME.split("/")[0] // how to apply sed and rev here?
CLASS = FILENAME // how to apply sed here?
Any help will be much appreciated