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)
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)
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'
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'
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'
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
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
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'
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
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))
def test(): print(sys.version_info) print(session) os = mw.getOs() print(os) return mw.getLocalIp()
def getDirSize(self, path): if mw.getOs() == 'darwin': tmp = mw.execShell('du -sh ' + path) else: tmp = mw.execShell('du -sbh ' + path) return tmp
def test(): print sys.version_info print session os = mw.getOs() print os return mw.getLocalIp()