1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/devteamcn-chia-tools

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
config.py 2.2 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
devteamcn Отправлено 20.07.2021 15:33 9b02667
import json
import platform
import os
import shutil
config = {}
root = os.path.dirname(__file__)
__current_dir = os.path.dirname(__file__)
__config_dir = os.path.join(os.path.expanduser('~'), '.ChiaTools')
__user_dir = os.path.join(os.path.expanduser('~'), '.ChiaTools')
__config_file = ''
def get_config():
global config
return config
def get_config_file():
global __config_file
if __config_file:
return __config_file
current_file = os.path.join(__current_dir, 'config.json')
user_file = os.path.join(__user_dir, 'config.json')
if os.path.exists(current_file):
__config_file = current_file
return current_file
if not os.path.exists(__user_dir):
os.mkdir(__user_dir)
__config_file = user_file
return user_file
def load_config():
global config
config_file = get_config_file()
try:
if not os.path.exists(config_file):
return
cfg_json = open(config_file, 'r').read()
if not cfg_json:
return
config = json.loads(cfg_json)
except:
pass
if config is None:
config = {}
# update config
if 'miner_name' in config:
config['hpool_miner_name'] = config['miner_name']
del config['miner_name']
if 'apikey' in config:
config['hpool_apikey'] = config['apikey']
del config['apikey']
if 'auto_mine' in config:
config['hpool_auto_mine'] = config['auto_mine']
del config['auto_mine']
if 'hdd_folders' in config:
hdd_folders_obj = config['hdd_folders']
for folder_obj in hdd_folders_obj:
if 'new_plot' not in folder_obj:
folder_obj['new_plot'] = False
def save_config():
global config
if not config:
return
config_file = get_config_file()
config_dir = os.path.dirname(config_file)
try:
if not os.path.exists(config_dir):
os.mkdir(config_dir)
tmp_file = os.path.join(config_dir, 'config.json.tmp')
cfg_json = json.dumps(config, indent=' ')
open(tmp_file, 'w').write(cfg_json)
if os.path.exists(config_file):
os.remove(config_file)
os.rename(tmp_file, config_file)
except Exception as e:
pass

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/devteamcn-chia-tools.git
git@api.gitlife.ru:oschina-mirror/devteamcn-chia-tools.git
oschina-mirror
devteamcn-chia-tools
devteamcn-chia-tools
master