修复取包名大小写问题
This commit is contained in:
@ -1566,11 +1566,61 @@ class LinuxPlatform(GenericPlatform):
|
|||||||
|
|
||||||
fileName = os.path.normpath(fileName)
|
fileName = os.path.normpath(fileName)
|
||||||
if not os.path.exists(fileName):
|
if not os.path.exists(fileName):
|
||||||
raise Exception(ErrorCode.GAUSS_502["GAUSS_50201"] % fileName)
|
try:
|
||||||
|
directory_to_search = os.path.join(dirName, "./../../../")
|
||||||
|
matched_files = self.compare_files_in_directory(directory_to_search, fileName)
|
||||||
|
|
||||||
|
if len(matched_files) == 1:
|
||||||
|
return matched_files[0]
|
||||||
|
elif len(matched_files) > 1:
|
||||||
|
print("Multiple matching files found,"
|
||||||
|
"please select one:")
|
||||||
|
|
||||||
|
for i, file in enumerate(matched_files, 1):
|
||||||
|
print(f"{i}. {file}")
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
choice = int(input("Please enter the serial number"
|
||||||
|
"of the option:"))
|
||||||
|
if 1 <= choice <= len(matched_files):
|
||||||
|
return matched_files[choice - 1]
|
||||||
|
else:
|
||||||
|
print("Invalid input: Please re-enter")
|
||||||
|
except ValueError:
|
||||||
|
print("Invalid input: Please re-enter")
|
||||||
|
else:
|
||||||
|
raise Exception("No matching files found in the directory.")
|
||||||
|
except Exception as e:
|
||||||
|
raise Exception(ErrorCode.GAUSS_502["GAUSS_50201"] % fileName)
|
||||||
|
|
||||||
if not os.path.isfile(fileName):
|
if not os.path.isfile(fileName):
|
||||||
raise Exception(ErrorCode.GAUSS_502["GAUSS_50210"] % fileName)
|
raise Exception(ErrorCode.GAUSS_502["GAUSS_50210"] % fileName)
|
||||||
return fileName
|
return fileName
|
||||||
|
|
||||||
|
def compare_files_in_directory(directory, file_to_compare):
|
||||||
|
"""
|
||||||
|
function: The function is to recursively search for files in the
|
||||||
|
specified directory and compare them with the given file,
|
||||||
|
input:
|
||||||
|
directory: Directory path to traverse
|
||||||
|
file_to_compare: The file path to compare with files in the directory
|
||||||
|
output:
|
||||||
|
matched_files
|
||||||
|
"""
|
||||||
|
matched_files = []
|
||||||
|
|
||||||
|
for root, dirs, files in os.walk(directory):
|
||||||
|
for file in files:
|
||||||
|
file_path = os.path.join(root, file)
|
||||||
|
if os.path.isfile(file_path) and file_to_compare.lower() == file_path.lower():
|
||||||
|
matched_files.append(file_path)
|
||||||
|
|
||||||
|
if matched_files:
|
||||||
|
return matched_files
|
||||||
|
else:
|
||||||
|
raise Exception(ErrorCode.GAUSS_502["GAUSS_50201"] % file_to_compare)
|
||||||
|
|
||||||
def setKeyValueInSshd(self, key, value):
|
def setKeyValueInSshd(self, key, value):
|
||||||
"""
|
"""
|
||||||
function: Set a (key, value) pair into /etc/ssh/sshd_config,
|
function: Set a (key, value) pair into /etc/ssh/sshd_config,
|
||||||
|
@ -243,7 +243,60 @@ class LinuxPlatform(object):
|
|||||||
package_name_list.append(package_name)
|
package_name_list.append(package_name)
|
||||||
if os.path.exists(file_name) and os.path.isfile(file_name):
|
if os.path.exists(file_name) and os.path.isfile(file_name):
|
||||||
return file_name
|
return file_name
|
||||||
|
|
||||||
|
for file_name in file_name_list:
|
||||||
|
try:
|
||||||
|
directory_to_search = os.path.join(dir_name, "./../../../")
|
||||||
|
matched_files = self.compare_files_in_directory(directory_to_search, file_name)
|
||||||
|
|
||||||
|
if len(matched_files) == 1:
|
||||||
|
return matched_files[0]
|
||||||
|
elif len(matched_files) > 1:
|
||||||
|
print("Multiple matching files found,"
|
||||||
|
"please select one:")
|
||||||
|
|
||||||
|
for i, file in enumerate(matched_files, 1):
|
||||||
|
print(f"{i}. {file}")
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
choice = int(input("Please enter the serial number"
|
||||||
|
"of the option:"))
|
||||||
|
if 1 <= choice <= len(matched_files):
|
||||||
|
return matched_files[choice - 1]
|
||||||
|
else:
|
||||||
|
print("Invalid input: Please re-enter")
|
||||||
|
except ValueError:
|
||||||
|
print("Invalid input: Please re-enter")
|
||||||
|
else:
|
||||||
|
raise Exception("No matching files found in the directory.")
|
||||||
|
except Exception as e:
|
||||||
|
raise Exception(ErrorCode.GAUSS_502["GAUSS_50201"] % file_name)
|
||||||
|
|
||||||
raise Exception(ErrorCode.GAUSS_502["GAUSS_50201"] % package_name_list)
|
raise Exception(ErrorCode.GAUSS_502["GAUSS_50201"] % package_name_list)
|
||||||
|
|
||||||
|
def compare_files_in_directory(directory, file_to_compare):
|
||||||
|
"""
|
||||||
|
function: The function is to recursively search for files in the
|
||||||
|
specified directory and compare them with the given file,
|
||||||
|
input:
|
||||||
|
directory: Directory path to traverse
|
||||||
|
file_to_compare: The file path to compare with files in the directory
|
||||||
|
output:
|
||||||
|
matched_files
|
||||||
|
"""
|
||||||
|
matched_files = []
|
||||||
|
|
||||||
|
for root, dirs, files in os.walk(directory):
|
||||||
|
for file in files:
|
||||||
|
file_path = os.path.join(root, file)
|
||||||
|
if os.path.isfile(file_path) and file_to_compare.lower() == file_path.lower():
|
||||||
|
matched_files.append(file_path)
|
||||||
|
|
||||||
|
if matched_files:
|
||||||
|
return matched_files
|
||||||
|
else:
|
||||||
|
raise Exception(ErrorCode.GAUSS_502["GAUSS_50201"] % file_to_compare)
|
||||||
|
|
||||||
def getGrepCmd(self):
|
def getGrepCmd(self):
|
||||||
"""
|
"""
|
||||||
|
Reference in New Issue
Block a user