Ai
23 Star 56 Fork 90

openEuler/hpcrunner
关闭

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
toolService.py 1.81 KB
一键复制 编辑 原始数据 按行查看 历史
chunlin 提交于 2025-01-06 19:58 +08:00 . add key check when use config file
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import time
import os
class ToolService:
def prt_content(self, content):
"""
在内容上下添加分隔线并打印。
"""
flags = '*' * 30
print(f"{flags}\n{content}\n{flags}")
def gen_list(self, data):
"""
将字符串按行分割成列表。
"""
return data.strip().split('\n')
def get_time_stamp(self):
"""
获取当前时间的时间戳。
"""
return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
def read_file(self, filename):
"""
读取文件内容。
"""
content = ''
try:
with open(filename, encoding='utf-8') as f:
content = f.read().strip()
except FileNotFoundError:
pass
return content
def write_file(self, filename, content=""):
"""
将内容写入文件。
"""
with open(filename, 'w') as f:
f.write(content)
def del_file(self, filepath):
"""
删除文件。
"""
if os.path.exists(filepath):
os.remove(filepath)
def mkdirs(self, path):
"""
递归创建目录。
"""
if not os.path.exists(path):
os.makedirs(path)
def mkfile(self, path, content=''):
"""
创建文件并写入内容。
"""
if not os.path.exists(path):
self.write_file(path, content)
def check_url_isvalid(self, url):
"""
检查URL是否有效。
"""
import requests
try:
response = requests.get(url, stream=True)
return response.status_code == 200
except requests.exceptions.RequestException as e:
return False
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/openeuler/hpcrunner.git
git@gitee.com:openeuler/hpcrunner.git
openeuler
hpcrunner
hpcrunner
master

搜索帮助