first add files
This commit is contained in:
24
bin/ci
Executable file
24
bin/ci
Executable file
@@ -0,0 +1,24 @@
|
||||
#!/bin/sh
|
||||
# ci (GNU RCS) 5.9.0
|
||||
#
|
||||
# Copyright (C) 2013 Thien-Thi Nguyen
|
||||
#
|
||||
# This file is part of GNU RCS.
|
||||
#
|
||||
# GNU RCS is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# GNU RCS is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty
|
||||
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
d=`echo "$0" | sed 's|[^/]*$||'`
|
||||
exec "$d"rcs ci "$@"
|
||||
|
||||
# ci ends here
|
||||
24
bin/co
Executable file
24
bin/co
Executable file
@@ -0,0 +1,24 @@
|
||||
#!/bin/sh
|
||||
# co (GNU RCS) 5.9.0
|
||||
#
|
||||
# Copyright (C) 2013 Thien-Thi Nguyen
|
||||
#
|
||||
# This file is part of GNU RCS.
|
||||
#
|
||||
# GNU RCS is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# GNU RCS is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty
|
||||
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
d=`echo "$0" | sed 's|[^/]*$||'`
|
||||
exec "$d"rcs co "$@"
|
||||
|
||||
# co ends here
|
||||
BIN
bin/dd_extract
Executable file
BIN
bin/dd_extract
Executable file
Binary file not shown.
BIN
bin/dd_list
Executable file
BIN
bin/dd_list
Executable file
Binary file not shown.
BIN
bin/lsscsi
Executable file
BIN
bin/lsscsi
Executable file
Binary file not shown.
24
bin/rcsclean
Executable file
24
bin/rcsclean
Executable file
@@ -0,0 +1,24 @@
|
||||
#!/bin/sh
|
||||
# rcsclean (GNU RCS) 5.9.0
|
||||
#
|
||||
# Copyright (C) 2013 Thien-Thi Nguyen
|
||||
#
|
||||
# This file is part of GNU RCS.
|
||||
#
|
||||
# GNU RCS is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# GNU RCS is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty
|
||||
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
d=`echo "$0" | sed 's|[^/]*$||'`
|
||||
exec "$d"rcs rcsclean "$@"
|
||||
|
||||
# rcsclean ends here
|
||||
24
bin/rcsdiff
Executable file
24
bin/rcsdiff
Executable file
@@ -0,0 +1,24 @@
|
||||
#!/bin/sh
|
||||
# rcsdiff (GNU RCS) 5.9.0
|
||||
#
|
||||
# Copyright (C) 2013 Thien-Thi Nguyen
|
||||
#
|
||||
# This file is part of GNU RCS.
|
||||
#
|
||||
# GNU RCS is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# GNU RCS is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty
|
||||
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
d=`echo "$0" | sed 's|[^/]*$||'`
|
||||
exec "$d"rcs rcsdiff "$@"
|
||||
|
||||
# rcsdiff ends here
|
||||
132
bin/rcsfreeze
Executable file
132
bin/rcsfreeze
Executable file
@@ -0,0 +1,132 @@
|
||||
#! /bin/sh
|
||||
# rcsfreeze - assign a symbolic revision number to a configuration of RCS files
|
||||
#
|
||||
# Copyright (C) 2010-2013 Thien-Thi Nguyen
|
||||
#
|
||||
# This file is part of GNU RCS.
|
||||
#
|
||||
# GNU RCS is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# GNU RCS is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty
|
||||
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
##
|
||||
# Usage: rcsfreeze [symbolic-name]
|
||||
#
|
||||
# The idea is to run rcsfreeze each time a new version is checked
|
||||
# in. A unique symbolic revision number (C_[number], where number
|
||||
# is increased each time rcsfreeze is run) is then assigned to the most
|
||||
# recent revision of each RCS file of the main trunk.
|
||||
#
|
||||
# If the command is invoked with an argument, then this
|
||||
# argument is used as the symbolic name to freeze a configuration.
|
||||
# The unique identifier is still generated
|
||||
# and is listed in the log file but it will not appear as
|
||||
# part of the symbolic revision name in the actual RCS file.
|
||||
#
|
||||
# A log message is requested from the user which is saved for future
|
||||
# references.
|
||||
#
|
||||
# The shell script works only on all RCS files at one time.
|
||||
# It is important that all changed files are checked in (there are
|
||||
# no precautions against any error in this respect).
|
||||
# file names:
|
||||
# {RCS/}.rcsfreeze.ver version number
|
||||
# {RCS/}.rscfreeze.log log messages, most recent first
|
||||
##
|
||||
version='rcsfreeze (GNU RCS) 5.9.0
|
||||
Copyright (C) 2010-2013 Thien-Thi Nguyen
|
||||
Copyright (C) 1990-1995 Paul Eggert
|
||||
License GPLv3+; GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
|
||||
This is free software: you are free to change and redistribute it.
|
||||
There is NO WARRANTY, to the extent permitted by law.
|
||||
|
||||
Written by Stephan v. Bechtolsheim.'
|
||||
|
||||
usage ()
|
||||
{
|
||||
sed '/^##/,/^##/!d;/^##/d;s/^# //g;s/^#$//g' $0
|
||||
}
|
||||
|
||||
if [ x"$1" = x--help ] ; then usage ; exit 0 ; fi
|
||||
if [ x"$1" = x--version ] ; then echo "$version" ; exit 0 ; fi
|
||||
|
||||
PATH=/usr/local/bin:/bin:/usr/bin:/usr/ucb:$PATH
|
||||
export PATH
|
||||
|
||||
DATE=`date` || exit
|
||||
# Check whether we have an RCS subdirectory, so we can have the right
|
||||
# prefix for our paths.
|
||||
if test -d RCS
|
||||
then RCSDIR=RCS/ EXT=
|
||||
else RCSDIR= EXT=,v
|
||||
fi
|
||||
|
||||
# Version number stuff, log message file
|
||||
VERSIONFILE=${RCSDIR}.rcsfreeze.ver
|
||||
LOGFILE=${RCSDIR}.rcsfreeze.log
|
||||
# Initialize, rcsfreeze never run before in the current directory
|
||||
test -r $VERSIONFILE || { echo 0 >$VERSIONFILE && >>$LOGFILE; } || exit
|
||||
|
||||
# Get Version number, increase it, write back to file.
|
||||
VERSIONNUMBER=`cat $VERSIONFILE` &&
|
||||
VERSIONNUMBER=`expr $VERSIONNUMBER + 1` &&
|
||||
echo $VERSIONNUMBER >$VERSIONFILE || exit
|
||||
|
||||
# Symbolic Revision Number
|
||||
SYMREV=C_$VERSIONNUMBER
|
||||
# Allow the user to give a meaningful symbolic name to the revision.
|
||||
SYMREVNAME=${1-$SYMREV}
|
||||
echo >&2 "rcsfreeze: symbolic revision number computed: \"${SYMREV}\"
|
||||
rcsfreeze: symbolic revision number used: \"${SYMREVNAME}\"
|
||||
rcsfreeze: the two differ only when rcsfreeze invoked with argument
|
||||
rcsfreeze: give log message, summarizing changes (end with EOF or single '.')" \
|
||||
|| exit
|
||||
|
||||
# Stamp the logfile. Because we order the logfile the most recent
|
||||
# first we will have to save everything right now in a temporary file.
|
||||
TMPLOG=`mktemp -t` || exit
|
||||
trap 'rm -f $TMPLOG; exit 1' 1 2 13 15
|
||||
# Now ask for a log message, continously add to the log file
|
||||
(
|
||||
echo "Version: $SYMREVNAME($SYMREV), Date: $DATE
|
||||
-----------" || exit
|
||||
while read MESS
|
||||
do
|
||||
case $MESS in
|
||||
.) break
|
||||
esac
|
||||
echo " $MESS" || exit
|
||||
done
|
||||
echo "-----------
|
||||
" &&
|
||||
cat $LOGFILE
|
||||
) >$TMPLOG &&
|
||||
|
||||
# combine old and new logfiles
|
||||
cp $TMPLOG $LOGFILE &&
|
||||
rm -f $TMPLOG &&
|
||||
|
||||
# Now the real work begins by assigning a symbolic revision number
|
||||
# to each rcs file. Take the most recent version on the default branch.
|
||||
|
||||
# If there are any .*,v files, throw them in too.
|
||||
# But ignore RCS/.* files that do not end in ,v.
|
||||
DOTFILES=
|
||||
for DOTFILE in ${RCSDIR}.*,v
|
||||
do
|
||||
if test -f "$DOTFILE"
|
||||
then
|
||||
DOTFILES="${RCSDIR}.*,v"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
exec rcs -q -n$SYMREVNAME: ${RCSDIR}*$EXT $DOTFILES
|
||||
24
bin/rcsmerge
Executable file
24
bin/rcsmerge
Executable file
@@ -0,0 +1,24 @@
|
||||
#!/bin/sh
|
||||
# rcsmerge (GNU RCS) 5.9.0
|
||||
#
|
||||
# Copyright (C) 2013 Thien-Thi Nguyen
|
||||
#
|
||||
# This file is part of GNU RCS.
|
||||
#
|
||||
# GNU RCS is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# GNU RCS is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty
|
||||
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
d=`echo "$0" | sed 's|[^/]*$||'`
|
||||
exec "$d"rcs rcsmerge "$@"
|
||||
|
||||
# rcsmerge ends here
|
||||
24
bin/rlog
Executable file
24
bin/rlog
Executable file
@@ -0,0 +1,24 @@
|
||||
#!/bin/sh
|
||||
# rlog (GNU RCS) 5.9.0
|
||||
#
|
||||
# Copyright (C) 2013 Thien-Thi Nguyen
|
||||
#
|
||||
# This file is part of GNU RCS.
|
||||
#
|
||||
# GNU RCS is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# GNU RCS is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty
|
||||
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
d=`echo "$0" | sed 's|[^/]*$||'`
|
||||
exec "$d"rcs rlog "$@"
|
||||
|
||||
# rlog ends here
|
||||
153
bin/sunhpc
Executable file
153
bin/sunhpc
Executable file
@@ -0,0 +1,153 @@
|
||||
#!/opt/sunpy3/bin/python3
|
||||
#coding:utf-8
|
||||
|
||||
import os
|
||||
import sys
|
||||
import pwd
|
||||
import sunhpc
|
||||
import syslog
|
||||
import shutil
|
||||
import sunhpc.invoke
|
||||
|
||||
if sys.getdefaultencoding() != 'utf-8':
|
||||
reload(sys)
|
||||
sys.setdefaultencoding('utf-8')
|
||||
|
||||
def ttySize():
|
||||
try:
|
||||
(width, heigh) = shutil.get_terminal_size()
|
||||
except:
|
||||
width = 80
|
||||
return width
|
||||
|
||||
os.environ['COLUMNS'] = str(ttySize())
|
||||
syslog.openlog('SunhpcCMD', syslog.LOG_PID, syslog.LOG_LOCAL0)
|
||||
|
||||
try:
|
||||
import sqlalchemy
|
||||
import sunhpc.db.helper
|
||||
|
||||
database = sunhpc.db.helper.DatabaseHelper()
|
||||
database.connect()
|
||||
|
||||
except ImportError:
|
||||
raise
|
||||
except sqlalchemy.exc.OperationalError:
|
||||
raise
|
||||
|
||||
# 如果参数为空,应当主动赋值帮助,就当成sunhpc help命令.
|
||||
if len(sys.argv) == 1:
|
||||
args = [ 'list', 'help']
|
||||
else:
|
||||
args = sys.argv[1:]
|
||||
#
|
||||
# 如果这个sunhpc 没有参数, 则使用 sunhpc list help
|
||||
# 否则, 使用第二个参数, 例如 sunhpc list
|
||||
# 那么 args[0] = 永远指定第二个参数.
|
||||
# 检查命令是否被圈引
|
||||
# sunhpc aa bb -- 那么cmd=['aa']
|
||||
# sunhpc "aa bb" -- 那么cmd=['aa','bb']
|
||||
module = None
|
||||
cmd = args[0].split()
|
||||
|
||||
# 一般不会执行这里.
|
||||
# 只有命令参数带入引号,才会执行此处.
|
||||
# 例如: sunhpc "aa bb" 而 sunhpc aa bb 则跳过此处.
|
||||
if len(cmd) > 1:
|
||||
s = 'sunhpc.commands.%s' % '.'.join(cmd)
|
||||
# 此时模块路径应该是 sunhpc.commands.aa.bb
|
||||
try:
|
||||
# 如果没有此模块,则触发ModuleNotFoundError异常.
|
||||
__import__(s)
|
||||
|
||||
# 如果模块存在,但是报错,应该是头部没有进行import 相关模块.
|
||||
# 触发 NameError 异常.
|
||||
module = eval(s)
|
||||
|
||||
# 设定变量,供后面for递减模块中args列表从第二个参数取值使用.
|
||||
i = 1
|
||||
except:
|
||||
module = None
|
||||
|
||||
# 这里正式开始检查命令参数.
|
||||
if not module:
|
||||
# 递减sunhpc 参数.
|
||||
for i in range(len(args), 0, -1):
|
||||
s = 'sunhpc.commands.%s' % '.'.join(args[:i])
|
||||
# sunhpc.commands.aa.bb
|
||||
# sunhpc.commands.aa
|
||||
try:
|
||||
# 倒序检查模块是否存在.
|
||||
__import__(s)
|
||||
module = eval(s)
|
||||
if module:
|
||||
# 如果找到模块,那么其余的参数,就会作为模块参数提供给此模块.
|
||||
break
|
||||
except ImportError:
|
||||
continue
|
||||
|
||||
# 如果没有找到提供的任何模块,则命令执行失败.
|
||||
if not module:
|
||||
print ('error - invalid sunhpc command "%s"' % args[0])
|
||||
sys.exit(-1)
|
||||
|
||||
# 将模块路径重新转化成命令行形式格式.
|
||||
# sunhpc.commands.aa.bb
|
||||
# sunhpc commands aa bb 去除sunhpc commands.
|
||||
# name = aa bb
|
||||
name = ' '.join(s.split('.')[2:])
|
||||
|
||||
# 此时module已经找到相应的模块了.
|
||||
# module = sunhpc.commands.aa.bb
|
||||
|
||||
try:
|
||||
# 检查module模块是否有Command类,如果没有则触发 AttributeError 异常.
|
||||
command = getattr(module, 'Command')(database)
|
||||
except AttributeError:
|
||||
# 没有Command类,则会执行到此处.到这里我们需要调用帮助信息.
|
||||
#
|
||||
# 此时的bb模块中没有Command类.
|
||||
# 命令:sunhpc aa bb
|
||||
# 已知module路径. sunhpc.commands.aa.bb
|
||||
# 已经name变量, aa bb
|
||||
#
|
||||
# 导入sunhpc帮助模块
|
||||
import sunhpc.commands.list.help
|
||||
help = sunhpc.commands.list.help.Command(database)
|
||||
# 将module路径转换成列表然后使用切片找出模块全路径和子路径.
|
||||
fullmodpath = s.split('.')
|
||||
submodpath = '/'.join(fullmodpath[2:])
|
||||
|
||||
# 执行Command类中run函数.第一个参数是字典,第二个是列表.
|
||||
help.run({'subdir':submodpath}, [])
|
||||
print (help.getText())
|
||||
sys.exit(-1)
|
||||
|
||||
# 如果有Command类, 则执行主模块sunhpc.commands.__init__中的runWapper函数
|
||||
# 两种用途
|
||||
# 1, 收集命令参数并且转换成固定格式.
|
||||
# 2, 开始执行命令入口函数.
|
||||
# 如果触发自定义命令异常,则输出使用帮助信息.
|
||||
if command.MustBeRoot and not (command.isRootUser() or command.isApacheUser()):
|
||||
# 如果需要特权权限, 则需要提权操作.
|
||||
os.system('sudo %s' % ' '.join(sys.argv))
|
||||
else:
|
||||
# 收集参数等信息,然后运行模块run函数,错误则触发CommandError异常.
|
||||
# runWrapper是主模块中的Command类中的入口函数.
|
||||
# name : 当前模块路径.
|
||||
# args : 当前有效模块后面全部视为参数.
|
||||
try:
|
||||
command.runWrapper(name, args[i:])
|
||||
text = command.getText()
|
||||
if len(text) > 0:
|
||||
print (text.rstrip())
|
||||
if text[len(text)-1] != '\n':
|
||||
print ()
|
||||
except sunhpc.core.utils.CommandError as e:
|
||||
msg = ' '.join(str(e).split())
|
||||
#print ("\033[91m[errs] %s\033[0m" % msg)
|
||||
print (msg)
|
||||
print (command.usage())
|
||||
exit(1)
|
||||
|
||||
syslog.closelog()
|
||||
167
bin/syncDaemon
Executable file
167
bin/syncDaemon
Executable file
@@ -0,0 +1,167 @@
|
||||
#!/opt/sunpy3/bin/python3
|
||||
#coding:utf-8
|
||||
import os, sys, time, queue
|
||||
import pickle, base64, shutil, tempfile
|
||||
import logging, random, argparse, configparser
|
||||
from multiprocessing.managers import BaseManager
|
||||
class QueueManager(BaseManager):
|
||||
pass
|
||||
s_queue = queue.Queue()
|
||||
r_queue = queue.Queue()
|
||||
|
||||
class Application(object):
|
||||
|
||||
def __init__(self):
|
||||
|
||||
self.conf = '/etc/sunhpc-plugin.conf'
|
||||
self.addr = None
|
||||
self.port = None
|
||||
self.keys = None
|
||||
self.conn = None
|
||||
self.send = None
|
||||
self.recv = None
|
||||
|
||||
self.modules = {}
|
||||
self.logfile = '/opt/sunhpc/logs/syncdaemon.log'
|
||||
|
||||
def config(self):
|
||||
config = configparser.ConfigParser()
|
||||
if os.path.exists(self.conf):
|
||||
try:
|
||||
config.read(self.conf)
|
||||
self.addr = config['plugins']['address']
|
||||
self.port = int(config['plugins']['port'])
|
||||
self.keys = config['plugins']['keys'].encode('utf-8')
|
||||
except KeyError as e:
|
||||
self.exelog('Read "/etc/sunhpc-plugin.conf error - %s' % repr(e))
|
||||
|
||||
def parseArgs(self):
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--addr', metavar='addr', nargs='?', help='IP address')
|
||||
parser.add_argument('--port', metavar='port', nargs='?', help='IP port')
|
||||
parser.add_argument('--keys', metavar='keys', nargs='?', help='Secret key')
|
||||
parser.add_argument('--conf', metavar='conf', nargs='?', help='Config file')
|
||||
|
||||
args = parser.parse_args()
|
||||
if args.addr:
|
||||
self.addr = args.addr
|
||||
if args.port:
|
||||
self.port = args.port
|
||||
if args.keys:
|
||||
self.keys = args.keys.encode('utf-8')
|
||||
if args.conf:
|
||||
self.conf = args.conf
|
||||
|
||||
def register(self):
|
||||
QueueManager.register('send_queue', callable=lambda: s_queue)
|
||||
QueueManager.register('recv_queue', callable=lambda: r_queue)
|
||||
manager = QueueManager(address=(self.addr, self.port), authkey=self.keys)
|
||||
return manager
|
||||
|
||||
def connect(self):
|
||||
self.conn = self.register()
|
||||
self.conn.start()
|
||||
self.send = self.conn.send_queue()
|
||||
self.recv = self.conn.recv_queue()
|
||||
|
||||
def load_plugins(self):
|
||||
plugin_path = '/opt/sunhpc/var/plugins/syncdata'
|
||||
sys.path.append(plugin_path)
|
||||
tmpdirs = tempfile.mkdtemp()
|
||||
self.modules['temp'] = tmpdirs
|
||||
self.modules['path'] = plugin_path
|
||||
self.modules['plugins'] = []
|
||||
|
||||
for plugin_file in os.listdir(plugin_path):
|
||||
plugin_dict = {}
|
||||
if not plugin_file.endswith('.py'):
|
||||
continue
|
||||
|
||||
if plugin_file in ['plugins.py']:
|
||||
fn = os.path.join(plugin_path, plugin_file)
|
||||
with open(fn, 'rb') as f:
|
||||
self.modules['init'] = base64.b64encode(f.read())
|
||||
continue
|
||||
|
||||
p = plugin_file.split('.py')[0]
|
||||
plugin = __import__(p).plugin()
|
||||
plugin_dict['file'] = plugin_file
|
||||
plugin_dict['modname'] = p
|
||||
# 获取src开头函数名称作为模块字典中 key.
|
||||
# src函数在服务器端执行后放入字典中 value.
|
||||
for fname in plugin.get_srcfuncname(plugin):
|
||||
plugin_n = getattr(plugin, fname)
|
||||
plugin_dict[fname] = plugin_n()
|
||||
|
||||
# 只获取set开头函数并且放入模块字典中.
|
||||
# set函数在客户端中执行.
|
||||
for setname in plugin.get_setfuncname(plugin):
|
||||
plugin_dict[setname] = None
|
||||
|
||||
filename = os.path.join(plugin_path, plugin_file)
|
||||
with open(filename, 'rb') as f:
|
||||
content = base64.b64encode(f.read())
|
||||
plugin_dict['source'] = content
|
||||
|
||||
self.modules['plugins'].append(plugin_dict)
|
||||
|
||||
shutil.rmtree(tmpdirs)
|
||||
|
||||
def running(self):
|
||||
|
||||
print ('addr -- %s' % self.addr)
|
||||
print ('port -- %s' % self.port)
|
||||
self.outputlog('start the syncdaemon...')
|
||||
self.connect()
|
||||
if not self.modules:
|
||||
self.load_plugins()
|
||||
|
||||
data = pickle.dumps(self.modules)
|
||||
running = 1
|
||||
while running:
|
||||
time.sleep(1)
|
||||
try:
|
||||
self.send.put(data)
|
||||
result = self.recv.get(timeout=3)
|
||||
if result == 'exit':
|
||||
running = 0
|
||||
|
||||
self.outputlog(result)
|
||||
except queue.Empty:
|
||||
pass
|
||||
|
||||
self.conn.shutdown()
|
||||
self.outputlog('end the syncdaemon...')
|
||||
|
||||
def outputlog(self, s):
|
||||
log_format = "%(asctime)s %(name)s %(levelname)s %(message)s"
|
||||
dateformat = '%Y-%m-%d %H:%M:%S %a'
|
||||
logging.basicConfig(
|
||||
level = logging.DEBUG,
|
||||
format = log_format,
|
||||
datefmt = dateformat,
|
||||
filename = self.logfile
|
||||
)
|
||||
if s:
|
||||
logging.info(s)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
#
|
||||
# 使用createKeys函数创建一个16位秘钥.
|
||||
# 如果想创建一个新的秘钥,那么删除
|
||||
# /opt/sunhpc/data/.daemon_keys 文件.
|
||||
# 将会重新创建一个新的秘钥.
|
||||
#
|
||||
# syncDaemon --addr 127.0.0.1 --port 5000
|
||||
#
|
||||
app = Application()
|
||||
app.config()
|
||||
app.parseArgs()
|
||||
app.running()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user