Exemplo n.º 1
0
    def update(  # pylint: disable=arguments-differ
            self,
            package,
            requirements=None,
            only_check=False,
            only_packages=False):
        if isdir(package):
            pkg_dir = package
        else:
            name, requirements, url = self.parse_pkg_input(
                package, requirements)
            pkg_dir = self.get_package_dir(name, requirements, url)

        p = PlatformFactory.newPlatform(pkg_dir)
        pkgs_before = pkgs_after = p.get_installed_packages().keys()

        if not only_packages:
            BasePkgManager.update(self, pkg_dir, requirements, only_check)
            p = PlatformFactory.newPlatform(pkg_dir)
            pkgs_after = p.get_installed_packages().keys()

        p.update_packages(only_check)
        self.cleanup_packages(p.packages.keys())

        pkgs_missed = set(pkgs_before) - set(pkgs_after)
        if pkgs_missed:
            p.install_packages(
                with_packages=pkgs_missed, skip_default_package=True)

        return True
Exemplo n.º 2
0
    def update(  # pylint: disable=arguments-differ
            self,
            package,
            requirements=None,
            only_check=False,
            only_packages=False):
        if isdir(package):
            pkg_dir = package
        else:
            name, requirements, url = self.parse_pkg_uri(package, requirements)
            pkg_dir = self.get_package_dir(name, requirements, url)

        if not pkg_dir:
            raise exception.UnknownPlatform(package)

        p = PlatformFactory.newPlatform(pkg_dir)
        pkgs_before = list(p.get_installed_packages())

        missed_pkgs = set()
        if not only_packages:
            BasePkgManager.update(self, pkg_dir, requirements, only_check)
            p = PlatformFactory.newPlatform(pkg_dir)
            missed_pkgs = set(pkgs_before) & set(p.packages)
            missed_pkgs -= set(p.get_installed_packages())

        p.update_packages(only_check)
        self.cleanup_packages(list(p.packages))

        if missed_pkgs:
            p.install_packages(with_packages=list(missed_pkgs),
                               skip_default_package=True)

        return True
Exemplo n.º 3
0
    def update(  # pylint: disable=arguments-differ
            self,
            package,
            requirements=None,
            only_check=False,
            only_packages=False):
        if isdir(package):
            pkg_dir = package
        else:
            name, requirements, url = self.parse_pkg_uri(package, requirements)
            pkg_dir = self.get_package_dir(name, requirements, url)

        if not pkg_dir:
            raise exception.UnknownPlatform(package)

        p = PlatformFactory.newPlatform(pkg_dir)
        pkgs_before = p.get_installed_packages().keys()

        missed_pkgs = set()
        if not only_packages:
            BasePkgManager.update(self, pkg_dir, requirements, only_check)
            p = PlatformFactory.newPlatform(pkg_dir)
            missed_pkgs = set(pkgs_before) & set(p.packages.keys())
            missed_pkgs -= set(p.get_installed_packages().keys())

        p.update_packages(only_check)
        self.cleanup_packages(p.packages.keys())

        if missed_pkgs:
            p.install_packages(
                with_packages=list(missed_pkgs), skip_default_package=True)

        return True
Exemplo n.º 4
0
    def update(  # pylint: disable=arguments-differ
            self,
            package,
            requirements=None,
            only_check=False,
            only_packages=False):
        if isdir(package):
            pkg_dir = package
        else:
            name, requirements, url = self.parse_pkg_input(
                package, requirements)
            pkg_dir = self.get_package_dir(name, requirements, url)

        p = PlatformFactory.newPlatform(pkg_dir)
        pkgs_before = pkgs_after = p.get_installed_packages().keys()

        if not only_packages:
            BasePkgManager.update(self, pkg_dir, requirements, only_check)
            p = PlatformFactory.newPlatform(pkg_dir)
            pkgs_after = p.get_installed_packages().keys()

        p.update_packages(only_check)
        self.cleanup_packages(p.packages.keys())

        pkgs_missed = set(pkgs_before) - set(pkgs_after)
        if pkgs_missed:
            p.install_packages(with_packages=pkgs_missed,
                               skip_default_package=True)

        return True
Exemplo n.º 5
0
 def __init__(self, package_dir=None, repositories=None):
     if not repositories:
         repositories = [
             "https://dl.bintray.com/platformio/dl-platforms/manifest.json",
             "{0}://dl.platformio.org/platforms/manifest.json".format(
                 "https" if app.get_setting("strict_ssl") else "http")
         ]
     BasePkgManager.__init__(self, package_dir
                             or get_project_platforms_dir(), repositories)
Exemplo n.º 6
0
 def uninstall(self, name, requirements=None, trigger_event=True):
     name, requirements, _ = self.parse_pkg_name(name, requirements)
     p = PlatformFactory.newPlatform(name, requirements)
     BasePkgManager.uninstall(self, name, requirements)
     # trigger event is disabled when upgrading operation
     # don't cleanup packages, "install" will do that
     if trigger_event:
         self.cleanup_packages(p.packages.keys())
     return True
