<filename>serverTemplate.py
#!/bin/python
## need to install alicptfts first
import alicptfts, os, click
import tqdm
## the available High level commands are written in shell and serverShell
from HLshell.mycmd_1 import serverShell, shell



'''
cmd can be a list: ['cmd', par1, par2...]
or a string: 'cmd par1 par2...'
packet byte should be string
'''
def myencode(*cmd):
    ## encode the command into packet
    return cmd

def mydecode(byte):
    ## decode the packet into command
    return byte

class GCSserver():
    shell = serverShell()

    ## connect FTS first
    def FTSconnect(self,port=8001):
        shell.do_connect(port)

    ## send the command to client if connected
    def sendCMD(self,cmdline):
        bpar = myencode(cmdline)

        ## send the command
        shell.do_send(bpar)

        ## if we run scanning, call the function to recieve data file
        ## just a test, it's not run in background
        if ('FTSscan' in cmdline):
            shell.recieveFile(filename='',buffersize=4096,printProgress=True)

## wrap with class
#pass_shell = click.make_pass_decorator(GCSserver,ensure=True)
pass_shell = click.make_pass_decorator(serverShell,ensure=True)

@click.group()
@click.option('--debug', 'debug_mode', default=False, help='print out more information for debugging')
@click.pass_context
def FTSmain(ctx):
    ctx.obj = serverShell(debug_mode=debug_mode)

@FTSmain.command()
@click.option('-i','--ip',default=81,type=int,help='TCP/UDP port')
@click.option('-t','--timeout',default=30,type=float,help='timeout')
@pass_shell
def connect(shell,ip,timeout):
    shell.do_connect(ip, timeout)

@FTSmain.command()
@click.argument('name',required=True,type=float)
@click.argument('vec',required=True,type=float)
@click.argument('acc',required=True,type=float)
@pass_shell
def setting(shell,name,vec,acc):
    cmd = 'FTSsettings ' + ' '.join([name,vec,acc])
    output = []
    shell.do_send(cmd,output)
    re, out, err = output ## pass by ref
    ## run in local
    #shell.do_FTSsettings([name,vec,acc])
<filename>serverTemplate.py
#!/bin/python
## need to install alicptfts first
import alicptfts, os, click
import tqdm
## the available High level commands are written in shell and serverShell
from HLshell.mycmd_1 import serverShell, shell



'''
cmd can be a list: ['cmd', par1, par2...]
or a string: 'cmd par1 par2...'
packet byte should be string
'''
def myencode(*cmd):
    ## encode the command into packet
    return cmd

def mydecode(byte):
    ## decode the packet into command
    return byte

class GCSserver():
    shell = serverShell()

    ## connect FTS first
    def FTSconnect(self,port=8001):
        shell.do_connect(port)

    ## send the command to client if connected
    def sendCMD(self,cmdline):
        bpar = myencode(cmdline)

        ## send the command
        shell.do_send(bpar)

        ## if we run scanning, call the function to recieve data file
        ## just a test, it's not run in background
        if ('FTSscan' in cmdline):
            shell.recieveFile(filename='',buffersize=4096,printProgress=True)

## wrap with class
#pass_shell = click.make_pass_decorator(GCSserver,ensure=True)
pass_shell = click.make_pass_decorator(serverShell,ensure=True)

@click.group()
@click.option('--debug', 'debug_mode', default=False, help='print out more information for debugging')
@click.pass_context
def FTSmain(ctx):
    ctx.obj = serverShell(debug_mode=debug_mode)

@FTSmain.command()
@click.option('-i','--ip',default=81,type=int,help='TCP/UDP port')
@click.option('-t','--timeout',default=30,type=float,help='timeout')
@pass_shell
def connect(shell,ip,timeout):
    shell.do_connect(ip, timeout)

@FTSmain.command()
@click.argument('name',required=True,type=float)
@click.argument('vec',required=True,type=float)
@click.argument('acc',required=True,type=float)
@pass_shell
def setting(shell,name,vec,acc):
    cmd = 'FTSsettings ' + ' '.join([name,vec,acc])
    output = []
    shell.do_send(cmd,output)
    re, out, err = output ## pass by ref
    ## run in local
    #shell.do_FTSsettings([name,vec,acc])
#!/bin/python ## need to install alicptfts first ## the available High level commands are written in shell and serverShell cmd can be a list: ['cmd', par1, par2...] or a string: 'cmd par1 par2...' packet byte should be string ## encode the command into packet ## decode the packet into command ## connect FTS first ## send the command to client if connected ## send the command ## if we run scanning, call the function to recieve data file ## just a test, it's not run in background ## wrap with class #pass_shell = click.make_pass_decorator(GCSserver,ensure=True) ## pass by ref ## run in local #shell.do_FTSsettings([name,vec,acc])