示例#1
0
    def is_json_ok(self, json_file = None, data = None):
        """ Check if the json file is OK
            @param json_file : path to the json file
            @param data : json data
        """
        try:
            if json_file != None:
                pkg_json = PackageJson(path = json_file)
            elif data != None:
                pkg_json = PackageJson(data = data)
        except:
            self.log.error(u"Error while reading the json file '{0}' : {1}".format(json_file, traceback.format_exc()))
            return False
        try:
            pkg_json.validate()
        except PackageException as e:
            self.log.error(u"Invalid json file. Reason : {0}".format(e.value))
            return False

        self.json = pkg_json.get_json()

        if self.is_compliant_with_domogik() == False:
            return False

        return True
示例#2
0
    def is_json_ok(self, json_file=None, data=None):
        """ Check if the json file is OK
            @param json_file : path to the json file
            @param data : json data
        """
        try:
            if json_file != None:
                pkg_json = PackageJson(path=json_file)
            elif data != None:
                pkg_json = PackageJson(data=data)
        except PackageException as e:
            self.log.error(u"Invalid json file. Reason : {0}".format(e.value))
            return False
        except:
            self.log.error(
                u"Error while reading the json file '{0}' : {1}".format(
                    json_file, traceback.format_exc()))
            return False
        try:
            pkg_json.validate()
        except PackageException as e:
            self.log.error(u"Invalid json file. Reason : {0}".format(e.value))
            return False

        self.json = pkg_json.get_json()

        if self.is_compliant_with_domogik() == False:
            return False

        return True
示例#3
0
    def __init__(self, type, name):
        """ Init a plugin 
            @param type : package type
            @param name : package name
        """
        self.type = type
        self.name = name
        self.json = None

        ### init logger
        log = logger.Logger('manager')
        self.log = log.get_logger('manager')

        self.valid = False
        self.log.debug(u"Package {0}-{1} : read the json file and validate it".format(self.type, self.name))
        try:
            pkg_json = PackageJson(pkg_type = self.type, name = self.name)
            pkg_json.validate()
            self.json = pkg_json.get_json()
            self.valid = True
            self.log.debug(u"Package {0}-{1} : the json file is valid".format(self.type, self.name))
        except PackageException as e:
            self.log.error(u"Package {0}-{1} : error while trying to read the json file".format(self.type, self.name))
            self.log.error(u"Package {0}-{1} : invalid json file".format(self.type, self.name))
            self.log.error(u"Package {0}-{1} : {2}".format(self.type, self.name, e.value))
示例#4
0
 def fill_data(self):
     """ Fill the client data by reading the json file
     """
     try:
         self.log.info(u"Plugin {0} : read the json file".format(self.name))
         pkg_json = PackageJson(pkg_type = "plugin", name = self.name)
         #we don't need to validate the json file as it has already be done in the check_avaiable_packages function
         self.data = pkg_json.get_json()
         self.add_configuration_values_to_data()
     except PackageException as e:
         self.log.error(u"Plugin {0} : error while trying to read the json file".format(self.name))
         self.log.error(u"Plugin {0} : invalid json file".format(self.name))
         self.log.error(u"Plugin {0} : {1}".format(self.name, e.value))
         self.set_status(STATUS_INVALID)
         pass
示例#5
0
 def _load_json(self):
     """ Load the plugin json file
     """
     try:
         self.log.info(u"Read the json file and validate id".format(self._name))
         pkg_json = PackageJson(pkg_type = "plugin", name = self._name)
         # check if json is valid
         if pkg_json.validate() == False:
             # TODO : how to get the reason ?
             self.log.error(u"Invalid json file")
             self.force_leave(status = STATUS_INVALID)
         else:
             # if valid, store the data so that it can be used later
             self.log.info(u"The json file is valid")
             self.json_data = pkg_json.get_json()
     except:
         self.log.error(u"Error while trying to read the json file : {1}".format(self._name, traceback.format_exc()))
         self.force_leave(status = STATUS_INVALID)
示例#6
0
 def _load_json(self):
     """ Load the client json file
     """
     try:
         self.log.info(u"Read the json file and validate id".format(self._name))
         pkg_json = PackageJson(pkg_type = self._type, name = self._name)
         # check if json is valid
         if pkg_json.validate() == False:
             # TODO : how to get the reason ?
             self.log.error(u"Invalid json file")
             self.force_leave(status = STATUS_INVALID)
         else:
             # if valid, store the data so that it can be used later
             self.log.info(u"The json file is valid")
             self.json_data = pkg_json.get_json()
     except:
         self.log.error(u"Error while trying to read the json file : {1}".format(self._name, traceback.format_exc()))
         self.force_leave(status = STATUS_INVALID)