Exemplo n.º 7
0
 def __init__(self, package_dir=None, repositories=None):
     if not repositories:
         repositories = [
             "https://dl.bintray.com/platformio/dl-platforms/manifest.json",
             "{0}://dl.platformio.org/platforms/manifest.json".format(
                 "https" if app.get_setting("enable_ssl") else "http"
             ),
         ]
     BasePkgManager.__init__(self, package_dir or join(util.get_home_dir(), "platforms"), repositories)
Exemplo n.º 8
0
 def __init__(self, package_dir=None, repositories=None):
     if not repositories:
         repositories = [
             "{0}://dl.platformio.org/platforms/manifest.json".format(
                 "http" if app.get_setting("disable_ssl") else "https")
         ]
     BasePkgManager.__init__(self, package_dir or
                             join(util.get_home_dir(), "platforms"),
                             repositories)
Exemplo n.º 9
0
 def uninstall(self, name, requirements=None, trigger_event=True):
     name, requirements, _ = self.parse_pkg_name(name, requirements)
     p = PlatformFactory.newPlatform(name, requirements)
     BasePkgManager.uninstall(self, name, requirements)
     # trigger event is disabled when upgrading operation
     # don't cleanup packages, "install" will do that
     if trigger_event:
         self.cleanup_packages(p.packages.keys())
     return True
Exemplo n.º 10
0
 def update(self,  # pylint: disable=arguments-differ
            name, requirements=None, only_packages=False, only_check=False):
     name, requirements, _ = self.parse_pkg_name(name, requirements)
     if not only_packages:
         BasePkgManager.update(self, name, requirements, only_check)
     p = PlatformFactory.newPlatform(name, requirements)
     p.update_packages(only_check)
     self.cleanup_packages(p.packages.keys())
     return True
Exemplo n.º 11
0
 def update(  # pylint: disable=arguments-differ
     self, name, requirements=None, only_packages=False, only_check=False
 ):
     name, requirements, _ = self.parse_pkg_name(name, requirements)
     if not only_packages:
         BasePkgManager.update(self, name, requirements, only_check)
     p = PlatformFactory.newPlatform(name, requirements)
     p.update_packages(only_check)
     self.cleanup_packages(p.packages.keys())
     return True
Exemplo n.º 12
0
 def __init__(self, package_dir=None, repositories=None):
     if not repositories:
         repositories = [
             "https://dl.bintray.com/platformio/dl-platforms/manifest.json",
             "{0}://dl.platformio.org/platforms/manifest.json".format(
                 "https" if app.get_setting("strict_ssl") else "http"),
         ]
     self.config = ProjectConfig.get_instance()
     BasePkgManager.__init__(
         self, package_dir or self.config.get_optional_dir("platforms"),
         repositories)
Exemplo n.º 13
0
def test_pkg_name_parser():
    items = [
        ["PkgName", ("PkgName", None, None)],
        [("PkgName", "!=1.2.3,<2.0"), ("PkgName", "!=1.2.3,<2.0", None)],
        ["[email protected]", ("PkgName", "1.2.3", None)],
        [("[email protected]", "1.2.5"), ("[email protected]", "1.2.5", None)],
        ["id:13", ("id:13", None, None)],
        ["id:13@~1.2.3", ("id:13", "~1.2.3", None)],
        [util.get_home_dir(),
         (".platformio", None, "file://" + util.get_home_dir())],
        ["LocalName=" + util.get_home_dir(),
         ("LocalName", None, "file://" + util.get_home_dir())],
        ["https://github.com/user/package.git",
         ("package", None, "git+https://github.com/user/package.git")],
        ["https://gitlab.com/user/package.git",
         ("package", None, "git+https://gitlab.com/user/package.git")],
        ["https://github.com/user/package/archive/branch.zip",
         ("branch", None,
          "https://github.com/user/package/archive/branch.zip")],
        ["https://github.com/user/package/archive/branch.tar.gz",
         ("branch", None,
          "https://github.com/user/package/archive/branch.tar.gz")],
        ["https://developer.mbed.org/users/user/code/package/",
         ("package", None,
          "hg+https://developer.mbed.org/users/user/code/package/")],
        ["https://github.com/user/package#v1.2.3",
         ("package", None, "git+https://github.com/user/package#v1.2.3")],
        ["https://github.com/user/package.git#branch",
         ("package", None, "git+https://github.com/user/package.git#branch")],
        ["PkgName=https://github.com/user/package.git#a13d344fg56",
         ("PkgName", None,
          "git+https://github.com/user/package.git#a13d344fg56")],
        ["PkgName=user/package",
         ("PkgName", None, "git+https://github.com/user/package")],
        ["PkgName=user/package#master",
         ("PkgName", None, "git+https://github.com/user/package#master")],
        ["git+https://github.com/user/package",
         ("package", None, "git+https://github.com/user/package")],
        ["hg+https://example.com/user/package",
         ("package", None, "hg+https://example.com/user/package")],
        ["[email protected]:user/package.git",
         ("package", None, "[email protected]:user/package.git")],
        ["[email protected]:user/package.git#v1.2.0",
         ("package", None, "[email protected]:user/package.git#v1.2.0")]
    ]
    for params, result in items:
        if isinstance(params, tuple):
            assert BasePkgManager.parse_pkg_name(*params) == result
        else:
            assert BasePkgManager.parse_pkg_name(params) == result
