FILESPATH = "${@base_set_filespath(["${FILE_DIRNAME}/${BP}", \ "${FILE_DIRNAME}/${BPN}", "${FILE_DIRNAME}/files"], d)}"
时间: 2023-07-19 14:55:44 浏览: 117
这是一个 BitBake 脚本语句,用于设置文件路径。其中,`${FILE_DIRNAME}` 表示当前文件所在目录,`${BP}` 表示当前 BitBake 文件的 base name,`${BPN}` 表示当前 recipe 的 base name,`d` 表示当前 BitBake 数据库。`base_set_filespath` 是 BitBake 内置函数,用于设置文件路径。在这个语句中,会将 `${FILE_DIRNAME}/${BP}`、`${FILE_DIRNAME}/${BPN}`、`${FILE_DIRNAME}/files` 这三个路径拼接成一个路径,并赋值给 `FILESPATH` 变量。
相关问题
请将下述shell语言转换为python语言:if [ $HELPs_project_directory ]; then printf "" else # because on sunway platfrom, file name contain symbolic link can not open # thus we should make sure the HELPs directory do not contain symbolic link # first obtain the script directory, this path may contain symbolic link readonly script_directory="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" # then remove symbolic link if it exist, the absolute path now obtained readonly HELPs_script_directory=$(readlink -f ${script_directory}) readonly HELPs_project_directory=`dirname ${HELPs_script_directory}` readonly HELPs_build_directory=${HELPs_project_directory}/build readonly HELPs_document_directory=${HELPs_project_directory}/document readonly HELPs_third_party_directory=${HELPs_project_directory}/third_party readonly HELPs_output_directory=${HELPs_project_directory}/output readonly HELPs_HPC_script_directory=${HELPs_project_directory}/HPC_script fi
以下是将上述Shell代码转换为Python代码的示例:
```python
import os
if os.environ.get('HELPs_project_directory'):
print("")
else:
# because on sunway platfrom, file name contain symbolic link can not open
# thus we should make sure the HELPs directory do not contain symbolic link
# first obtain the script directory, this path may contain symbolic link
script_directory = os.path.dirname(os.path.realpath(__file__))
# then remove symbolic link if it exist, the absolute path now obtained
HELPs_script_directory = os.path.realpath(script_directory)
HELPs_project_directory = os.path.dirname(HELPs_script_directory)
HELPs_build_directory = os.path.join(HELPs_project_directory, 'build')
HELPs_document_directory = os.path.join(HELPs_project_directory, 'document')
HELPs_third_party_directory = os.path.join(HELPs_project_directory, 'third_party')
HELPs_output_directory = os.path.join(HELPs_project_directory, 'output')
HELPs_HPC_script_directory = os.path.join(HELPs_project_directory, 'HPC_script')
```
在上述Python代码中,我们使用`os`模块来获取路径和目录,并使用相应的函数替代Shell中的命令。通过这种方式,我们可以在Python中实现与原始Shell代码相同的逻辑。请注意,根据具体情况,你可能需要根据实际需求进行调整和修改。
请将下列shell语句转换为python语句:if [ ${stage} -le 2 ] && [ ${stop_stage} -ge 2 ]; then # Make train dict echo "Make a dictionary" mkdir -p $(dirname $dict) echo "<blank> 0" > ${dict} # 0 will be used for "blank" in CTC echo "<unk> 1" >> ${dict} # <unk> must be 1 if [ "${token_type}" = bpe ]; then # we borrowed these code and scripts which are related bpe from ESPnet. cut -f 2- -d" " data/${train_set}/text | sort > data/lang_char/input.txt tools/spm_train --input=data/lang_char/input.txt --vocab_size=${nbpe} --model_type=${bpemode} --model_prefix=${bpemodel} --input_sentence_size=100000000 tools/spm_encode --model=${bpemodel}.model --output_format=piece < data/lang_char/input.txt | tr ' ' '\n' | sort | uniq | awk '{print $0 " " NR+1}' >> ${dict} elif [ "${token_type}" = char ]; then tools/text2token.py -s 1 -n 1 data/${train_set}/text | cut -f 2- -d" " | tr " " "\n" \ | sort | uniq | grep -a -v -e '^\s*$' | awk '{print $0 " " NR+1}' >> ${dict} fi num_token=$(cat $dict | wc -l) echo "<sos/eos> $num_token" >> $dict # <eos> fi
以下是将上述shell语句转换为Python语句的代码:
```python
if stage <= 2 and stop_stage >= 2:
# Make train dict
print("Make a dictionary")
os.makedirs(os.path.dirname(dict), exist_ok=True)
with open(dict, "w") as f:
f.write("<blank> 0\n") # 0 will be used for "blank" in CTC
f.write("<unk> 1\n") # <unk> must be 1
if token_type == "bpe":
# we borrowed these code and scripts which are related bpe from ESPnet.
with open(f"data/{train_set}/text") as text_file:
texts = [line.strip().split()[1:] for line in text_file]
with open("data/lang_char/input.txt", "w") as input_file:
for text in texts:
input_file.write(" ".join(text) + "\n")
subprocess.run(f"tools/spm_train --input=data/lang_char/input.txt --vocab_size={nbpe} --model_type={bpemode} --model_prefix={bpemodel} --input_sentence_size=100000000", shell=True)
with open(f"{bpemodel}.vocab") as vocab_file:
vocab = [line.strip().split()[0] for line in vocab_file]
with open(dict, "a") as dict_file:
for i, vocab_item in enumerate(vocab):
dict_file.write(f"{vocab_item} {i+2}\n")
elif token_type == "char":
with open(f"data/{train_set}/text") as text_file:
texts = [line.strip().split()[1] for line in text_file]
texts = " ".join(texts)
tokens = subprocess.check_output(f"echo '{texts}' | tools/spm_encode --model={bpemodel}.model --output_format=piece", shell=True)
tokens = tokens.decode().split("\n")
tokens = [token.strip() for token in tokens if token.strip() != ""]
tokens = sorted(set(tokens))
with open(dict, "a") as dict_file:
for i, token in enumerate(tokens):
dict_file.write(f"{token} {i+2}\n")
num_token = sum(1 for line in open(dict))
with open(dict, "a") as dict_file:
dict_file.write(f"<sos/eos> {num_token}\n") # <eos>
```
需要注意的是,在Python中也需要使用相应的模块和工具来实现shell语句中的一些操作,例如在此代码中使用了`os`、`subprocess`模块和`tools/spm_train`、`tools/spm_encode`脚本来进行文件操作和调用外部命令。另外,由于Python中没有直接对应的`$`符号,需要使用`f-string`或者`str.format()`方法来进行字符串格式化。
阅读全文