def toJson(self):
     LogService.logMessage("ScreenXmlToJsonService.toJson", LogService.INFO)
     return "{\"layoutID\": " + str(
         self._layoutID
     ) + ",\"layoutURL\": \"" + settings.WEBSERVER_ASSET_IP + str(
         self._layoutID) + "/layout.zip\",\"lastModifiedDate\": \"" + str(
             self._lastModifiedDate) + "\"}"
Exemple #2
0
 def getAllLayouts(self, userID=None):
     LogService.logMessage("QueryService.getAllLayouts", LogService.INFO)
     # make filtering more programmatic
     filters = []
     if userID != None:
         filters = ["userID = " + str(userID)]
     return DatabaseConnector.select(layout, filters).all()
Exemple #3
0
def getLatestLayout(**kwargs):
    LogService.logMessage("api.getLatestLayout", LogService.INFO)
    keyCode = kwargs.get('keyCode')
    keyPass = kwargs.get('keyPass')
    deviceIdentifier = kwargs.get('deviceIdentifier')
    userID = kwargs.get('userID')

    layoutResponse = "{\"layout\":"
    LogService.logMessage("api.getLatestLayout beforeQueryService",
                          LogService.INFO)

    layout = QueryService.getLastLayout(userID)
    LogService.logMessage("api.getLatestLayout afterQueryService",
                          LogService.INFO)
    if layout != None:
        LogService.logMessage("api.getLatestLayout layout found",
                              LogService.INFO)
        xmltojson = ScreenXmlToJsonService(layout.xml, layout.layoutID,
                                           layout.modifiedDT)
        xmltojson.parse()
        layoutResponse += xmltojson.toJson()
    else:
        LogService.logMessage("api.getLatestLayout layout not found",
                              LogService.INFO)
        layoutResponse += "{}"

    layoutResponse += "}"
    return layoutResponse
Exemple #4
0
 def getDevice(self, deviceClientId, deviceCpuId):
     LogService.logMessage("QueryService.getDevice", LogService.INFO)
     # make filtering more programmatic
     filters = [
         "device_clientid = " + deviceClientId,
         "device_cpuid = " + deviceCpuId
     ]
     return DatabaseConnector.select(device, filters).all()
Exemple #5
0
def getAllLayouts(**kwargs):
    LogService.logMessage("api.getAllLayouts", LogService.INFO)
    layouts = QueryService.getAllLayouts()
    for layout in layouts:
        #LogService.logMessage("api.getAllLayouts : layout " + layout.xml, LogService.INFO);
        xmltojson = ScreenXmlToJsonService(layout.xml)
        xmltojson.parse()
        jsonval = xmltojson.toJson()
Exemple #6
0
 def getLastLayout(self, userID=None):
     LogService.logMessage("QueryService.getLastLayout", LogService.INFO)
     # make filtering more programmatic
     filters = []
     if userID != None:
         filters = ["userID = " + str(userID)]
     # TODO maybe sort the results starting with the latest by ID and get first result???
     layouts = DatabaseConnector.select(layout, filters).all()
     if len(layouts) > 0:
         return layouts[-1]
     return None
    def toJsonArray(self, repr, array):
        LogService.logMessage("AbstractXmlToJsonService.toJsonArray",
                              LogService.INFO)
        reprJson = "," + self.safeStr(repr) + ": ["

        # parse all array elements
        for element in array:
            if hasattr(element, 'toJson'):
                reprJson += element.toJson() + ","
            else:
                reprJson += self.safeStr(element) + ","

        # if element is found and endswith a ',' comma, remove the comma
        elementFound = len(array)
        if elementFound > 0 and reprJson.endswith(','):
            reprJson = reprJson[:-1]

        # close array brackets and return
        reprJson += "]"
        return reprJson
Exemple #8
0
 def select(self, object, filters): 
     LogService.logMessage("DatabaseConnector.select", LogService.INFO);                
     try:                        
         self.__startSession();
         result = self._session.query(object);
         for qfilter in filters:
             result = result.filter(text(qfilter));                    
         self.__destroySession();
         LogService.logMessage("DatabaseConnector.select : successfull", LogService.INFO);        
         return result;
     except SQLAlchemyError as e:
         # log an error message here
         LogService.logMessage("DatabaseConnector.select : select failed exception " + e.strerror, LogService.CRITICAL);
         return None
     except:
         LogService.logMessage("DatabaseConnector.select : select failed exception ", LogService.INFO);
         return None
Exemple #9
0
 def update(self, object): 
     LogService.logMessage("DatabaseConnector.update", LogService.INFO);           
     try:                        
         self._session.commit();
         self.__destroySession();
         LogService.logMessage("DatabaseConnector.update : successfull", LogService.INFO);        
         return True
     except SQLAlchemyError as e:
         # log an error message here
         LogService.logMessage("DatabaseConnector.update : update failed exception " + e.strerror, LogService.CRITICAL);
         return False
Exemple #10
0
 def insert(self, object): 
     LogService.logMessage("DatabaseConnector.insert", LogService.INFO);        
     try:            
         self.__startSession();
         self._session.add(object);
         self._session.commit();
         self.__destroySession();
         LogService.logMessage("DatabaseConnector.insert : insert successfull", LogService.INFO);
     except SQLAlchemyError as e:
         # log an error message here
         LogService.logMessage("DatabaseConnector.insert : insert failed exception " + e.strerror, LogService.CRITICAL);
         return
 def screenToJson(self):
     LogService.logMessage("ScreenXmlToJsonService.__screenToJson",
                           LogService.INFO)
     return self.__screen.toJson()