Exemplo n.º 14
0
    def check_pkg_structure(self, pkg_dir):
        try:
            return BasePkgManager.check_pkg_structure(self, pkg_dir)
        except exception.MissingPackageManifest:
            # we will generate manifest automatically
            pass

        manifest = {
            "name": "Library_" + md5(pkg_dir).hexdigest()[:5],
            "version": "0.0.0"
        }
        manifest_path = self._find_any_manifest(pkg_dir)
        if manifest_path:
            _manifest = self._parse_manifest(manifest_path)
            pkg_dir = dirname(manifest_path)
            for key in ("name", "version"):
                if key not in _manifest:
                    _manifest[key] = manifest[key]
            manifest = _manifest
        else:
            for root, dirs, files in os.walk(pkg_dir):
                if len(dirs) == 1 and not files:
                    manifest['name'] = dirs[0]
                    continue
                if dirs or files:
                    pkg_dir = root
                    break

        with open(join(pkg_dir, self.manifest_name), "w") as fp:
            json.dump(manifest, fp)

        return pkg_dir
Exemplo n.º 15
0
    def install(self,
                name,
                requirements=None,
                with_packages=None,
                without_packages=None,
                skip_default_package=False,
                after_update=False,
                silent=False,
                force=False,
                **_):  # pylint: disable=too-many-arguments, arguments-differ
        platform_dir = BasePkgManager.install(self,
                                              name,
                                              requirements,
                                              silent=silent,
                                              force=force)
        p = PlatformFactory.newPlatform(platform_dir)

        # don't cleanup packages or install them after update
        # we check packages for updates in def update()
        if after_update:
            return True

        p.install_packages(with_packages,
                           without_packages,
                           skip_default_package,
                           silent=silent,
                           force=force)
        return self.cleanup_packages(list(p.packages))
Exemplo n.º 16
0
    def install(self,
                name,
                requirements=None,
                with_packages=None,
                without_packages=None,
                skip_default_package=False,
                trigger_event=True,
                silent=False,
                force=False,
                **_):  # pylint: disable=too-many-arguments, arguments-differ
        platform_dir = BasePkgManager.install(
            self, name, requirements, silent=silent, force=force)
        p = PlatformFactory.newPlatform(platform_dir)

        # @Hook: when 'update' operation (trigger_event is False),
        # don't cleanup packages or install them
        if not trigger_event:
            return True
        p.install_packages(
            with_packages,
            without_packages,
            skip_default_package,
            silent=silent,
            force=force)
        self.cleanup_packages(p.packages.keys())
        return True
Exemplo n.º 17
0
    def install(self,
                name,
                requirements=None,
                with_packages=None,
                without_packages=None,
                skip_default_package=False,
                after_update=False,
                silent=False,
                force=False,
                **_):  # pylint: disable=too-many-arguments, arguments-differ
        platform_dir = BasePkgManager.install(
            self, name, requirements, silent=silent, force=force)
        p = PlatformFactory.newPlatform(platform_dir)

        # don't cleanup packages or install them after update
        # we check packages for updates in def update()
        if after_update:
            return True

        p.install_packages(
            with_packages,
            without_packages,
            skip_default_package,
            silent=silent,
            force=force)
        return self.cleanup_packages(p.packages.keys())
Exemplo n.º 18
0
    def install(self,
                name,
                requirements=None,
                silent=False,
                trigger_event=True,
                interactive=False):
        already_installed = False
        _name, _requirements, _url = self.parse_pkg_name(name, requirements)

        try:
            if not _url:
                _name = "id=%d" % self._get_pkg_id_by_name(
                    _name,
                    _requirements,
                    silent=silent,
                    interactive=interactive)
            already_installed = self.get_package(_name, _requirements, _url)
            pkg_dir = BasePkgManager.install(
                self, _name
                if not _url else name, _requirements, silent, trigger_event)
        except exception.InternetIsOffline as e:
            if not silent:
                click.secho(str(e), fg="yellow")
            return

        if already_installed:
            return

        manifest = self.load_manifest(pkg_dir)
        if "dependencies" not in manifest:
            return pkg_dir

        if not silent:
            click.secho("Installing dependencies", fg="yellow")

        for filters in self.normalize_dependencies(manifest['dependencies']):
            assert "name" in filters
            if any([s in filters.get("version", "") for s in ("\\", "/")]):
                self.install("{name}={version}".format(**filters))
            else:
                try:
                    lib_info = self.search_for_library(filters, silent,
                                                       interactive)
                except exception.LibNotFound as e:
                    if not silent:
                        click.secho("Warning! %s" % e, fg="yellow")
                    continue

                if filters.get("version"):
                    self.install(
                        lib_info['id'],
                        requirements=filters.get("version"),
                        silent=silent,
                        trigger_event=trigger_event)
                else:
                    self.install(
                        lib_info['id'],
                        silent=silent,
                        trigger_event=trigger_event)
        return pkg_dir
Exemplo n.º 19
0
    def check_pkg_structure(self, pkg_dir):
        try:
            return BasePkgManager.check_pkg_structure(self, pkg_dir)
        except exception.MissingPackageManifest:
            # we will generate manifest automatically
            pass

        manifest = {
            "name": "Library_" + md5(pkg_dir).hexdigest()[:5],
            "version": "0.0.0"
        }
        manifest_path = self._find_any_manifest(pkg_dir)
        if manifest_path:
            _manifest = self._parse_manifest(manifest_path)
            pkg_dir = dirname(manifest_path)
            for key in ("name", "version"):
                if key not in _manifest:
                    _manifest[key] = manifest[key]
            manifest = _manifest
        else:
            for root, dirs, files in os.walk(pkg_dir):
                if len(dirs) == 1 and not files:
                    manifest['name'] = dirs[0]
                    continue
                if dirs or files:
                    pkg_dir = root
                    break

        with open(join(pkg_dir, self.manifest_name), "w") as fp:
            json.dump(manifest, fp)

        return pkg_dir
Exemplo n.º 20
0
    def install(  # pylint: disable=arguments-differ
            self,
            name,
            requirements=None,
            silent=False,
            trigger_event=True,
            interactive=False):
        pkg_dir = None
        try:
            _name, _requirements, _url = self.parse_pkg_input(
                name, requirements)
            if not _url:
                name = "id=%d" % self.get_pkg_id_by_name(
                    _name,
                    _requirements,
                    silent=silent,
                    interactive=interactive)
                requirements = _requirements
            pkg_dir = BasePkgManager.install(self, name, requirements, silent,
                                             trigger_event)
        except exception.InternetIsOffline as e:
            if not silent:
                click.secho(str(e), fg="yellow")
            return

        if not pkg_dir:
            return

        manifest = self.load_manifest(pkg_dir)
        if "dependencies" not in manifest:
            return pkg_dir

        if not silent:
            click.secho("Installing dependencies", fg="yellow")

        for filters in self.normalize_dependencies(manifest['dependencies']):
            assert "name" in filters
            if any([s in filters.get("version", "") for s in ("\\", "/")]):
                self.install("{name}={version}".format(**filters))
            else:
                try:
                    lib_info = self.search_for_library(filters, silent,
                                                       interactive)
                except exception.LibNotFound as e:
                    if not silent:
                        click.secho("Warning! %s" % e, fg="yellow")
                    continue

                if filters.get("version"):
                    self.install(
                        lib_info['id'],
                        requirements=filters.get("version"),
                        silent=silent,
                        trigger_event=trigger_event)
                else:
                    self.install(
                        lib_info['id'],
                        silent=silent,
                        trigger_event=trigger_event)
        return pkg_dir
Exemplo n.º 21
0
    def install(self,
                name,
                requirements=None,
                with_packages=None,
                without_packages=None,
                skip_default_package=False,
                trigger_event=True,
                silent=False,
                force=False,
                **_):  # pylint: disable=too-many-arguments, arguments-differ
        platform_dir = BasePkgManager.install(
            self, name, requirements, silent=silent, force=force)
        p = PlatformFactory.newPlatform(platform_dir)

        # @Hook: when 'update' operation (trigger_event is False),
        # don't cleanup packages or install them
        if not trigger_event:
            return True
        p.install_packages(
            with_packages,
            without_packages,
            skip_default_package,
            silent=silent,
            force=force)
        self.cleanup_packages(p.packages.keys())
        return True
Exemplo n.º 22
0
 def install(
     self, name, requirements=None, with_packages=None, without_packages=None, skip_default_package=False, **_
 ):  # pylint: disable=too-many-arguments
     platform_dir = BasePkgManager.install(self, name, requirements)
     p = PlatformFactory.newPlatform(self.get_manifest_path(platform_dir))
     p.install_packages(with_packages, without_packages, skip_default_package)
     self.cleanup_packages(p.packages.keys())
     return True
