1 Star 0 Fork 1

hujiamin0908/test0927_1

forked from hujiamin0106/test0927_1 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
test432.py 10.49 KB
一键复制 编辑 原始数据 按行查看 历史
寓述 提交于 2022-09-27 17:19 . rename test432 to test432.py.
# Copyright 2019-2021 Huawei Technologies Co., Ltd.All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Setup."""
import sys
import os
import shutil
import stat
import platform
import shlex
import subprocess
import types
from importlib import import_module
from setuptools import setup
from setuptools.command.egg_info import egg_info
from setuptools.command.build_py import build_py
from setuptools.command.install import install
def get_readme_content():
pwd = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(pwd, 'README.md'), encoding='UTF-8') as f:
return f.read()
def get_version():
"""
Get version.
Returns:
str, mindinsight version.
"""
machinery = import_module('importlib.machinery')
module_path = os.path.join(os.path.dirname(__file__), 'mindinsight', '_version.py')
module_name = '__mindinsightversion__'
version_module = types.ModuleType(module_name)
loader = machinery.SourceFileLoader(module_name, module_path)
loader.exec_module(version_module)
return version_module.VERSION
def get_platform():
"""
Get platform name.
Returns:
str, platform name in lowercase.
"""
return platform.system().strip().lower()
def get_description():
"""
Get description.
Returns:
str, wheel package description.
"""
os_info = get_platform()
cpu_info = platform.machine().strip()
cmd = "git log --format='[sha1]:%h, [branch]:%d' -1"
process = subprocess.Popen(
shlex.split(cmd),
shell=False,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
stdout, _ = process.communicate()
if not process.returncode:
git_version = stdout.decode().strip()
return 'mindinsight platform: %s, cpu: %s, git version: %s' % (os_info, cpu_info, git_version)
return 'mindinsight platform: %s, cpu: %s' % (os_info, cpu_info)
def get_install_requires():
"""
Get install requirements.
Returns:
list, list of dependent packages.
"""
with open('requirements.txt') as file:
return file.read().strip().splitlines()
def update_permissions(path):
"""
Update permissions.
Args:
path (str): Target directory path.
"""
for dirpath, dirnames, filenames in os.walk(path):
for dirname in dirnames:
dir_fullpath = os.path.join(dirpath, dirname)
os.chmod(dir_fullpath, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC | stat.S_IRGRP | stat.S_IXGRP)
for filename in filenames:
file_fullpath = os.path.join(dirpath, filename)
os.chmod(file_fullpath, stat.S_IREAD)
def run_script(script):
"""
Run script.
Args:
script (str): Target script file path.
Returns:
int, return code.
"""
cmd = '/bin/bash {}'.format(script)
process = subprocess.Popen(
shlex.split(cmd),
shell=False
)
return process.wait()
def build_dependencies():
"""Build dependencies."""
build_dir = os.path.join(os.path.dirname(__file__), 'build')
sys.stdout.write('building ui ...\n')
ui_script = os.path.join(build_dir, 'scripts', 'ui.sh')
rc = run_script(ui_script)
if rc:
sys.stdout.write('building ui failure\n')
sys.exit(1)
class EggInfo(egg_info):
"""Egg info."""
def run(self):
build_dependencies()
egg_info_dir = os.path.join(os.path.dirname(__file__), 'mindinsight.egg-info')
shutil.rmtree(egg_info_dir, ignore_errors=True)
super().run()
update_permissions(egg_info_dir)
#!/usr/bin/env python3
# coding: utf-8
# Copyright (c) 2020-2022 Huawei Technologies Co., Ltd.
# oec-hardware is 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.
# Create: 2020-04-01
import os
import json
import configparser
from subprocess import getoutput
from .command_ui import CommandUI
from .device import Device
from .sysinfo import SysInfo
from .env import CertEnv
from .constants import FILE_FLAGS, FILE_MODES
class Document():
"""
Basic document module
"""
def __init__(self, filename, logger, document=None):
self.filename = filename
self.logger = logger
self.document = document
def save(self):
"""
Save file
"""
with os.fdopen(os.open(self.filename, FILE_FLAGS, FILE_MODES), "w+") as save_f:
json.dump(self.document, save_f, indent=4)
return True
def load(self):
"""
Load file
"""
if not os.path.exists(self.filename):
return False
try:
with open(self.filename, "r") as load_f:
self.document = json.load(load_f)
except json.decoder.JSONDecodeError as error:
self.logger.error("The file %s is not json file." % self.filename)
return False
return True
class CertDocument(Document):
"""
Get hardware and release information
"""
def __init__(self, filename, logger, document=''):
super().__init__(filename, logger, dict())
if not document:
self.load()
def new(self):
"""
Create new document object
"""
try:
cmd_result = getoutput("/usr/sbin/dmidecode -t 1")
for line in cmd_result.split("\n"):
property_right = line.split(":", 1)
if len(property_right) != 2:
continue
key = property_right[0].strip()
value = property_right[1].strip()
if key in ("Manufacturer", "Product Name", "Version"):
self.document[key] = value
except Exception as concrete_error:
self.logger.error(
"Get hardware information failed. %s" % concrete_error)
if not os.path.exists(CertEnv.releasefile):
self.logger.error("The file %s doesn't exist." %
CertEnv.releasefile)
return False
sysinfo = SysInfo(CertEnv.releasefile)
self.document["OS"] = sysinfo.get_product() + " " + sysinfo.get_version()
self.document["kernel"] = sysinfo.get_kernel()
self.document["ID"] = CommandUI().prompt(
"Please provide your Compatibility Test ID:")
self.document["Product URL"] = CommandUI().prompt(
"Please provide your Product URL:")
self.document["server"] = CommandUI().prompt(
"Please provide the Compatibility Test Server (Hostname or Ipaddr):")
def get_oech_value(self, prop, value):
"""
Get oech version or name
"""
config = configparser.ConfigParser()
config.read(CertEnv.versionfile)
if prop == 'VERSION':
self.document["oech_version"] = config.get(prop, value)
self.document["oech_name"] = config.get(prop, value)
return config.get(prop, value)
def get_hardware(self):
"""
Get hardware information
"""
return self.document["Manufacturer"] + " " + self.document["Product Name"] + " " \
+ self.document["Version"]
# Copyright (c) 2020 Huawei Technologies Co.,Ltd.
#
# openGauss is licensed under 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.
"""This is only a template file that helps
users implement the web interfaces for DBMind.
And some implementations are only demonstrations.
"""
import time
from pydantic import BaseModel
from dbmind.common.http import request_mapping, OAuth2
from dbmind.common.http import standardized_api_output
from dbmind.service import web
@request_mapping('/api/summary/workload_forecasting', methods=['GET'], api=True)
@oauth2.token_authentication()
@standardized_api_output
def workload_forecasting_summary():
return web.get_forecast_sequence_info(metric_name=None)
@request_mapping('/api/workload_forecasting/sequence/{name}', methods=['GET'], api=True)
@oauth2.token_authentication()
@standardized_api_output
def workload_forecasting_get_metric_sequence(name, start: int = None, end: int = None, step: int = None):
return web.get_metric_sequence(name, start, end, step)
@request_mapping('/api/workload_forecasting/sequence/forecast/{name}', methods=['GET'], api=True)
@oauth2.token_authentication()
@standardized_api_output
def workload_forecasting_forecast(name: str, start: int = None, end: int = None, step: int = None):
if start is None and end is None:
r = web.get_forecast_sequence_info(name)['rows']
if len(r) > 0:
rv = web.get_stored_forecast_sequence(name, start_at=int(time.time() * 1000), limit=500)
return rv
return web.get_metric_forecast_sequence(name, start, end, step)
https://gitee.com/mindspore/mindinsight.git 4406
https://gitee.com/openeuler/oec-hardware.git 3470
https://gitee.com/opengauss/openGauss-DBMind.git 2026
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/hujiamin0908/test0927_1.git
git@gitee.com:hujiamin0908/test0927_1.git
hujiamin0908
test0927_1
test0927_1
master

搜索帮助