forked from platformio/platformio-core
Implemented "platformio search" command
This commit is contained in:
1 parent
673a41c21c
commit
bdfe849c97
9 files changed
+66
-14
No files matched your search
@@ -1,78 +0,0 @@
|
||||
# Copyright (C) Ivan Kravets <me@ikravets.com>
|
||||
# See LICENSE for details.
|
||||
|
||||
from os.path import join
|
||||
|
||||
from click import echo, secho, style
|
||||
|
||||
from platformio.exception import (PackageInstalled, UnknownPackage,
|
||||
UnknownPlatform)
|
||||
from platformio.pkgmanager import PackageManager
|
||||
from platformio.util import exec_command, get_source_dir
|
||||
|
||||
|
||||
class PlatformFactory(object):
|
||||
|
||||
@staticmethod
|
||||
def newPlatform(name):
|
||||
clsname = "%sPlatform" % name.title()
|
||||
try:
|
||||
mod = __import__("platformio.platforms." + name.lower(),
|
||||
None, None, [clsname])
|
||||
except ImportError:
|
||||
raise UnknownPlatform(name)
|
||||
|
||||
obj = getattr(mod, clsname)()
|
||||
assert isinstance(obj, BasePlatform)
|
||||
return obj
|
||||
|
||||
|
||||
class BasePlatform(object):
|
||||
|
||||
PACKAGES = {}
|
||||
|
||||
def get_name(self):
|
||||
raise NotImplementedError()
|
||||
|
||||
def install(self, with_packages, without_packages):
|
||||
requirements = []
|
||||
pm = PackageManager(self.get_name())
|
||||
|
||||
upkgs = set(with_packages + without_packages)
|
||||
ppkgs = set(self.PACKAGES.keys())
|
||||
if not upkgs.issubset(ppkgs):
|
||||
raise UnknownPackage(", ".join(upkgs - ppkgs))
|
||||
|
||||
for name, opts in self.PACKAGES.iteritems():
|
||||
if name in without_packages:
|
||||
continue
|
||||
elif name in with_packages or opts["default"]:
|
||||
requirements.append((name, opts["path"]))
|
||||
|
||||
for (name, path) in requirements:
|
||||
echo("Installing %s package:" % style(name, fg="cyan"))
|
||||
try:
|
||||
pm.install(name, path)
|
||||
except PackageInstalled:
|
||||
secho("Already installed", fg="yellow")
|
||||
|
||||
return True
|
||||
|
||||
def after_run(self, result): # pylint: disable=R0201
|
||||
return result
|
||||
|
||||
def run(self, variables, targets):
|
||||
assert isinstance(variables, list)
|
||||
assert isinstance(targets, list)
|
||||
|
||||
if "clean" in targets:
|
||||
targets.remove("clean")
|
||||
targets.append("-c")
|
||||
|
||||
result = exec_command([
|
||||
"scons",
|
||||
"-Q",
|
||||
"-f", join(get_source_dir(), "builder", "main.py")
|
||||
] + variables + targets)
|
||||
|
||||
return self.after_run(result)
|
||||
Reference in new issue
Block a user