Exemplo n.º 23
0
    def uninstall(self, package, requirements=None, trigger_event=True):
        if isdir(package):
            pkg_dir = package
        else:
            name, requirements, url = self.parse_pkg_input(
                package, requirements)
            pkg_dir = self.get_package_dir(name, requirements, url)

        p = PlatformFactory.newPlatform(pkg_dir)
        BasePkgManager.uninstall(self, pkg_dir, requirements)

        # @Hook: when 'update' operation (trigger_event is False),
        # don't cleanup packages or install them
        if not trigger_event:
            return True

        self.cleanup_packages(p.packages.keys())
        return True
Exemplo n.º 24
0
    def uninstall(self, package, requirements=None, trigger_event=True):
        if isdir(package):
            pkg_dir = package
        else:
            name, requirements, url = self.parse_pkg_input(
                package, requirements)
            pkg_dir = self.get_package_dir(name, requirements, url)

        p = PlatformFactory.newPlatform(pkg_dir)
        BasePkgManager.uninstall(self, pkg_dir, requirements)

        # @Hook: when 'update' operation (trigger_event is False),
        # don't cleanup packages or install them
        if not trigger_event:
            return True

        self.cleanup_packages(p.packages.keys())
        return True
Exemplo n.º 25
0
    def uninstall(self, package, requirements=None, after_update=False):
        if isdir(package):
            pkg_dir = package
        else:
            name, requirements, url = self.parse_pkg_uri(package, requirements)
            pkg_dir = self.get_package_dir(name, requirements, url)

        if not pkg_dir:
            raise exception.UnknownPlatform(package)

        p = PlatformFactory.newPlatform(pkg_dir)
        BasePkgManager.uninstall(self, pkg_dir, requirements)

        # don't cleanup packages or install them after update
        # we check packages for updates in def update()
        if after_update:
            return True

        return self.cleanup_packages(list(p.packages))
Exemplo n.º 26
0
    def uninstall(self, package, requirements=None, after_update=False):
        if isdir(package):
            pkg_dir = package
        else:
            name, requirements, url = self.parse_pkg_uri(package, requirements)
            pkg_dir = self.get_package_dir(name, requirements, url)

        if not pkg_dir:
            raise exception.UnknownPlatform(package)

        p = PlatformFactory.newPlatform(pkg_dir)
        BasePkgManager.uninstall(self, pkg_dir, requirements)

        # don't cleanup packages or install them after update
        # we check packages for updates in def update()
        if after_update:
            return True

        return self.cleanup_packages(p.packages.keys())
Exemplo n.º 27
0
 def install(self,  # pylint: disable=too-many-arguments
             name,
             requirements=None,
             with_packages=None,
             without_packages=None,
             skip_default_package=False,
             **_):
     platform_dir = BasePkgManager.install(self, name, requirements)
     p = PlatformFactory.newPlatform(self.get_manifest_path(platform_dir))
     p.install_packages(with_packages, without_packages,
                        skip_default_package)
     self.cleanup_packages(p.packages.keys())
     return True
Exemplo n.º 28
0
    def get_manifest_path(self, pkg_dir):
        path = BasePkgManager.get_manifest_path(self, pkg_dir)
        if path:
            return path

        # if library without manifest, returns first source file
        src_dir = join(util.glob_escape(pkg_dir))
        if isdir(join(pkg_dir, "src")):
            src_dir = join(src_dir, "src")
        chs_files = glob(join(src_dir, "*.[chS]"))
        if chs_files:
            return chs_files[0]
        cpp_files = glob(join(src_dir, "*.cpp"))
        if cpp_files:
            return cpp_files[0]

        return None
Exemplo n.º 29
0
    def get_manifest_path(self, pkg_dir):
        path = BasePkgManager.get_manifest_path(self, pkg_dir)
        if path:
            return path

        # if library without manifest, returns first source file
        src_dir = join(util.glob_escape(pkg_dir))
        if isdir(join(pkg_dir, "src")):
            src_dir = join(src_dir, "src")
        chs_files = glob(join(src_dir, "*.[chS]"))
        if chs_files:
            return chs_files[0]
        cpp_files = glob(join(src_dir, "*.cpp"))
        if cpp_files:
            return cpp_files[0]

        return None
Exemplo n.º 30
0
    def install(
            self,  # pylint: disable=too-many-arguments
            name,
            requirements=None,
            silent=False,
            trigger_event=True,
            interactive=False):
        _name, _requirements, _url = self.parse_pkg_name(name, requirements)
        if not _url:
            _name = "id=%d" % self._get_pkg_id_by_name(
                _name, _requirements, silent=silent, interactive=interactive)
        already_installed = self.get_package(_name, _requirements, _url)
        pkg_dir = BasePkgManager.install(self, _name if not _url else name,
                                         _requirements, silent, trigger_event)

        if already_installed:
            return

        manifest = self.load_manifest(pkg_dir)
        if "dependencies" not in manifest:
            return pkg_dir

        if not silent:
            click.secho("Installing dependencies", fg="yellow")

        for filters in self.normalize_dependencies(manifest['dependencies']):
            assert "name" in filters
            if any([s in filters.get("version", "") for s in ("\\", "/")]):
                self.install("{name}={version}".format(**filters))
            else:
                lib_info = self.search_for_library(filters, silent,
                                                   interactive)
                if filters.get("version"):
                    self.install(lib_info['id'],
                                 requirements=filters.get("version"),
                                 silent=silent,
                                 trigger_event=trigger_event)
                else:
                    self.install(lib_info['id'],
                                 silent=silent,
                                 trigger_event=trigger_event)
        return pkg_dir
