Skip to content

glanchow/consmaster

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 

Repository files navigation

consmaster

Consmaster

  1. Introduction
  2. Installation
  3. Current development
  4. Network
  5. Create an exercice
  6. Todo
1. Introduction ---------------

ConsMaster was designed to help students in understanding how to represent lists in parenthesis, dotted and graphical representations.

consmaster screenshot

2. Installation ---------------

You will need PySide and SqlAlchemy

$ sudo apt-get install python-pyside
$ sudo apt-get install python-sqlalchemy
$ git clone https://github.com/glanchow/consmaster.git

Start the client

$ cd consmaster/src/
$ ./consmaster.py

Start the server

$ ./consmaster-server.py
3. Current development ----------------------

Visual overview of what is done and what is to do.

4. Network ----------

The network interface is based on the PySide network library. It is fully functionnal although at the time I'm writing it only supports register and login commands. I'm going to describe the login command so that you can add your own commands.

By default you can connect to the server as an anonymous user, and after that you can use a simple command to login as a user.

Let's look on the server side.

# src consmaster-server.py
self.user = None
self.commands = {}
self.commands["register"] = self.register
self.commands["login"] = self.login

The server handles each client with a single thread, and every thread knows it's user as self.user, which is None if the user is connected as anonymous. Then each command is referenced by it's name in the commands dict, with the corresponding routine.

# src consmaster-server.py
def login(self, inStream):
    username = inStream.readQString()
    password = inStream.readQString()
    email = inStream.readQString()
    status, user = UserManager.authenticate(username, password)
    if status == AUTHENTICATE_SUCCESS:
        self.user = user
    reply, outStream = self.newReply()
    outStream.writeInt16(status)
    self.sendReply(reply, outStream)

The request looks like « register username password email » but in a binary format understood by PySide, this is why we use builtins like readQString(), to detect words encoded with writeQString() as we will see in a few lines. The reply starts with a status code and whatever you want after that. You can have a look at status code :

# src NetworkCodes.py
REGISTER_SUCCESS = 300
REGISTER_USERNAME_EXISTS = 301
AUTHENTICATE_SUCCESS = 400
AUTHENTICATE_FAILURE = 401

Then in the client, a routine is dedicated to each reply.

 # src consmaster.py
 self.replies = {}
 self.replies[REGISTER_SUCCESS] = self.registered
 self.replies[REGISTER_USERNAME_EXISTS] = self.alreadyRegistered
 self.replies[AUTHENTICATE_SUCCESS] = self.logged
 self.replies[AUTHENTICATE_FAILURE] = self.badCreditentials

And finally here's how we send a command from the client to the server.

# src consmaster.py
def login(self):
    request, outStream = self.newRequest()
    outStream.writeQString("login")
    outStream.writeQString(self.usernameLineEdit.text())
    outStream.writeQString(self.passwordLineEdit.text())
    self.sendRequest(request, outStream)
5. Exercice ---------------

Take a look at solver.py

6. Todo -------
  1. Let the user choose host and port from command line for both client and server
  2. Store host, port, and other configuration in a config file like ~/.consmasterrc
  3. Find a good daemonizer script for the server
  4. Check for non linear graph drawing in Pigale project to draw good looking conses

About

learn list notation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages