Пример #1
0
def cli(ctx, **options):
    non_storage_cmds = ("search", "show", "register", "stats", "builtin")
    # skip commands that don't need storage folder
    if ctx.invoked_subcommand in non_storage_cmds or \
            (len(ctx.args) == 2 and ctx.args[1] in ("-h", "--help")):
        return
    storage_dir = options['storage_dir']
    if not storage_dir:
        if options['global']:
            storage_dir = join(util.get_home_dir(), "lib")
        elif util.is_platformio_project():
            storage_dir = util.get_projectlibdeps_dir()
        elif util.is_ci():
            storage_dir = join(util.get_home_dir(), "lib")
            click.secho(
                "Warning! Global library storage is used automatically. "
                "Please use `platformio lib --global %s` command to remove "
                "this warning." % ctx.invoked_subcommand,
                fg="yellow")
    elif util.is_platformio_project(storage_dir):
        with util.cd(storage_dir):
            storage_dir = util.get_projectlibdeps_dir()

    if not storage_dir and not util.is_platformio_project():
        raise exception.NotGlobalLibDir(util.get_project_dir(),
                                        join(util.get_home_dir(), "lib"),
                                        ctx.invoked_subcommand)

    ctx.obj = LibraryManager(storage_dir)
    if "--json-output" not in ctx.args:
        click.echo("Library Storage: " + storage_dir)
Пример #2
0
def test_project_lib_complex(clirunner, validate_cliresult, tmpdir):
    with tmpdir.as_cwd():
        # init
        result = clirunner.invoke(cmd_init)
        validate_cliresult(result)

        # isntall
        result = clirunner.invoke(cmd_lib, ["install", "54", "ArduinoJson"])
        validate_cliresult(result)
        items1 = [
            d.basename
            for d in tmpdir.join(basename(util.get_projectlibdeps_dir()))
            .listdir()
        ]
        items2 = ["DallasTemperature_ID54", "OneWire_ID1", "ArduinoJson_ID64"]
        assert set(items1) == set(items2)

        # list
        result = clirunner.invoke(cmd_lib, ["list", "--json-output"])
        validate_cliresult(result)
        items1 = [i['name'] for i in json.loads(result.output)]
        items2 = ["DallasTemperature", "OneWire", "ArduinoJson"]
        assert set(items1) == set(items2)

        # update
        result = clirunner.invoke(cmd_lib, ["update"])
        validate_cliresult(result)
        assert "[Up-to-date]" in result.output
Пример #3
0
def test_project_lib_complex(clirunner, validate_cliresult, tmpdir):
    with tmpdir.as_cwd():
        # init
        result = clirunner.invoke(cmd_init)
        validate_cliresult(result)

        # isntall
        result = clirunner.invoke(cmd_lib, ["install", "54", "ArduinoJson"])
        validate_cliresult(result)
        items1 = [
            d.basename for d in tmpdir.join(
                basename(util.get_projectlibdeps_dir())).listdir()
        ]
        items2 = ["DallasTemperature_ID54", "OneWire_ID1", "ArduinoJson_ID64"]
        assert set(items1) == set(items2)

        # list
        result = clirunner.invoke(cmd_lib, ["list", "--json-output"])
        validate_cliresult(result)
        items1 = [i['name'] for i in json.loads(result.output)]
        items2 = ["DallasTemperature", "OneWire", "ArduinoJson"]
        assert set(items1) == set(items2)

        # update
        result = clirunner.invoke(cmd_lib, ["update"])
        validate_cliresult(result)
        assert "[Up-to-date]" in result.output
Пример #4
0
def _autoinstall_libdeps(ctx, libraries, verbose=False):
    storage_dir = util.get_projectlibdeps_dir()
    ctx.obj = LibraryManager(storage_dir)
    if verbose:
        click.echo("Library Storage: " + storage_dir)
    for lib in libraries:
        try:
            ctx.invoke(cmd_lib_install, libraries=[lib], silent=not verbose)
        except exception.LibNotFound as e:
            click.secho("Warning! %s" % e, fg="yellow")
Пример #5
0
def _autoinstall_libdeps(ctx, libraries, verbose=False):
    storage_dir = util.get_projectlibdeps_dir()
    ctx.obj = LibraryManager(storage_dir)
    if verbose:
        click.echo("Library Storage: " + storage_dir)
    for lib in libraries:
        try:
            ctx.invoke(cmd_lib_install, libraries=[lib], silent=not verbose)
        except exception.LibNotFound as e:
            click.secho("Warning! %s" % e, fg="yellow")