Exemplo n.º 31
0
 def is_outdated(self, name, requirements=None):
     if BasePkgManager.is_outdated(self, name, requirements):
         return True
     p = PlatformFactory.newPlatform(name, requirements)
     return p.are_outdated_packages()
Exemplo n.º 32
0
def test_pkg_name_parser():
    items = [
        ["PkgName", ("PkgName", None, None)],
        [("PkgName", "!=1.2.3,<2.0"), ("PkgName", "!=1.2.3,<2.0", None)],
        ["[email protected]", ("PkgName", "1.2.3", None)],
        [("[email protected]", "1.2.5"), ("[email protected]", "1.2.5", None)],
        ["id:13", ("id:13", None, None)],
        ["id:13@~1.2.3", ("id:13", "~1.2.3", None)], [
            util.get_home_dir(),
            (".platformio", None, "file://" + util.get_home_dir())
        ], [
            "LocalName=" + util.get_home_dir(),
            ("LocalName", None, "file://" + util.get_home_dir())
        ], [
            "https://github.com/user/package.git",
            ("package", None, "git+https://github.com/user/package.git")
        ], [
            "https://gitlab.com/user/package.git",
            ("package", None, "git+https://gitlab.com/user/package.git")
        ], [
            "https://github.com/user/package/archive/branch.zip",
            ("branch", None,
             "https://github.com/user/package/archive/branch.zip")
        ], [
            "https://github.com/user/package/archive/branch.tar.gz",
            ("branch", None,
             "https://github.com/user/package/archive/branch.tar.gz")
        ], [
            "https://developer.mbed.org/users/user/code/package/",
            ("package", None,
             "hg+https://developer.mbed.org/users/user/code/package/")
        ], [
            "https://github.com/user/package#v1.2.3",
            ("package", None, "git+https://github.com/user/package#v1.2.3")
        ], [
            "https://github.com/user/package.git#branch",
            ("package", None, "git+https://github.com/user/package.git#branch")
        ], [
            "PkgName=https://github.com/user/package.git#a13d344fg56",
            ("PkgName", None,
             "git+https://github.com/user/package.git#a13d344fg56")
        ], [
            "PkgName=user/package",
            ("PkgName", None, "git+https://github.com/user/package")
        ], [
            "PkgName=user/package#master",
            ("PkgName", None, "git+https://github.com/user/package#master")
        ], [
            "git+https://github.com/user/package",
            ("package", None, "git+https://github.com/user/package")
        ], [
            "hg+https://example.com/user/package",
            ("package", None, "hg+https://example.com/user/package")
        ], [
            "[email protected]:user/package.git",
            ("package", None, "[email protected]:user/package.git")
        ], [
            "[email protected]:user/package.git#v1.2.0",
            ("package", None, "[email protected]:user/package.git#v1.2.0")
        ], [
            "git+ssh://[email protected]/user/package#1.2.0",
            ("package", None,
             "git+ssh://[email protected]/user/package#1.2.0")
        ]
    ]
    for params, result in items:
        if isinstance(params, tuple):
            assert BasePkgManager.parse_pkg_name(*params) == result
        else:
            assert BasePkgManager.parse_pkg_name(params) == result
Exemplo n.º 33
0
 def __init__(self, package_dir=None):
     if not package_dir:
         package_dir = join(util.get_home_dir(), "lib")
     BasePkgManager.__init__(self, package_dir)
Exemplo n.º 34
0
 def is_outdated(self, name, requirements=None):
     if BasePkgManager.is_outdated(self, name, requirements):
         return True
     p = PlatformFactory.newPlatform(name, requirements)
     return p.are_outdated_packages()