Exemple #12
0
def validateBox(**kwargs):
    LogService.logMessage("api.validateBox", LogService.INFO)
    keyCode = kwargs.get('keyCode')
    keyPass = kwargs.get('keyPass')
    deviceIdentifier = kwargs.get('deviceIdentifier')
    return __isValidKey(keyCode, keyPass) and __isValidBox(deviceIdentifier)
Exemple #13
0
 def __createSession(self): 
     LogService.logMessage("DatabaseConnector.__createSession", LogService.INFO);                    
     Session = sessionmaker(bind=self._engine)
     self._session = Session()
Exemple #14
0
 def __destroySession(self):
     LogService.logMessage("DatabaseConnector.__destroySession", LogService.INFO);                    
     self._session.close();
Exemple #15
0
def __isValidBox(deviceIdentifier):
    try:
        LogService.logMessage(
            "api.__isValidBox : deviceIdentifier {0}".format(deviceIdentifier),
            LogService.INFO)
        decodedMessage = Util.decrypt(deviceIdentifier)
        LogService.logMessage(
            "api.__isValidBox : decodedMessage {0}".format(decodedMessage),
            LogService.INFO)
        deviceInformation = Util.parseDecodedMessage(decodedMessage)
        LogService.logMessage(
            "api.__isValidBox : device information parsed {0} {1}".format(
                deviceInformation[0], deviceInformation[1]), LogService.INFO)
        devices = QueryService.getDevice(deviceInformation[0],
                                         deviceInformation[1])
        if len(devices) > 0:
            device = devices[0]
            LogService.logMessage(
                "api.__isValidBox : device found {0}".format(device.device_id),
                LogService.INFO)
            if (datetime.now() - datetime.strptime(
                    device.device_deactivationdate,
                    "%d/%m/%Y %H:%M:%S")).total_seconds() > 0:
                LogService.logMessage(
                    "api.__isValidBox : device deactivated {0}".format(
                        device.device_id), LogService.INFO)
                return False
            LogService.logMessage(
                "api.__isValidBox : device active {0}".format(
                    device.device_id), LogService.INFO)
            return True
        else:
            LogService.logMessage("api.__isValidBox : device not found",
                                  LogService.INFO)
            return False
    except Error as e:
        LogService.logMessage("api.__isValidBox : {0} {1}".format(
            e.errno, e.strerror))
        return False
Exemple #16
0
 def __startSession(self):
     LogService.logMessage("DatabaseConnector.__startSession", LogService.INFO);                    
     database_connection = '{0}://{1}:{2}@{3}/{4}?unix_socket=/var/run/mysqld/mysqld.sock'.format(settings.database_type, settings.database_user, settings.database_pass, '127.0.0.1:' + settings.database_port, settings.database_name)        
     self._engine = create_engine(database_connection, echo=settings.DATABASE_LOGGING)        
     self.__createSession()
 def toJson(self):
     LogService.logMessage("AbstractModel.toJson", LogService.INFO)
     return ("{\"" + self.__repr__() + "\":{" + self._toJson() + "}}")
 def _toJson(self):
     LogService.logMessage("AbstractModel._toJson", LogService.ERROR)
     raise Exception('_toJson method shall be overriden!')
Exemple #19
0
from services.ArgumentService import ArgumentService
from models.EntityManager import EntityManager
from services.GraphService import GraphService
from services.LogService import LogService

LogService.configure()
args = ArgumentService.configure().parse()

with EntityManager.initialize(GraphService.getGraph()):
    if args.operation == 'clear':
        EntityManager.clear()

    if args.operation == 'update':
        depth = args.depth
        if args.person:
            for id in args.person:
                EntityManager.Person(id).sync(True).expand(depth)
        if args.media:
            for id in args.media:
                EntityManager.Media(id).sync(True).expand(depth)

    if args.operation == 'load':
        for id in args.person:
            p = EntityManager.Person(id)
            p.load()
            p.pp()
 def parse(self):
     LogService.logMessage("ScreenXmlToJsonService.parse", LogService.INFO)
     self.__parseScreen(self._tree.attrib)
     self.__parseRegions(self._tree.iter('region'))
     self.__saveAssets(settings.XIBO_ASSET_PATH, settings.ZIP_SAVE_PATH)
Exemple #21
0
 def __init__(self, xmlstr, layoutID, lastModifiedDate):
     LogService.logMessage("AbstractXmlToJsonService.__init__", LogService.INFO);        
     self._tree = xml.etree.ElementTree.fromstring(xmlstr);          
     self._layoutID = layoutID;
     self._lastModifiedDate = lastModifiedDate;
Exemple #22
0
 def toJson(self):
     LogService.logMessage("AbstractXmlToJsonService.toJson", LogService.ERROR);
     raise NotImplementedError('toJson method shall be overriden!');
     
Exemple #23
0
 def parse(self):
     LogService.logMessage("AbstractXmlToJsonService.parse", LogService.ERROR);        
     raise NotImplementedError('parse method shall be overriden!');