Beispiel #1
0
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Domogik. If not, see U{http://www.gnu.org/licenses}.

Plugin purpose
==============

Insert plugin data in database

Implements
==========

PluginData

@author: Fritz <*****@*****.**>
@copyright: (C) 2007-2012 Domogik project
@license: GPL(v3)
@organization: Domogik
"""

from domogik.common.packagedata import PackageData
import sys

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print("Usage : %s <plugin json file>" % sys.argv[0])
        quit()
    PD = PackageData(sys.argv[1])
    PD.insert()
Beispiel #2
0
    def install_package(self, path, version=None, package_part=PKG_PART_XPL):
        """ Install a package
            0. Eventually download package
            1. Extract tar.gz
            2. Install package
            3. Insert data in database
            @param path : path for tar.gz
            @param version : version to install (default : highest)
            @param package_part : PKG_PART_XPL (for manager), PKG_PART_RINOR (for RINOR)
        """
        if PACKAGE_MODE != True:
            raise PackageException("Package mode not activated")
        self.log("Start install for part '%s' of '%s'" % (package_part, path))
        if path[0:6] == "cache:":
            path = "%s/package/download/%s" % (REST_URL, path[6:])

        if path[0:5] == "repo:":
            pkg, status = self._find_package(path[5:], version)
            if status != True:
                return status
            path = pkg.archive_url

        # get package name
        if path[0:4] == "http":  # special process for a http path
            id = full_name = "-".join(path.split("/")[-3:])
            print ("id=%s" % full_name)
        else:
            full_name = os.path.basename(path)
            # twice to remove first .gz and then .tar
            id = os.path.splitext(full_name)[0]
            id = os.path.splitext(id)[0]

        self.log("Ask for installing package id : %s" % id)

        # get temp dir to extract data
        my_tmp_dir_dl = TMP_EXTRACT_DIR
        my_tmp_dir = "%s/%s" % (my_tmp_dir_dl, id)
        self._create_folder(my_tmp_dir)

        # Check if we need to download package
        if path[0:4] == "http":
            dl_path = "%s/%s.tgz" % (my_tmp_dir_dl, full_name)
            self.log("Downloading package : '%s' to '%s'" % (path, dl_path))
            urllib.urlretrieve(path, dl_path)
            path = dl_path
            self.log("Package downloaded : %s" % path)

        # extract in tmp directory
        self.log("Extracting package...")
        try:
            self._extract_package(path, my_tmp_dir)
        except:
            msg = "Error while extracting package '%s' : %s" % (path, traceback.format_exc())
            self.log(msg)
            raise PackageException(msg)
        self.log("Package successfully extracted.")

        # get Json informations
        pkg_json = PackageJson(path="%s/info.json" % my_tmp_dir).json

        # check compatibility with domogik installed version
        __import__("domogik")
        dmg = sys.modules["domogik"]
        self.log("Domogik version = %s" % dmg.__version__)
        self.log("Minimum Domogik version required for package = %s" % pkg_json["identity"]["domogik_min_version"])
        print ("%s < %s" % (pkg_json["identity"]["domogik_min_version"], dmg.__version__))
        if pkg_json["identity"]["domogik_min_version"] > dmg.__version__:
            msg = "This package needs a Domogik version >= %s. Actual is %s. Installation ABORTED!" % (
                pkg_json["identity"]["domogik_min_version"],
                dmg.__version__,
            )
            self.log(msg)
            raise PackageException(msg)

        # check the json_version file
        self.log("Required json version = %s" % MIN_JSON_VERSION)
        self.log("Package json version = %s" % pkg_json["json_version"])
        if pkg_json["json_version"] < MIN_JSON_VERSION:
            msg = "This package has json_version set to %s, but Domogik needs at least %s" % (
                pkg_json["json_version"],
                MIN_JSON_VERSION,
            )
            self.log(msg)
            raise PackageException(msg)

        # create install directory
        self._create_folder(INSTALL_PATH)

        # install plugin in $HOME
        self.log("Installing package (%s)..." % pkg_json["identity"]["type"])
        try:
            if pkg_json["identity"]["type"] in ("plugin", "external"):
                self._install_plugin_or_external(my_tmp_dir, INSTALL_PATH, pkg_json["identity"]["type"], package_part)
            else:
                raise "Package type '%s' not installable" % pkg_json["identity"]["type"]
        except:
            msg = "Error while installing package : %s" % (traceback.format_exc())
            self.log(msg)
            raise PackageException(msg)
        self.log("Package successfully extracted.")

        # insert data in database
        if pkg_json["identity"]["type"] in ("plugin", "external"):
            if package_part == PKG_PART_RINOR:
                self.log("Insert data in database...")
                pkg_data = PackageData("%s/info.json" % my_tmp_dir)
                pkg_data.insert()

        self.log("Package installation finished")
        return True
Beispiel #3
0
    def install_package(self, path, version=None, package_part=PKG_PART_XPL):
        """ Install a package
            0. Eventually download package
            1. Extract tar.gz
            2. Install package
            3. Insert data in database
            @param path : path for tar.gz
            @param version : version to install (default : highest)
            @param package_part : PKG_PART_XPL (for manager), PKG_PART_RINOR (for RINOR)
        """
        if PACKAGE_MODE != True:
            raise PackageException("Package mode not activated")
        self.log("Start install for part '%s' of '%s'" % (package_part, path))
        if path[0:6] == "cache:":
            path = "%s/package/download/%s" % (REST_URL, path[6:])

        if path[0:5] == "repo:":
            pkg, status = self._find_package(path[5:], version)
            if status != True:
                return status
            path = pkg.archive_url

        # get package name
        if path[0:4] == "http":  # special process for a http path
            id = full_name = '-'.join(path.split("/")[-3:])
            print("id=%s" % full_name)
        else:
            full_name = os.path.basename(path)
            # twice to remove first .gz and then .tar
            id = os.path.splitext(full_name)[0]
            id = os.path.splitext(id)[0]

        self.log("Ask for installing package id : %s" % id)

        # get temp dir to extract data
        my_tmp_dir_dl = TMP_EXTRACT_DIR
        my_tmp_dir = "%s/%s" % (my_tmp_dir_dl, id)
        self._create_folder(my_tmp_dir)

        # Check if we need to download package
        if path[0:4] == "http":
            dl_path = "%s/%s.tgz" % (my_tmp_dir_dl, full_name)
            self.log("Downloading package : '%s' to '%s'" % (path, dl_path))
            urllib.urlretrieve(path, dl_path)
            path = dl_path
            self.log("Package downloaded : %s" % path)

        # extract in tmp directory
        self.log("Extracting package...")
        try:
            self._extract_package(path, my_tmp_dir)
        except:
            msg = "Error while extracting package '%s' : %s" % (
                path, traceback.format_exc())
            self.log(msg)
            raise PackageException(msg)
        self.log("Package successfully extracted.")

        # get Json informations
        pkg_json = PackageJson(path="%s/info.json" % my_tmp_dir).json

        # check compatibility with domogik installed version
        __import__("domogik")
        dmg = sys.modules["domogik"]
        self.log("Domogik version = %s" % dmg.__version__)
        self.log("Minimum Domogik version required for package = %s" %
                 pkg_json["identity"]["domogik_min_version"])
        print("%s < %s" %
              (pkg_json["identity"]["domogik_min_version"], dmg.__version__))
        if pkg_json["identity"]["domogik_min_version"] > dmg.__version__:
            msg = "This package needs a Domogik version >= %s. Actual is %s. Installation ABORTED!" % (
                pkg_json["identity"]["domogik_min_version"], dmg.__version__)
            self.log(msg)
            raise PackageException(msg)

        # check the json_version file
        self.log("Required json version = %s" % MIN_JSON_VERSION)
        self.log("Package json version = %s" % pkg_json["json_version"])
        if pkg_json["json_version"] < MIN_JSON_VERSION:
            msg = "This package has json_version set to %s, but Domogik needs at least %s" % (
                pkg_json["json_version"], MIN_JSON_VERSION)
            self.log(msg)
            raise PackageException(msg)

        # create install directory
        self._create_folder(INSTALL_PATH)

        # install plugin in $HOME
        self.log("Installing package (%s)..." % pkg_json["identity"]["type"])
        try:
            if pkg_json["identity"]["type"] in ('plugin', 'external'):
                self._install_plugin_or_external(my_tmp_dir, INSTALL_PATH,
                                                 pkg_json["identity"]["type"],
                                                 package_part)
            else:
                raise "Package type '%s' not installable" % pkg_json[
                    "identity"]["type"]
        except:
            msg = "Error while installing package : %s" % (
                traceback.format_exc())
            self.log(msg)
            raise PackageException(msg)
        self.log("Package successfully extracted.")

        # insert data in database
        if pkg_json["identity"]["type"] in ('plugin', 'external'):
            if package_part == PKG_PART_RINOR:
                self.log("Insert data in database...")
                pkg_data = PackageData("%s/info.json" % my_tmp_dir)
                pkg_data.insert()

        self.log("Package installation finished")
        return True
Beispiel #4
0
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Domogik. If not, see U{http://www.gnu.org/licenses}.

Plugin purpose
==============

Insert plugin data in database

Implements
==========

PluginData

@author: Fritz <*****@*****.**>
@copyright: (C) 2007-2012 Domogik project
@license: GPL(v3)
@organization: Domogik
"""

from domogik.common.packagedata import PackageData
import sys

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print("Usage : %s <plugin json file>" % sys.argv[0])
        quit()
    PD = PackageData(sys.argv[1])
    PD.insert()