| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- # -*- coding: utf-8 -*-
- import subprocess
- import os
- import platform
- from base.base_load_config import load_config
- comfig_json = load_config()
- use_proxy = comfig_json.get('USE_PROXY')
- proxy_host = comfig_json.get('PROXY_HOST')
- proxy_port = comfig_json.get('PROXY_PORT')
- if use_proxy:
- system = platform.system()
- if system == 'Windows':
- env = os.environ.copy()
- command = ['set',
- 'http_proxy=http://{}:{}'.format(proxy_host, proxy_port),
- '&',
- 'set',
- 'https_proxy=http://{}:{}'.format(proxy_host, proxy_port)
- ]
- elif system == 'Darwin':
- env = os.environ.copy()
- command = ['export',
- 'https_proxy=http://{}:{}'.format(proxy_host, proxy_port),
- 'http_proxy=http://{}:{}'.format(proxy_host, proxy_port),
- 'all_proxy=socks5://{}:{}'.format(proxy_host, proxy_port)
- ]
- elif system == 'Linux':
- env = os.environ.copy()
- command = ['export',
- 'https_proxy=http://{}:{}'.format(proxy_host, proxy_port),
- 'http_proxy=http://{}:{}'.format(proxy_host, proxy_port),
- 'all_proxy=socks5://{}:{}'.format(proxy_host, proxy_port)
- ]
- else:
- print("未知操作系统")
- exit(0)
- result = subprocess.run(command, text=True, capture_output=True)
- print(result)
|