mirror of https://github.com/midoks/mdserver-web
parent
2804d0ed24
commit
d988ce55b1
@ -0,0 +1,77 @@ |
|||||||
|
# coding:utf-8 |
||||||
|
|
||||||
|
# --------------------------------------------------------------------------------- |
||||||
|
# MW-Linux面板 |
||||||
|
# --------------------------------------------------------------------------------- |
||||||
|
# copyright (c) 2018-∞(https://github.com/midoks/mdserver-web) All rights reserved. |
||||||
|
# --------------------------------------------------------------------------------- |
||||||
|
# Author: midoks <midoks@163.com> |
||||||
|
# --------------------------------------------------------------------------------- |
||||||
|
|
||||||
|
# --------------------------------------------------------------------------------- |
||||||
|
# 核心方法库 |
||||||
|
# --------------------------------------------------------------------------------- |
||||||
|
|
||||||
|
|
||||||
|
import os |
||||||
|
import sys |
||||||
|
import time |
||||||
|
import string |
||||||
|
import json |
||||||
|
import hashlib |
||||||
|
import shlex |
||||||
|
import datetime |
||||||
|
import subprocess |
||||||
|
import glob |
||||||
|
import base64 |
||||||
|
import re |
||||||
|
|
||||||
|
from random import Random |
||||||
|
|
||||||
|
def execShell(cmdstring, cwd=None, timeout=None, shell=True): |
||||||
|
|
||||||
|
if shell: |
||||||
|
cmdstring_list = cmdstring |
||||||
|
else: |
||||||
|
cmdstring_list = shlex.split(cmdstring) |
||||||
|
if timeout: |
||||||
|
end_time = datetime.datetime.now() + datetime.timedelta(seconds=timeout) |
||||||
|
|
||||||
|
sub = subprocess.Popen(cmdstring_list, cwd=cwd, stdin=subprocess.PIPE, |
||||||
|
shell=shell, bufsize=4096, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
||||||
|
|
||||||
|
while sub.poll() is None: |
||||||
|
time.sleep(0.1) |
||||||
|
if timeout: |
||||||
|
if end_time <= datetime.datetime.now(): |
||||||
|
raise Exception("Timeout:%s" % cmdstring) |
||||||
|
|
||||||
|
if sys.version_info[0] == 2: |
||||||
|
return sub.communicate() |
||||||
|
|
||||||
|
data = sub.communicate() |
||||||
|
# python3 fix 返回byte数据 |
||||||
|
if isinstance(data[0], bytes): |
||||||
|
t1 = str(data[0], encoding='utf-8') |
||||||
|
|
||||||
|
if isinstance(data[1], bytes): |
||||||
|
t2 = str(data[1], encoding='utf-8') |
||||||
|
return (t1, t2) |
||||||
|
|
||||||
|
|
||||||
|
def getTracebackInfo(): |
||||||
|
import traceback |
||||||
|
errorMsg = traceback.format_exc() |
||||||
|
return errorMsg |
||||||
|
|
||||||
|
def getRunDir(): |
||||||
|
return os.getcwd() |
||||||
|
|
||||||
|
def dbSqitePrefix(): |
||||||
|
WIN = sys.platform.startswith('win') |
||||||
|
if WIN: # 如果是 Windows 系统,使用三个斜线 |
||||||
|
prefix = 'sqlite:///' |
||||||
|
else: # 否则使用四个斜线 |
||||||
|
prefix = 'sqlite:////' |
||||||
|
return prefix |
||||||
|
|
Loading…
Reference in new issue