Exemplo n.º 35
0
    def load_manifest(self, pkg_dir):
        manifest = BasePkgManager.load_manifest(self, pkg_dir)
        if not manifest:
            return manifest

        # if Arduino library.properties
        if "sentence" in manifest:
            manifest['frameworks'] = ["arduino"]
            manifest['description'] = manifest['sentence']
            del manifest['sentence']

        if "author" in manifest:
            if isinstance(manifest['author'], dict):
                manifest['authors'] = [manifest['author']]
            else:
                manifest['authors'] = [{"name": manifest['author']}]
            del manifest['author']

        if "authors" in manifest and not isinstance(manifest['authors'], list):
            manifest['authors'] = [manifest['authors']]

        if "keywords" not in manifest:
            keywords = []
            for keyword in re.split(r"[\s/]+",
                                    manifest.get("category", "Uncategorized")):
                keyword = keyword.strip()
                if not keyword:
                    continue
                keywords.append(keyword.lower())
            manifest['keywords'] = keywords
            if "category" in manifest:
                del manifest['category']

        # don't replace VCS URL
        if "url" in manifest and "description" in manifest:
            manifest['homepage'] = manifest['url']
            del manifest['url']

        if "architectures" in manifest:
            platforms = []
            platforms_map = {
                "avr": "atmelavr",
                "sam": "atmelsam",
                "samd": "atmelsam",
                "esp8266": "espressif8266",
                "arc32": "intel_arc32"
            }
            for arch in manifest['architectures'].split(","):
                arch = arch.strip()
                if arch == "*":
                    platforms = "*"
                    break
                if arch in platforms_map:
                    platforms.append(platforms_map[arch])
            manifest['platforms'] = platforms
            del manifest['architectures']

        # convert listed items via comma to array
        for key in ("keywords", "frameworks", "platforms"):
            if key not in manifest or \
                    not isinstance(manifest[key], basestring):
                continue
            manifest[key] = [
                i.strip() for i in manifest[key].split(",") if i.strip()
            ]

        return manifest
Exemplo n.º 36
0
 def __init__(self, package_dir=None):
     if not package_dir:
         package_dir = join(util.get_home_dir(), "lib")
     BasePkgManager.__init__(self, package_dir)
Exemplo n.º 37
0
    def install(  # pylint: disable=arguments-differ
            self,
            name,
            requirements=None,
            silent=False,
            trigger_event=True,
            interactive=False,
            force=False):
        _name, _requirements, _url = self.parse_pkg_uri(name, requirements)
        if not _url:
            name = "id=%d" % self.search_lib_id(
                {
                    "name": _name,
                    "requirements": _requirements
                },
                silent=silent,
                interactive=interactive)
            requirements = _requirements
        pkg_dir = BasePkgManager.install(self,
                                         name,
                                         requirements,
                                         silent=silent,
                                         trigger_event=trigger_event,
                                         force=force)

        if not pkg_dir:
            return None

        manifest = self.load_manifest(pkg_dir)
        if "dependencies" not in manifest:
            return pkg_dir

        if not silent:
            click.secho("Installing dependencies", fg="yellow")

        for filters in self.normalize_dependencies(manifest['dependencies']):
            assert "name" in filters
            if any([s in filters.get("version", "") for s in ("\\", "/")]):
                self.install("{name}={version}".format(**filters),
                             silent=silent,
                             trigger_event=trigger_event,
                             interactive=interactive,
                             force=force)
            else:
                try:
                    lib_id = self.search_lib_id(filters, silent, interactive)
                except exception.LibNotFound as e:
                    if not silent or is_builtin_lib(filters['name']):
                        click.secho("Warning! %s" % e, fg="yellow")
                    continue

                if filters.get("version"):
                    self.install(lib_id,
                                 filters.get("version"),
                                 silent=silent,
                                 trigger_event=trigger_event,
                                 interactive=interactive,
                                 force=force)
                else:
                    self.install(lib_id,
                                 silent=silent,
                                 trigger_event=trigger_event,
                                 interactive=interactive,
                                 force=force)
        return pkg_dir
Exemplo n.º 38
0
    def install(  # pylint: disable=arguments-differ
        self,
        name,
        requirements=None,
        silent=False,
        after_update=False,
        interactive=False,
        force=False,
    ):
        _name, _requirements, _url = self.parse_pkg_uri(name, requirements)
        if not _url:
            name = "id=%d" % self.search_lib_id(
                {
                    "name": _name,
                    "requirements": _requirements
                },
                silent=silent,
                interactive=interactive,
            )
            requirements = _requirements
        pkg_dir = BasePkgManager.install(
            self,
            name,
            requirements,
            silent=silent,
            after_update=after_update,
            force=force,
        )

        if not pkg_dir:
            return None

        manifest = None
        try:
            manifest = ManifestParserFactory.new_from_dir(pkg_dir).as_dict()
        except ManifestException:
            pass
        if not manifest or not manifest.get("dependencies"):
            return pkg_dir

        if not silent:
            click.secho("Installing dependencies", fg="yellow")

        builtin_lib_storages = None
        for filters in manifest["dependencies"]:
            assert "name" in filters

            # avoid circle dependencies
            if not self.INSTALL_HISTORY:
                self.INSTALL_HISTORY = []
            history_key = str(filters)
            if history_key in self.INSTALL_HISTORY:
                continue
            self.INSTALL_HISTORY.append(history_key)

            if any(s in filters.get("version", "") for s in ("\\", "/")):
                self.install(
                    "{name}={version}".format(**filters),
                    silent=silent,
                    after_update=after_update,
                    interactive=interactive,
                    force=force,
                )
            else:
                try:
                    lib_id = self.search_lib_id(filters, silent, interactive)
                except exception.LibNotFound as e:
                    if builtin_lib_storages is None:
                        builtin_lib_storages = get_builtin_libs()
                    if not silent or is_builtin_lib(builtin_lib_storages,
                                                    filters["name"]):
                        click.secho("Warning! %s" % e, fg="yellow")
                    continue

                if filters.get("version"):
                    self.install(
                        lib_id,
                        filters.get("version"),
                        silent=silent,
                        after_update=after_update,
                        interactive=interactive,
                        force=force,
                    )
                else:
                    self.install(
                        lib_id,
                        silent=silent,
                        after_update=after_update,
                        interactive=interactive,
                        force=force,
                    )
        return pkg_dir
