forked from platformio/platformio-core
Refactored "base" paltform
This commit is contained in:
1 parent
02d7aa1e1e
commit
dac83d6164
11 files changed
+47
-22
No files matched your search
@@ -3,7 +3,7 @@
|
||||
|
||||
from os.path import join
|
||||
|
||||
from platformio.platforms._base import BasePlatform
|
||||
from platformio.platforms.base import BasePlatform
|
||||
|
||||
|
||||
class AtmelavrPlatform(BasePlatform):
|
||||
|
||||
@@ -40,30 +40,55 @@ class BasePlatform(object):
|
||||
else:
|
||||
raise NotImplementedError()
|
||||
|
||||
def install(self, with_packages, without_packages):
|
||||
requirements = []
|
||||
pm = PackageManager(self.get_name())
|
||||
def get_pkgname_by_alias(self, alias):
|
||||
for name, opts in self.PACKAGES.items():
|
||||
if opts.get("alias", None) == alias:
|
||||
return name
|
||||
return None
|
||||
|
||||
upkgs = set(with_packages + without_packages)
|
||||
def install(self, with_packages, without_packages, skip_default_packages):
|
||||
with_packages = set(with_packages)
|
||||
without_packages = set(without_packages)
|
||||
|
||||
upkgs = with_packages | without_packages
|
||||
ppkgs = set(self.PACKAGES.keys())
|
||||
if not upkgs.issubset(ppkgs):
|
||||
raise UnknownPackage(", ".join(upkgs - ppkgs))
|
||||
unknown = upkgs - ppkgs
|
||||
if unknown:
|
||||
_unknown = unknown.copy()
|
||||
# maybe aliases
|
||||
for alias in unknown:
|
||||
pkgname = self.get_pkgname_by_alias(alias)
|
||||
if pkgname not in self.PACKAGES:
|
||||
continue
|
||||
if alias in with_packages:
|
||||
with_packages.discard(alias)
|
||||
with_packages.add(pkgname)
|
||||
if alias in without_packages:
|
||||
without_packages.discard(alias)
|
||||
without_packages.add(pkgname)
|
||||
_unknown.discard(alias)
|
||||
|
||||
for name, opts in self.PACKAGES.iteritems():
|
||||
if _unknown:
|
||||
raise UnknownPackage(", ".join(_unknown))
|
||||
|
||||
requirements = []
|
||||
for name, opts in self.PACKAGES.items():
|
||||
if name in without_packages:
|
||||
continue
|
||||
elif name in with_packages or opts["default"]:
|
||||
requirements.append((name, opts["path"]))
|
||||
elif (name in with_packages or (not skip_default_packages and
|
||||
opts['default'])):
|
||||
requirements.append((name, opts['path']))
|
||||
|
||||
pm = PackageManager(self.get_name())
|
||||
for (package, path) in requirements:
|
||||
pm.install(package, path)
|
||||
return True
|
||||
return len(requirements)
|
||||
|
||||
def uninstall(self):
|
||||
platform = self.get_name()
|
||||
pm = PackageManager(platform)
|
||||
|
||||
for package, data in pm.get_installed(platform).iteritems():
|
||||
for package, data in pm.get_installed(platform).items():
|
||||
pm.uninstall(package, data['path'])
|
||||
|
||||
pm.unregister_platform(platform)
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
from os.path import join
|
||||
|
||||
from platformio.platforms._base import BasePlatform
|
||||
from platformio.platforms.base import BasePlatform
|
||||
|
||||
|
||||
class Timsp430Platform(BasePlatform):
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
from os.path import join
|
||||
|
||||
from platformio.platforms._base import BasePlatform
|
||||
from platformio.platforms.base import BasePlatform
|
||||
|
||||
|
||||
class TitivaPlatform(BasePlatform):
|
||||
|
||||
Reference in new issue
Block a user