1 Star 0 Fork 0

lutt / cliserver

Gitee — Enterprise-level DevOps R&D management platform
Join Gitee
Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

cliserver

简介

cliserver可通过网络套接字提供命令行服务。使用者可将命令行和执行接口函数注册至cliserver,客户端与cliserver建立连接后可发送命令并由cliserver执行。

使用

1.创建服务

create_server(address, family, type)

  • address: (ip地址,端口) 或 unix套接字文件路径
  • family: 同socket的family
  • type: 同socket的type

2.注册命令

cmd_register(cmd_func)

  • cmd_func: 命令行的执行函数,函数的__doc__属性用于描述命令

3.事件调度

dispatcher()

  • epoll事件监听调度函数

示例程序如下:

  • 服务端
import os
import socket
import logging
import cliserver


def cmd_show_version(self, *argv):
    '''show version'''
    self.cmd_output('1.0')


def cmd_set_test_data(self, *argv):
    '''set test ( val1 | val2 ) Data '''
    self.cmd_output(' '.join(argv))


if __name__ == '__main__':
    if os.path.exists('usock'):
        os.unlink('usock')
    logging.basicConfig(level=logging.DEBUG, format='%(name)s %(funcName)s -> %(message)s')
    # server = CliServer(('127.0.0.1', 8888), socket.AF_INET, socket.SOCK_STREAM)
    cliserver.create_server('usock', socket.AF_UNIX, socket.SOCK_STREAM)
    cliserver.cmd_register(cmd_show_version)
    cliserver.cmd_register(cmd_set_test_data)
    cliserver.dispatcher()
  • 客户端
#! /bin/bash

stty -isig -echo -icanon
nc -U usock
stty isig echo icanon

Repository Comments ( 0 )

Sign in for post a comment

About

简单交互式命令服务端 expand collapse
Python
GPL-3.0
Cancel

Releases

No release

Contributors

All

Activities

load more
can not load any more
Python
1
https://gitee.com/taotao.lu/cliserver.git
git@gitee.com:taotao.lu/cliserver.git
taotao.lu
cliserver
cliserver
master

Search

181749 a2d7925e 1850385 181749 9f8568a7 1850385