Esempio n. 1
0
    def __init__(self):

        # 获取logger实例,如果参数为空则返回root logger
        self.logger = logging.getLogger()
        log_level_map = {'debug':logging.DEBUG,'info':logging.INFO,'warning':logging.WARNING,'error':logging.ERROR}
        # 指定logger输出格式
        formatter = logging.Formatter('%(asctime)s %(levelname)s: %(message)s')


        if utils.isLinux():
           logfile = "%s/%s/%s" %(base_dir,log_path,log_name)
        else:
           logfile = "%s\\%s\\%s" %(base_dir,log_path,log_name)

        if not self.logger.handlers:
            # 文件日志
            file_handler = logging.FileHandler(logfile)
            file_handler.setFormatter(formatter)  # 可以通过setFormatter指定输出格式

            # 控制台日志
            console_handler = logging.StreamHandler(sys.stdout)
            console_handler.formatter = formatter  # 也可以直接给formatter赋值

            # 为logger添加的日志处理器
            self.logger.addHandler(file_handler)
            self.logger.addHandler(console_handler)

            # 指定日志的最低输出级别,默认为WARN级别
            self.logger.setLevel(log_level_map[logLevel])
Esempio n. 2
0
def getFileFilter():
    """Returns the file filter text of all available data file formats which
    can be used with a file selection dialog UI."""
    extFmt = "(*.{1})"
    if isLinux():
        # the extension in parentheses is not shown on linux, add it here
        extFmt = "*.{1} (*.{1})"
    filefilter = []
    for cls in ArrayFile, PDHFile:
        for descr, ext in cls.fileFilter:
            filefilter.append(("{0} " + extFmt).format(descr, ext))
    return filefilter
Esempio n. 3
0
def getEnvironment():
    import utils

    if utils.useWii():
        import wii
        return wii.getEnvironment()

    if utils.isLinux():
        import unix
        return unix.getEnvironment()
    
    print "Could not determine environment. Defaulting to unix"
    import unix
    return unix.getEnvironment()
Esempio n. 4
0
def run():
    if utils.isLinux() == False:
        return [('ifconfig_collect os type error','this is windows')]
    #not first run
    if os.path.isfile('./oldifconfig'):
        fileold = open('./oldifconfig', 'r')
        fileold.seek(0)
        #读入上次记录的临时流量数据文件,和时间戳
        (oldtime, fileoldcontent) = fileold.read().split('#')
        fileold.close;
        netcard = {}
        tempstr = ''
        key = ''
        for strline in fileoldcontent.split('/n'):
            reobj = re.compile('^lo*.')
            if reobj.search(strline):
                break;
            reobj = re.compile('^eth*.')
            if reobj.search(strline):
                key = strline.split()[0]
            tempstr = tempstr + strline + '/n'
            netcard[key] = tempstr
        RXold = {}
        TXold = {}
        for key,value in netcard.items():
            tempsplit = value.split('/n')
            netcard[key] = ''
            for item in tempsplit:
                item = item + '<br>'
                netcard[key] = netcard[key] + item
                tempcount = 1
                for match in re.finditer("(bytes:)(.*?)( /()", item):
                    if tempcount == 1:
                        RXold[key] = match.group(2)
                        tempcount = tempcount + 1
                    elif tempcount == 2:
                        TXold[key] = match.group(2)
                        netcard[key] = netcard[key] + 'net io percent(bytes/s): 0 <br>'

        #记录当前网卡信息到临时文件中
        os.system('ifconfig > ifconfigtemp')
        file = open('./ifconfigtemp','r');
        fileold = open('./oldifconfig', 'w')
        temptimestr = str(int(time.time()));
        fileold.write(temptimestr)
        fileold.write('#')
        file.seek(0)
        fileold.write(file.read())
        fileold.close()
        returnkeys = []
        returnvalues = []
        netcard = {}
        tempcountcard = 0
        file.seek(0)
        key = ''
        for strline in file.readlines():
            reobj = re.compile('^lo*.')
            if reobj.search(strline):
                break;
            reobj = re.compile('^eth*.')
            if reobj.search(strline):
                key = strline.split()[0]
                netcard[key] = ''
            netcard[key] = netcard[key] + strline
        newnetcard = {}
        file.seek(0)
        key = ''
        for strline in file.readlines():
            reobj = re.compile('^lo*.')
            if reobj.search(strline):
                break;
            if re.search("^eth", strline):
                templist = strline.split()
                key = templist[0]
                newnetcard[key] = ''
                newnetcard[key] = templist[4] + newnetcard[key] + ' '
            if re.search("^ *inet ", strline):
                templist = strline.split()
                newnetcard[key] = templist[1][5:] + ' ' + newnetcard[key] + ' '
        for key,value in newnetcard.items():
            #记录每张网卡是否工作状态信息到临时文件
            os.system('ethtool %s > ethtooltemp'%(key))
            file = open('./ethtooltemp','r');
            tempethtooltemplist = file.read().split('/n/t')
            file.close
            if re.search("yes", tempethtooltemplist[-1]):
                templist = newnetcard[key].split()
                newnetcard[key] = templist[0] + ' runing! ' + templist[1]
            else:
                templist = newnetcard[key].split()
                if len(templist) > 1:
                    newnetcard[key] = templist[0] + ' stop! ' + templist[1]
                else:
                    newnetcard[key] =  'stop! ' + templist[0]
        file.close()
        RX = {}
        TX = {}
        for key,value in netcard.items():
            tempsplit = value.split('/n')
            netcard[key] = ''
            for item in tempsplit:
                item = item + '<br>'
                netcard[key] = netcard[key] + item
                tempcount = 1
                for match in re.finditer("(bytes:)(.*?)( /()", item):
                    if tempcount == 1:
                        RX[key] = str(int(match.group(2)) - int(RXold[key]))
                        tempcount = tempcount + 1
                    elif tempcount == 2:
                        TX[key] = str(int(match.group(2)) - int(TXold[key]))
                        divtime = float(int(time.time()) - int(oldtime))
                        if divtime == 0:
                            rate = (float(TX[key]) + float(RX[key]))
                        else:
                            rate = (float(TX[key]) + float(RX[key]))/(divtime)
                        if rate == 0:
                            newnetcard[key] = '0' + ' ' + newnetcard[key]
                        else:
                            newnetcard[key] = '%.2f'%rate + ' ' + newnetcard[key]
        return zip(['order'], ['48']) + newnetcard.items();
    else:
        os.system('ifconfig > ifconfigtemp')
        file = open('./ifconfigtemp','r');
        fileold = open('./oldifconfig', 'w')
        temptimestr = str(int(time.time()));
        fileold.write(temptimestr)
        fileold.write('#')
        file.seek(0)
        fileold.write(file.read())
        fileold.close()

        netcard = {}
        file.seek(0)
        key = ''
        for strline in file.readlines():
            reobj = re.compile('^lo*.')
            if reobj.search(strline):
                break;
            reobj = re.compile('^eth*.')
            if reobj.search(strline):
                key = strline.split()[0]
                netcard[key] = ''
            netcard[key] = netcard[key] + strline
        RX = {}
        TX = {}

        key = ''
        newnetcard = {}
        file.seek(0)
        for strline in file.readlines():
            reobj = re.compile('^lo*.')
            if reobj.search(strline):
                break;
            if re.search("^eth", strline):
                templist = strline.split()
                key = templist[0]
                newnetcard[key] = templist[4] + ' '
            if re.search("^ *inet ", strline):
                templist = strline.split()
                newnetcard[key] = newnetcard[key] + templist[1][5:] + ' '
        for key,value in newnetcard.items():
            os.system('ethtool %s > ethtooltemp'%(key))
            file = open('./ethtooltemp','r');
            tempethtooltemplist = file.read().split('/n')
            file.close
            if re.search("yes", tempethtooltemplist[-1]):
                newnetcard[key] = newnetcard[key] + 'runing!'
            else:
                newnetcard[key] = newnetcard[key] + 'stop!'
        file.close()
        for key,value in netcard.items():
            tempsplit = value.split('/n')
            netcard[key] = ''
            for item in tempsplit:
                item = item + '<br>'
                #print item
                netcard[key] = netcard[key] + item
                tempcount = 1
                for match in re.finditer("(bytes:)(.*?)( /()", item):
                    if tempcount == 1:
                        RX[key] = match.group(2)
                        tempcount = tempcount + 1
                    elif tempcount == 2:
                        TX[key] = match.group(2)
                        netcard[key] = netcard[key] + 'net io percent(bytes/s): 0 <br>'
                        newnetcard[key] = newnetcard[key] + ' ' + '0 <br>'
        return zip(['order'], ['48']) + newnetcard.items();
