Skip to content

How to contribute to LEPV backend

linuxep edited this page Oct 19, 2016 · 2 revisions

To contribute to LEPV backend, you will need to pull lepv code, and then go to directory "backend", you will see several ( and more to come ) python files. Each python file defines a python class, but one good thing about python is that we can define a "main" method in the class.

Take "LepDClient" for example:

import json import socket

class LepDClient:

`def __init__(self, server, port):`
    `self.server = server`
    `self.port = port`
    `self.bufferSize = 2048`

    `print(self.server)`
    `print(self.port)`

`def listAllMethods(self):`
    `response = self.sendRequest("ListAllMethod")`
    `if (response == None or 'result' not in response):`
        `return None`
    
    `results = response['result'].strip().split(" ")`
    `return results`

`def ping(self):`
    `response = self.sendRequest("SayHello")`
    `if (response != None and 'result' in response and response['result'] == 'Hello!'):`
        `return True`
    `else:`
        `return False`

if( __name__ =='__main__' ):

`client = LepDClient('www.linuxxueyuan.com', 1234)`

`# print(client.listAllMethods())`
`# `
`# print(client.ping())`
`#`
`# print(client.getProcMemInfo())`
`# `
`# print(client.getAverageLoad())`

`client.tryAllMethods()`

everything under "if( name =='main' ):" will NOT be touched if this python class is "imported" by other modules, but it will be executed if we run it as a standalone python script, like this:

python3 LepDClient.py

This is how we can test the python code for this class easily, without having to introduce any new test class/files. and feel free to change code in this section for your testing purpose

PyCharm is recommended IDE for LEPV development.

Clone this wiki locally