示例#1
0
    def _create_package_for_external(self, id, output_dir, force):
        """ Create package for a external
            1. read json file to get informations and list of files
            2. generate package
            @param id : name of external
            @param output_dir : target directory for package
            @param force : False : ask for confirmation
        """
        self.log("Hardware id : %s" % id)
        if PACKAGE_MODE == True:
            msg = "Domogik in 'production' mode (packages management activated) : creating a package is not possible"
            self.log(msg)
            return

        try:
            pkg_obj = PackageJson(id, pkg_type="external")
            pkg_json = pkg_obj.json
        except:
            self.log(str(traceback.format_exc()))
            return

        # check version format
        try:
            NormalizedVersion(pkg_json["identity"]["version"])
        except:
            self.log("Plugin version '%s' is not valid. Exiting." %
                     pkg_json["identity"]["version"])
            return
        try:
            NormalizedVersion(pkg_json["identity"]["domogik_min_version"])
        except:
            self.log("Domogik min version '%s' is not valid. Exiting." %
                     pkg_json["identity"]["domogik_min_version"])
            return

        self.log("Json file OK")

        if pkg_json["identity"]["type"] != "external":
            self.log("Error : this package is not an external member")
            return

        # display external informations
        pkg_obj.display()

        # check file existence
        if pkg_json["files"] == []:
            self.log("There is no file defined : the package won't be created")
            return

        # check doc files exist
        doc_path = DOC_PATH + "/external/%s/" % id
        doc_fullpath = SRC_PATH + doc_path
        if not os.path.isdir(doc_fullpath):
            self.log(
                "There is no documentation files in '%s' : the package won't be created"
                % doc_fullpath)
            return

        if force == False:
            self.log("\nAre these informations OK ?")
            resp = raw_input("[o/N]")
            if resp.lower() != "o":
                self.log("Exiting...")
                return

        # Copy Json file in a temporary location in order to complete it
        json_tmp_file = "%s/external-%s-%s.json" % (tempfile.gettempdir(
        ), pkg_json["identity"]["id"], pkg_json["identity"]["version"])
        shutil.copyfile(pkg_json["identity"]["info_file"], json_tmp_file)

        # Update info.json with generation date
        pkg_obj.set_generated(json_tmp_file)

        # Create .tgz
        self._create_tar_gz(
            "external-%s-%s" %
            (pkg_json["identity"]["id"], pkg_json["identity"]["version"]),
            output_dir, pkg_json["all_files"], json_tmp_file,
            pkg_json["identity"]["icon_file"], doc_fullpath)
示例#2
0
    def _create_package_for_external(self, id, output_dir, force):
        """ Create package for a external
            1. read json file to get informations and list of files
            2. generate package
            @param id : name of external
            @param output_dir : target directory for package
            @param force : False : ask for confirmation
        """
        self.log("Hardware id : %s" % id)
        if PACKAGE_MODE == True:
            msg = "Domogik in 'production' mode (packages management activated) : creating a package is not possible"
            self.log(msg)
            return

        try:
            pkg_obj = PackageJson(id, pkg_type="external")
            pkg_json = pkg_obj.json
        except:
            self.log(str(traceback.format_exc()))
            return

        # check version format
        try:
            NormalizedVersion(pkg_json["identity"]["version"])
        except:
            self.log("Plugin version '%s' is not valid. Exiting." % pkg_json["identity"]["version"])
            return
        try:
            NormalizedVersion(pkg_json["identity"]["domogik_min_version"])
        except:
            self.log("Domogik min version '%s' is not valid. Exiting." % pkg_json["identity"]["domogik_min_version"])
            return

        self.log("Json file OK")

        if pkg_json["identity"]["type"] != "external":
            self.log("Error : this package is not an external member")
            return

        # display external informations
        pkg_obj.display()

        # check file existence
        if pkg_json["files"] == []:
            self.log("There is no file defined : the package won't be created")
            return

        # check doc files exist
        doc_path = DOC_PATH + "/external/%s/" % id
        doc_fullpath = SRC_PATH + doc_path
        if not os.path.isdir(doc_fullpath):
            self.log("There is no documentation files in '%s' : the package won't be created" % doc_fullpath)
            return

        if force == False:
            self.log("\nAre these informations OK ?")
            resp = raw_input("[o/N]")
            if resp.lower() != "o":
                self.log("Exiting...")
                return

        # Copy Json file in a temporary location in order to complete it
        json_tmp_file = "%s/external-%s-%s.json" % (
            tempfile.gettempdir(),
            pkg_json["identity"]["id"],
            pkg_json["identity"]["version"],
        )
        shutil.copyfile(pkg_json["identity"]["info_file"], json_tmp_file)

        # Update info.json with generation date
        pkg_obj.set_generated(json_tmp_file)

        # Create .tgz
        self._create_tar_gz(
            "external-%s-%s" % (pkg_json["identity"]["id"], pkg_json["identity"]["version"]),
            output_dir,
            pkg_json["all_files"],
            json_tmp_file,
            pkg_json["identity"]["icon_file"],
            doc_fullpath,
        )