Пример #1
0
 def setFileAccept(self, filename):
     auth = 'www:www'
     if mw.getOs() == 'darwin':
         user = mw.execShell(
             "who | sed -n '2, 1p' |awk '{print $1}'")[0].strip()
         auth = user + ':staff'
     os.system('chown -R ' + auth + ' ' + filename)
     os.system('chmod -R 755 ' + filename)
Пример #2
0
def getOs():
    data = {}
    data['os'] = mw.getOs()
    ng_exe_bin = getServerDir() + "/nginx/sbin/nginx"
    if checkAuthEq(ng_exe_bin, 'root'):
        data['auth'] = True
    else:
        data['auth'] = False
    return mw.getJson(data)
Пример #3
0
def initdUinstall():
    if not app_debug:
        os_name = mw.getOs()
        if os_name == 'darwin':
            return "Apple Computer does not support"
    initd_bin = getInitDFile()
    os.remove(initd_bin)
    mw.execShell('chkconfig --del ' + getPluginName())
    return 'ok'
Пример #4
0
def initdStatus():
    if not app_debug:
        os_name = mw.getOs()
        if os_name == 'darwin':
            return "Apple Computer does not support"
    initd_bin = getInitDFile()
    if os.path.exists(initd_bin):
        return 'ok'
    return 'fail'
Пример #5
0
def initdInstall():
    import shutil
    if not app_debug:
        os_name = mw.getOs()
        if os_name == 'darwin':
            return "Apple Computer does not support"

    mem_bin = initDreplace()
    initd_bin = getInitDFile()
    shutil.copyfile(mem_bin, initd_bin)
    mw.execShell('chmod +x ' + initd_bin)
    mw.execShell('chkconfig --add ' + getPluginName())
    return 'ok'
Пример #6
0
    def getSystemVersion(self):
        # 取操作系统版本
        if mw.getOs() == 'darwin':
            data = mw.execShell('sw_vers')[0]
            data_list = data.strip().split("\n")
            mac_version = ''
            for x in data_list:
                mac_version += x.split("\t")[1] + ' '
            return mac_version

        version = mw.readFile('/etc/redhat-release')
        if not version:
            version = mw.readFile('/etc/issue').strip().split("\n")[0].replace(
                '\\n', '').replace('\l', '').strip()
        else:
            version = version.replace('release ', '').strip()
        return version
Пример #7
0
    def getMemInfo(self):
        # 取内存信息
        mem = psutil.virtual_memory()
        if mw.getOs() == 'darwin':
            memInfo = {'memTotal': mem.total / 1024 / 1024}
            memInfo['memRealUsed'] = memInfo['memTotal'] * (mem.percent / 100)
        else:
            memInfo = {
                'memTotal': mem.total / 1024 / 1024,
                'memFree': mem.free / 1024 / 1024,
                'memBuffers': mem.buffers / 1024 / 1024,
                'memCached': mem.cached / 1024 / 1024
            }

            memInfo['memRealUsed'] = memInfo['memTotal'] - \
                memInfo['memFree'] - memInfo['memBuffers'] - \
                memInfo['memCached']
        return memInfo
Пример #8
0
def csvnOp(method):

    if app_debug:
        os_name = mw.getOs()
        if os_name == 'darwin':
            return "Apple Computer does not support"

    _initd_csvn = '/etc/init.d/csvn'
    _initd_csvn_httpd = '/etc/init.d/csvn-httpd'
    #_csvn = getServerDir() + '/bin/csvn'
    #_csvn_httpd = getServerDir() + '/bin/csvn-httpd'

    ret_csvn_httpd = mw.execShell(_initd_csvn_httpd + ' ' + method)
    # ret_csvn = mw.execShell(_initd_csvn + ' ' + method)
    subprocess.Popen(_initd_csvn + ' ' + method,
                     stdout=subprocess.PIPE, shell=True)
    if ret_csvn_httpd[1] == '':
        return 'ok'
    return 'fail'
Пример #9
0
    def getMemUsed(self):
        # 取内存使用率
        try:
            import psutil
            mem = psutil.virtual_memory()

            if mw.getOs() == 'darwin':
                return mem.percent

            memInfo = {
                'memTotal': mem.total / 1024 / 1024,
                'memFree': mem.free / 1024 / 1024,
                'memBuffers': mem.buffers / 1024 / 1024,
                'memCached': mem.cached / 1024 / 1024
            }
            tmp = memInfo['memTotal'] - memInfo['memFree'] - \
                memInfo['memBuffers'] - memInfo['memCached']
            tmp1 = memInfo['memTotal'] / 100
            return (tmp / tmp1)
        except Exception, ex:
            return 1
Пример #10
0
def confReplace():
    service_path = os.path.dirname(os.getcwd())
    content = mw.readFile(getConfTpl())
    content = content.replace('{$SERVER_PATH}', service_path)

    user = '******'
    user_group = 'www'

    if mw.getOs() == 'darwin':
        # macosx do
        user = mw.execShell(
            "who | sed -n '2, 1p' |awk '{print $1}'")[0].strip()
        # user = '******'
        user_group = 'staff'
        content = content.replace('{$EVENT_MODEL}', 'kqueue')
    else:
        content = content.replace('{$EVENT_MODEL}', 'epoll')

    content = content.replace('{$OS_USER}', user)
    content = content.replace('{$OS_USER_GROUP}', user_group)

    nconf = getServerDir() + '/nginx/conf/nginx.conf'

    __content = mw.readFile(nconf)
    if __content.find('#user'):
        mw.writeFile(getServerDir() + '/nginx/conf/nginx.conf', content)

    # give nginx root permission
    ng_exe_bin = getServerDir() + "/nginx/sbin/nginx"
    if not checkAuthEq(ng_exe_bin, 'root'):
        args = getArgs()
        sudoPwd = args['pwd']
        cmd_own = 'chown -R ' + 'root:' + user_group + ' ' + ng_exe_bin
        os.system('echo %s|sudo -S %s' % (sudoPwd, cmd_own))
        cmd_mod = 'chmod 755 ' + ng_exe_bin
        os.system('echo %s|sudo -S %s' % (sudoPwd, cmd_mod))
        cmd_s = 'chmod u+s ' + ng_exe_bin
        os.system('echo %s|sudo -S %s' % (sudoPwd, cmd_s))
Пример #11
0
def test():
    print(sys.version_info)
    print(session)
    os = mw.getOs()
    print(os)
    return mw.getLocalIp()
Пример #12
0
 def getDirSize(self, path):
     if mw.getOs() == 'darwin':
         tmp = mw.execShell('du -sh ' + path)
     else:
         tmp = mw.execShell('du -sbh ' + path)
     return tmp
Пример #13
0
def test():
    print sys.version_info
    print session
    os = mw.getOs()
    print os
    return mw.getLocalIp()