Esempio n. 5
0
    archiver = None
    # TODO: perhaps switch to pythons builtin zip?
    if isWindows():
        archiver = Archiver7z(filetype="zip")
    else:
        archiver = ArchiverZip()

    PACKAGENAME = "{name} {ver}".format(name=version.name(),
                                        ver=version.number())
    # target (temp) dir for mcsas package
    sysname = platform.system().title()
    if "darwin" in sysname.lower():
        sysname = "MacOS"
    TARGETDIR = "{pckg} for {sysname}".format(pckg=PACKAGENAME,
                                              sysname=sysname)
    if isLinux():
        bitness, binfmt = platform.architecture()
        TARGETDIR += " " + bitness

    BASE = None
    EXEC_SUFFIX = ""
    if sys.platform in "win32":
        BASE = "Win32GUI"
        EXEC_SUFFIX = ".exe"

    TARGETNAME = version.name() + EXEC_SUFFIX

    # (source, target) pairs
    # without a target the file is placed in the top level directory of the package
    INCLUDEFILES = [
        "mcsas/mcsasparameters.json",
Esempio n. 6
0
# get script/executable location, add to module search path
SCRIPT_PATH, SCRIPT_FILENAME = getScriptPath()
if not hasattr(sys, "frozen") and SCRIPT_PATH not in sys.path:
    sys.path.append(SCRIPT_PATH)
    # FIXME? sphinx assumes the upper directory as root,
    # prefixes every module path with *mcsas*
    # -> do it the same way? Would simplify some things ...

import argparse
import logging
import multiprocessing
from log import replaceStdOutErr
from utils import isMac, isLinux

if (isLinux() and hasattr(sys, "frozen")
        and "LD_LIBRARY_PATH" not in os.environ):
    os.environ["LD_LIBRARY_PATH"] = SCRIPT_PATH


def makeAbsolutePath(relpath):
    return os.path.abspath(os.path.join(SCRIPT_PATH, relpath))


def main(argv=None):
    parser = argparse.ArgumentParser(description="Monte Carlo SAS analysis")
    parser.add_argument("-t",
                        "--text",
                        action="store_true",
                        help="Run in text mode without graphical "
                        "user interface")