本文整理汇总了Python中preupg.utils.FileHelper.check_file方法的典型用法代码示例。如果您正苦于以下问题:Python FileHelper.check_file方法的具体用法?Python FileHelper.check_file怎么用?Python FileHelper.check_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类preupg.utils.FileHelper
的用法示例。
在下文中一共展示了FileHelper.check_file方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: find_all_ini
# 需要导入模块: from preupg.utils import FileHelper [as 别名]
# 或者: from preupg.utils.FileHelper import check_file [as 别名]
def find_all_ini(self):
"""
This function is used for finding all _fix files in the user defined
directory
"""
for dir_name in os.listdir(self.dirname):
if dir_name.endswith(".ini"):
self.lists.append(os.path.join(self.dirname, dir_name))
for file_name in self.lists:
if FileHelper.check_file(file_name, "r") is False:
continue
try:
config = configparser.ConfigParser()
filehander = codecs.open(file_name, 'r', encoding=settings.defenc)
config.readfp(filehander)
fields = {}
if config.has_section('premigrate'):
section = 'premigrate'
else:
section = 'preupgrade'
for option in config.options(section):
fields[option] = config.get(section, option)
self.loaded[file_name] = [fields]
except configparser.MissingSectionHeaderError:
MessageHelper.print_error_msg(title="Missing section header")
except configparser.NoSectionError:
MessageHelper.print_error_msg(title="Missing section header")
except configparser.ParsingError:
MessageHelper.print_error_msg(title="Incorrect INI file\n", msg=file_name)
os.sys.exit(1)
示例2: find_all_ini
# 需要导入模块: from preupg.utils import FileHelper [as 别名]
# 或者: from preupg.utils.FileHelper import check_file [as 别名]
def find_all_ini(self):
"""
Find all ini files in the self.dirname path. Then read each ini file
and save all options in 'preupgrade' section with their values to
self.loded dict:
self.loaded[ini_file_path] = {option1: value, option2: value, ...}
"""
for dir_name in os.listdir(self.dirname):
if dir_name.endswith(".ini"):
self.lists.append(os.path.join(self.dirname, dir_name))
for file_name in self.lists:
if FileHelper.check_file(file_name, "r") is False:
continue
filehander = codecs.open(file_name, 'r', encoding=settings.defenc)
config = configparser.ConfigParser()
config.readfp(filehander)
fields = {}
section = 'preupgrade'
for option in config.options(section):
fields[option] = config.get(section, option)
self.loaded[file_name] = fields
示例3: check_files_are_readable
# 需要导入模块: from preupg.utils import FileHelper [as 别名]
# 或者: from preupg.utils.FileHelper import check_file [as 别名]
def check_files_are_readable(files):
for file in files:
if not FileHelper.check_file(file, "r"):
sys.exit("Error: Can't read '{0}'.".format(file))