Simple Linux Panel
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mdserver-web/plugins/csvn/index.py

160 lines
3.4 KiB

7 years ago
# coding: utf-8
import time
import random
import os
import urllib
import binascii
import json
import re
7 years ago
import sys
sys.path.append(os.getcwd() + "/class/core")
import public
7 years ago
7 years ago
app_debug = False
if public.getOs() == 'darwin':
app_debug = True
7 years ago
def getPluginName():
return 'csvn'
def getPluginDir():
return public.getPluginDir() + '/' + getPluginName()
def getServerDir():
return public.getServerDir() + '/' + getPluginName()
def getInitDFile():
if app_debug:
return '/tmp/' + getPluginName()
return '/etc/init.d/' + getPluginName()
7 years ago
def getArgs():
args = sys.argv[2:]
tmp = {}
for i in range(len(args)):
t = args[i].split(':')
tmp[t[0]] = t[1]
return tmp
def initDreplace():
7 years ago
initd_file = getInitDFile()
7 years ago
7 years ago
if not os.path.exists(initd_file):
return getServerDir()
7 years ago
7 years ago
return initd_file
7 years ago
7 years ago
def status():
7 years ago
data = public.execShell(
"ps -ef|grep " + getPluginName() + " |grep -v grep | grep -v python | awk '{print $2}'")
if data[0] == '':
return 'stop'
7 years ago
return 'start'
7 years ago
7 years ago
def csvnOp(method):
_initd_csvn = '/etc/init.d/csvn'
_initd_csvn_httpd = '/etc/init.d/csvn-httpd'
ret_csvn = public.execShell(_initd_csvn + ' ' + method)
ret_csvn_httpd = public.execShell(_initd_csvn + ' ' + method)
7 years ago
if ret_csvn[1] == '' and ret_csvn_httpd[1] == '':
7 years ago
return 'ok'
return 'fail'
7 years ago
def start():
return csvnOp('start')
7 years ago
def stop():
7 years ago
return csvnOp('stop')
7 years ago
def restart():
7 years ago
return csvnOp('restart')
7 years ago
def reload():
7 years ago
return csvnOp('reload')
7 years ago
def initdStatus():
if not app_debug:
os_name = public.getOs()
if os_name == 'darwin':
return "Apple Computer does not support"
7 years ago
_initd_csvn = '/etc/init.d/csvn'
_initd_csvn_httpd = '/etc/init.d/csvn-httpd'
if os.path.exists(_initd_csvn) and os.path.exists(_initd_csvn_httpd):
7 years ago
return 'ok'
return 'fail'
def initdInstall():
import shutil
if not app_debug:
os_name = public.getOs()
if os_name == 'darwin':
return "Apple Computer does not support"
7 years ago
_csvn = getServerDir() + '/bin/csvn'
_csvn_httpd = getServerDir() + '/bin/csvn-httpd'
public.execShell(_csvn + ' install')
public.execShell(_csvn_httpd + ' install')
return 'ok'
def initdUinstall():
if not app_debug:
os_name = public.getOs()
if os_name == 'darwin':
return "Apple Computer does not support"
_csvn = getServerDir() + '/bin/csvn'
_csvn_httpd = getServerDir() + '/bin/csvn-httpd'
public.execShell(_csvn + ' uninstall')
public.execShell(_csvn_httpd + ' uninstall')
7 years ago
return 'ok'
7 years ago
if __name__ == "__main__":
func = sys.argv[1]
if func == 'status':
print status()
7 years ago
elif func == 'start':
print start()
elif func == 'stop':
print stop()
elif func == 'restart':
print restart()
elif func == 'reload':
print reload()
elif func == 'initd_status':
print initdStatus()
elif func == 'initd_install':
print initdInstall()
elif func == 'initd_uninstall':
print initdUinstall()
elif func == 'run_info':
print runInfo()
elif func == 'conf':
print getConf()
elif func == 'save_conf':
print saveConf()
7 years ago
else:
7 years ago
print 'fail'