Ejemplo n.º 1
0
 def printer_getall(self):
     msg = ServerRequest(cmd=self.com.printer.getall)
     resp = ServerResponse.decode(self.send(msg.encode()))
     if not resp.err:
         assert type(resp.val) == list
         return natsorted(resp.val)
     else:
         raise Exception(resp.errmsg)
Ejemplo n.º 2
0
 def user_delete(self, userids, auth_userid, auth_passwd):
     msg = ServerRequest(cmd=self.com.user.edit)
     msg.args["userids"] = userids
     msg.args["auth_userid"] = auth_userid
     msg.args["auth_passwd"] = auth_passwd
     
     c_logger.debug("user_edit: Sending request to server...")
     return self.getresp(msg)
Ejemplo n.º 3
0
 def rate_getall(self):
     msg = ServerRequest(cmd=self.com.rate.getall)
     resp = ServerResponse.decode(self.send(msg.encode()))
     if not resp.err:
         assert type(resp.val) == list
         return natsorted([PrintRate.loadjson(r) for r in resp.val], key=lambda x: x.rateid)
     else:
         raise Exception(resp.errmsg)
Ejemplo n.º 4
0
 def getUsers(self):
     msg = ServerRequest(cmd=self.com.user.getall)
     c_logger.debug("getUsers: Sending request to server...")
     resp = ServerResponse.decode(self.send(msg.encode()))
     if not resp.err:
         return resp.val
     else:
         raise Exception(resp.errmsg)
Ejemplo n.º 5
0
 def user_issuper(self, userid, passwd):
     c_logger.debug("issuper: Checking if '{}' is an elevated user.".format(userid))
     msg = ServerRequest(cmd=self.com.user.issuper)
     msg.args["userid"] = userid
     msg.args["passwd"] = passwd
     
     c_logger.debug("issuper: Sending request to server...")
     resp = ServerResponse.decode(self.send(msg.encode()))
     if not resp.err:
         c_logger.debug("issuper: Done.")
         return resp.val
     else:
         raise Exception(resp.errmsg)
Ejemplo n.º 6
0
 def verifyUser(self, userid, passwd):
     c_logger.info("verifyUser: Verifying user credentials...")
     
     msg = ServerRequest(cmd=self.com.user.verify)
     msg.args["userid"] = userid
     msg.args["passwd"] = passwd
     
     c_logger.debug("verifyUser: Sending request to server...")
     resp = self.send(msg.encode())
     resp = ServerResponse.decode(resp)
     if not resp.err:
         return resp.val
     else:
         raise Exception(resp.errmsg)
Ejemplo n.º 7
0
 def parseCommand(self, code):
     # Check Input
     if not code:
         return ServerResponse()
     
     # Check syntax
     try:
         self.logger.debug("parseCommand: Reading command...")
         s = ServerRequest.decode(code)
         if s.cmd not in self.fcns.keys():
             raise Exception("An unknown command code ({}) was passed.".format(s.cmd))
     except Exception as e:
         self.logger.exception("parseCommand: An exception was raised.")
         return ServerResponse(err=True, errmsg=str(e))
     self.logger.debug("parseCommands: Parsing complete.")
     
     # Execute commands
     try:
         self.logger.debug("parseCommand: Recieved code {}; executing {}".format(s.cmd,
                           self.fcns[s.cmd]))
         v = self.fcns[s.cmd](*s.args, **s.kwargs)
         self.logger.debug("parseCommands: Done.")
         return ServerResponse(val=v)
     except Exception as e:
         self.logger.exception("parseCommand: Unable to execute command.")
         return ServerResponse(err=True, errmsg=str(e))# Return excecution error
Ejemplo n.º 8
0
 def rate_add(self, rateid, lengthrate, timerate, auth_userid, auth_passwd):
     msg = ServerRequest(cmd=self.com.rate.add)
     msg.args["rateid"] = rateid
     msg.args["lengthrate"] = lengthrate
     msg.args["timerate"] = timerate
     msg.args["auth_userid"] = auth_userid
     msg.args["auth_passwd"] = auth_passwd
     resp = ServerResponse.decode(self.send(msg.encode()))
     if resp.err:
         raise Exception(resp.errmsg)
Ejemplo n.º 9
0
 def user_add(self, userid, passwd, issuper=False, auth_userid="", auth_passwd="", email="", 
             firstname="", lastname=""):
     c_logger.info("user_add: Adding a new user.")
     
     msg = ServerRequest(cmd=self.com.user.add)
     msg.args = {
             "userid" : userid,
             "passwd" : passwd,
             "email" : email,
             "issuper" : issuper,
             "auth_userid" : auth_userid,
             "auth_passwd" : auth_passwd,
             "firstname" : firstname,
             "lastname" : lastname,
         }
     
     c_logger.debug("user_add: Sending request to server...")
     return self.getresp(msg)
Ejemplo n.º 10
0
 def user_edit(self, userid, auth_userid, auth_passwd, passwd="", issuper=None, email="", 
              firstname="", lastname=""):
     msg = ServerRequest(cmd=self.com.user.edit)
     msg.args["userid"] = userid
     msg.args["auth_userid"] = auth_userid
     msg.args["auth_passwd"] = auth_passwd
     if passwd:
         msg.args["passwd"] = passwd
     if not issuper==None:
         msg.args["issuper"] = issuper
     if email:
         msg.args["email"] = email
     if firstname:
         msg.args["firstname"] = firstname
     if lastname:
         msg.args["lastname"] = lastname
     
     c_logger.debug("user_edit: Sending request to server...")
     return self.getresp(msg)
Ejemplo n.º 11
0
 def printer_delete(self, printer, auth_userid, auth_passwd):
     msg = ServerRequest(cmd=self.com.printer.delete)
     msg.args["printer"] = printer
     msg.args["auth_userid"] = auth_userid
     msg.args["auth_passwd"] = auth_passwd
     resp = ServerResponse.decode(self.send(msg.encode()))
     if resp.err:
         raise Exception(resp.errmsg)
Ejemplo n.º 12
0
 def sendRequest(self, cmd, *args, **kwargs):
     request = ServerRequest(cmd, *args, **kwargs)
     return self.getresp(request)
Ejemplo n.º 13
0
 def print_add(self, userid, passwd, length, duration, printer, rate, paidby="", note=""):
     msg = ServerRequest(cmd=self.com.print.add)
     msg.args["userid"] = userid
     msg.args["passwd"] = passwd
     msg.args["length"] = length
     msg.args["duration"] = duration
     msg.args["printer"] = printer
     msg.args["rate"] = rate
     if paidby:
         msg.args["paidby"] = paidby
     if note:
         msg.args["note"] = note
     
     resp = ServerResponse.decode(self.send(msg.encode()))
     if not resp.err:
         return resp.val
     else:
         raise Exception(resp.errmsg)
Ejemplo n.º 14
0
 def user_get(self, **kwargs):
     msg = ServerRequest(cmd=self.com.user.get)
     msg.args = kwargs
     c_logger.debug("user_get: Sending request to server...")
     users = self.getresp(msg)
     return [User.fromDict(d) for d in users]