Пример #6
0
def _autoinstall_libdeps(ctx, libraries, verbose=False):
    if not libraries:
        return
    storage_dir = util.get_projectlibdeps_dir()
    ctx.obj = LibraryManager(storage_dir)
    if verbose:
        click.echo("Library Storage: " + storage_dir)
    for lib in libraries:
        try:
            ctx.invoke(cmd_lib_install, libraries=[lib], silent=not verbose)
        except exception.LibNotFound as e:
            if verbose or not is_builtin_lib(lib):
                click.secho("Warning! %s" % e, fg="yellow")
        except exception.InternetIsOffline as e:
            click.secho(str(e), fg="yellow")
Пример #7
0
def _autoinstall_libdeps(ctx, libraries, verbose=False):
    if not libraries:
        return
    storage_dir = util.get_projectlibdeps_dir()
    ctx.obj = LibraryManager(storage_dir)
    if verbose:
        click.echo("Library Storage: " + storage_dir)
    for lib in libraries:
        try:
            ctx.invoke(cmd_lib_install, libraries=[lib], silent=not verbose)
        except exception.LibNotFound as e:
            if verbose or not is_builtin_lib(lib):
                click.secho("Warning! %s" % e, fg="yellow")
        except exception.InternetIsOffline as e:
            click.secho(str(e), fg="yellow")
Пример #8
0
 def _gather_tplvars(self):
     self._tplvars.update(self.get_project_env())
     self._tplvars.update(self.get_project_build_data())
     with util.cd(self.project_dir):
         self._tplvars.update({
             "project_name": self.get_project_name(),
             "src_files": self.get_src_files(),
             "user_home_dir": abspath(expanduser("~")),
             "project_dir": self.project_dir,
             "project_src_dir": util.get_projectsrc_dir(),
             "project_lib_dir": util.get_projectlib_dir(),
             "project_libdeps_dir": util.get_projectlibdeps_dir(),
             "systype": util.get_systype(),
             "platformio_path": self._fix_os_path(
                 util.where_is_program("platformio")),
             "env_pathsep": os.pathsep,
             "env_path": self._fix_os_path(os.getenv("PATH"))
         })  # yapf: disable
Пример #9
0
 def _gather_tplvars(self):
     self._tplvars.update(self.get_project_env())
     self._tplvars.update(self.get_project_build_data())
     with util.cd(self.project_dir):
         self._tplvars.update({
             "project_name": self.get_project_name(),
             "src_files": self.get_src_files(),
             "user_home_dir": abspath(expanduser("~")),
             "project_dir": self.project_dir,
             "project_src_dir": util.get_projectsrc_dir(),
             "project_lib_dir": util.get_projectlib_dir(),
             "project_libdeps_dir": util.get_projectlibdeps_dir(),
             "systype": util.get_systype(),
             "platformio_path": self._fix_os_path(
                 sys.argv[0] if isfile(sys.argv[0])
                 else util.where_is_program("platformio")),
             "env_pathsep": os.pathsep,
             "env_path": self._fix_os_path(os.getenv("PATH"))
         })  # yapf: disable
Пример #10
0
    PIOVARIABLES=commonvars.keys(),
    ENV=environ,
    UNIX_TIME=int(time()),
    PROGNAME="program",
    PIOHOME_DIR=util.get_home_dir(),
    PROJECT_DIR=util.get_project_dir(),
    PROJECTSRC_DIR=util.get_projectsrc_dir(),
    PROJECTTEST_DIR=util.get_projecttest_dir(),
    PROJECTDATA_DIR=util.get_projectdata_dir(),
    PROJECTPIOENVS_DIR=util.get_projectpioenvs_dir(),
    BUILD_DIR=join("$PROJECTPIOENVS_DIR", "$PIOENV"),
    BUILDSRC_DIR=join("$BUILD_DIR", "src"),
    BUILDTEST_DIR=join("$BUILD_DIR", "test"),
    LIBSOURCE_DIRS=[
        util.get_projectlib_dir(),
        util.get_projectlibdeps_dir(),
        join("$PIOHOME_DIR", "lib")
    ],
    PYTHONEXE=util.get_pythonexe_path())

if not int(ARGUMENTS.get("PIOVERBOSE", 0)):
    DEFAULT_ENV_OPTIONS['ARCOMSTR'] = "Archiving $TARGET"
    DEFAULT_ENV_OPTIONS['LINKCOMSTR'] = "Linking $TARGET"
    DEFAULT_ENV_OPTIONS['RANLIBCOMSTR'] = "Indexing $TARGET"
    for k in ("ASCOMSTR", "ASPPCOMSTR", "CCCOMSTR", "CXXCOMSTR"):
        DEFAULT_ENV_OPTIONS[k] = "Compiling $TARGET"