Exemplo n.º 39
0
    def load_manifest(self, pkg_dir):
        manifest = BasePkgManager.load_manifest(self, pkg_dir)
        if not manifest:
            return manifest

        # if Arduino library.properties
        if "sentence" in manifest:
            manifest['frameworks'] = ["arduino"]
            manifest['description'] = manifest['sentence']
            del manifest['sentence']

        if "author" in manifest:
            if isinstance(manifest['author'], dict):
                manifest['authors'] = [manifest['author']]
            else:
                manifest['authors'] = [{"name": manifest['author']}]
            del manifest['author']

        if "authors" in manifest and not isinstance(manifest['authors'], list):
            manifest['authors'] = [manifest['authors']]

        if "keywords" not in manifest:
            keywords = []
            for keyword in re.split(r"[\s/]+",
                                    manifest.get("category", "Uncategorized")):
                keyword = keyword.strip()
                if not keyword:
                    continue
                keywords.append(keyword.lower())
            manifest['keywords'] = keywords
            if "category" in manifest:
                del manifest['category']

        # don't replace VCS URL
        if "url" in manifest and "description" in manifest:
            manifest['homepage'] = manifest['url']
            del manifest['url']

        if "architectures" in manifest:
            platforms = []
            platforms_map = {
                "avr": "atmelavr",
                "sam": "atmelsam",
                "samd": "atmelsam",
                "esp8266": "espressif8266",
                "esp32": "espressif32",
                "arc32": "intel_arc32"
            }
            for arch in manifest['architectures'].split(","):
                arch = arch.strip()
                if arch == "*":
                    platforms = "*"
                    break
                if arch in platforms_map:
                    platforms.append(platforms_map[arch])
            manifest['platforms'] = platforms
            del manifest['architectures']

        # convert listed items via comma to array
        for key in ("keywords", "frameworks", "platforms"):
            if key not in manifest or \
                    not isinstance(manifest[key], basestring):
                continue
            manifest[key] = [
                i.strip() for i in manifest[key].split(",") if i.strip()
            ]

        return manifest
Exemplo n.º 40
0
    def install(  # pylint: disable=arguments-differ
            self,
            name,
            requirements=None,
            silent=False,
            after_update=False,
            interactive=False,
            force=False):
        _name, _requirements, _url = self.parse_pkg_uri(name, requirements)
        if not _url:
            name = "id=%d" % self.search_lib_id({
                "name": _name,
                "requirements": _requirements
            },
                                                silent=silent,
                                                interactive=interactive)
            requirements = _requirements
        pkg_dir = BasePkgManager.install(
            self,
            name,
            requirements,
            silent=silent,
            after_update=after_update,
            force=force)

        if not pkg_dir:
            return None

        manifest = self.load_manifest(pkg_dir)
        if "dependencies" not in manifest:
            return pkg_dir

        if not silent:
            click.secho("Installing dependencies", fg="yellow")

        for filters in self.normalize_dependencies(manifest['dependencies']):
            assert "name" in filters

            # avoid circle dependencies
            if not self.INSTALL_HISTORY:
                self.INSTALL_HISTORY = []
            history_key = str(filters)
            if history_key in self.INSTALL_HISTORY:
                continue
            self.INSTALL_HISTORY.append(history_key)

            if any(s in filters.get("version", "") for s in ("\\", "/")):
                self.install(
                    "{name}={version}".format(**filters),
                    silent=silent,
                    after_update=after_update,
                    interactive=interactive,
                    force=force)
            else:
                try:
                    lib_id = self.search_lib_id(filters, silent, interactive)
                except exception.LibNotFound as e:
                    if not silent or is_builtin_lib(filters['name']):
                        click.secho("Warning! %s" % e, fg="yellow")
                    continue

                if filters.get("version"):
                    self.install(
                        lib_id,
                        filters.get("version"),
                        silent=silent,
                        after_update=after_update,
                        interactive=interactive,
                        force=force)
                else:
                    self.install(
                        lib_id,
                        silent=silent,
                        after_update=after_update,
                        interactive=interactive,
                        force=force)
        return pkg_dir