diff --git a/main.py b/main.py index 29c5f209b02631f3ab0528443ca577b4f9539af4..8a5ffbab212511862795868ea3301e2869e49be1 100644 --- a/main.py +++ b/main.py @@ -12,7 +12,9 @@ # See the Mulan PSL v2 for more details. # ********************************************************************************** """ +import sys import argparse +from src.utils.isocheck import IsoCheck class kyClassifier: @staticmethod @@ -29,6 +31,8 @@ if __name__ == '__main__': parser.add_argument('-iso', type=str, help='Input ISO file path') args = parser.parse_args() if args.iso: + if not IsoCheck.check(args.iso): + sys.exit(1) kyClassifier.process_iso(args.iso) diff --git a/src/utils/isocheck.py b/src/utils/isocheck.py new file mode 100644 index 0000000000000000000000000000000000000000..2571c3498436c4cc0d541fbc1ea844131007f4c9 --- /dev/null +++ b/src/utils/isocheck.py @@ -0,0 +1,45 @@ +#-*- coding:utf-8 -*- +""" +# ********************************************************************************** +# Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. +# [kyclassifier] licensed under the Mulan PSL v2. +# You can use this software according to the terms and conditions of the Mulan PSL v2. +# You may obtain a copy of Mulan PSL v2 at: +# http://license.coscl.org.cn/MulanPSL2 +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR +# PURPOSE. +# See the Mulan PSL v2 for more details. +# ********************************************************************************** +""" +import os + +ERROR_INFO={ + 1001:"The ISO path does not exist. Please check if the entered ISO path is correct.", + 1002:"The ISO file format is not correct. Please check if the input file is a server operating system ISO image file.", +} + +class IsoCheck(object): + def __init__(self,path): + self.path=path + + def check_exist(self): + if not os.path.exists(self.path): + return False + else: + return True + + def check_format(self): + pass + + @classmethod + def check(cls,iso_path): + obj = cls(iso_path) + if not obj.check_exist(): + print(ERROR_INFO.get(1001,'')) + return False + elif not obj.check_format(): + print(ERROR_INFO.get(1002,'')) + return False + else: + return True