env = DefaultEnvironment(**DEFAULT_ENV_OPTIONS)

# decode common variables
for k in commonvars.keys():
Пример #11
0
    PIOVARIABLES=commonvars.keys(),
    ENV=environ,
    UNIX_TIME=int(time()),
    PIOHOME_DIR=util.get_home_dir(),
    PROJECT_DIR=util.get_project_dir(),
    PROJECTINCLUDE_DIR=util.get_projectinclude_dir(),
    PROJECTSRC_DIR=util.get_projectsrc_dir(),
    PROJECTTEST_DIR=util.get_projecttest_dir(),
    PROJECTDATA_DIR=util.get_projectdata_dir(),
    PROJECTBUILD_DIR=util.get_projectbuild_dir(),
    BUILD_DIR=join("$PROJECTBUILD_DIR", "$PIOENV"),
    BUILDSRC_DIR=join("$BUILD_DIR", "src"),
    BUILDTEST_DIR=join("$BUILD_DIR", "test"),
    LIBSOURCE_DIRS=[
        util.get_projectlib_dir(),
        util.get_projectlibdeps_dir(),
        join("$PIOHOME_DIR", "lib")
    ],
    PROGNAME="program",
    PROG_PATH=join("$BUILD_DIR", "$PROGNAME$PROGSUFFIX"),
    PYTHONEXE=util.get_pythonexe_path())

if not int(ARGUMENTS.get("PIOVERBOSE", 0)):
    DEFAULT_ENV_OPTIONS['ARCOMSTR'] = "Archiving $TARGET"
    DEFAULT_ENV_OPTIONS['LINKCOMSTR'] = "Linking $TARGET"
    DEFAULT_ENV_OPTIONS['RANLIBCOMSTR'] = "Indexing $TARGET"
    for k in ("ASCOMSTR", "ASPPCOMSTR", "CCCOMSTR", "CXXCOMSTR"):
        DEFAULT_ENV_OPTIONS[k] = "Compiling $TARGET"

env = DefaultEnvironment(**DEFAULT_ENV_OPTIONS)
Пример #12
0
def _autoinstall_libdeps(ctx, libraries, verbose=False):
    storage_dir = util.get_projectlibdeps_dir()
    ctx.obj = LibraryManager(storage_dir)
    if verbose:
        click.echo("Library Storage: " + storage_dir)
    ctx.invoke(cmd_lib_install, libraries=libraries, silent=not verbose)
Пример #13
0
    variables=commonvars,
    # Propagating External Environment
    PIOVARIABLES=commonvars.keys(),
    ENV=environ,
    UNIX_TIME=int(time()),
    PROGNAME="program",
    PIOHOME_DIR=util.get_home_dir(),
    PROJECT_DIR=util.get_project_dir(),
    PROJECTSRC_DIR=util.get_projectsrc_dir(),
    PROJECTTEST_DIR=util.get_projecttest_dir(),
    PROJECTDATA_DIR=util.get_projectdata_dir(),
    PROJECTPIOENVS_DIR=util.get_projectpioenvs_dir(),
    BUILD_DIR=join("$PROJECTPIOENVS_DIR", "$PIOENV"),
    BUILDSRC_DIR=join("$BUILD_DIR", "src"),
    BUILDTEST_DIR=join("$BUILD_DIR", "test"),
    LIBSOURCE_DIRS=[util.get_projectlib_dir(), util.get_projectlibdeps_dir(), join("$PIOHOME_DIR", "lib")],
    PYTHONEXE=util.get_pythonexe_path(),
)

if not int(ARGUMENTS.get("PIOVERBOSE", 0)):
    DEFAULT_ENV_OPTIONS["ARCOMSTR"] = "Archiving $TARGET"
    DEFAULT_ENV_OPTIONS["LINKCOMSTR"] = "Linking $TARGET"
    DEFAULT_ENV_OPTIONS["RANLIBCOMSTR"] = "Indexing $TARGET"
    for k in ("ASCOMSTR", "ASPPCOMSTR", "CCCOMSTR", "CXXCOMSTR"):
        DEFAULT_ENV_OPTIONS[k] = "Compiling $TARGET"

env = DefaultEnvironment(**DEFAULT_ENV_OPTIONS)

# decode common variables
for k in commonvars.keys():
    if k in env: