Пример #1
0
class BaseProcess(protocol.ProcessProtocol, object):

    STDOUT_CHUNK_SIZE = 2048

    COMMON_PATTERNS = {
        "PLATFORMIO_HOME_DIR": get_project_core_dir(),
        "PLATFORMIO_CORE_DIR": get_project_core_dir(),
        "PYTHONEXE": get_pythonexe_path(),
    }

    def apply_patterns(self, source, patterns=None):
        _patterns = self.COMMON_PATTERNS.copy()
        _patterns.update(patterns or {})

        for key, value in _patterns.items():
            if key.endswith(("_DIR", "_PATH")):
                _patterns[key] = fs.to_unix_path(value)

        def _replace(text):
            for key, value in _patterns.items():
                pattern = "$%s" % key
                text = text.replace(pattern, value or "")
            return text

        if isinstance(source, string_types):
            source = _replace(source)
        elif isinstance(source, (list, dict)):
            items = enumerate(source) if isinstance(source,
                                                    list) else source.items()
            for key, value in items:
                if isinstance(value, string_types):
                    source[key] = _replace(value)
                elif isinstance(value, (list, dict)):
                    source[key] = self.apply_patterns(value, patterns)

        return source

    def outReceived(self, data):
        if LOG_FILE:
            with open(LOG_FILE, "ab") as fp:
                fp.write(data)
        while data:
            chunk = data[:self.STDOUT_CHUNK_SIZE]
            click.echo(chunk, nl=False)
            data = data[self.STDOUT_CHUNK_SIZE:]

    @staticmethod
    def errReceived(data):
        if LOG_FILE:
            with open(LOG_FILE, "ab") as fp:
                fp.write(data)
        click.echo(data, nl=False, err=True)

    @staticmethod
    def processEnded(_):
        # Allow terminating via SIGINT/CTRL+C
        signal.signal(signal.SIGINT, signal.default_int_handler)
Пример #2
0
def test_get_package():
    tests = [
        [("unknown", ), None],
        [("1", ), None],
        [("id=1", "shasum"),
         dict(id=1, name="name_1", version="shasum")],
        [("id=1", "*"),
         dict(id=1, name="name_1", version="2.1.0")],
        [("id=1", "^1"),
         dict(id=1, name="name_1", version="1.2")],
        [("id=1", "^1"),
         dict(id=1, name="name_1", version="1.2")],
        [("name_1", "<2"),
         dict(id=1, name="name_1", version="1.2")],
        [("name_1", ">2"), None],
        [("name_1", "2-0-0"), None],
        [("name_2", ), dict(name="name_2", version="4.0.0")],
        [("url_has_higher_priority", None, "git+https://github.com"),
         dict(name="name_2",
              version="2.0.0",
              __src_url="git+https://github.com")],
        [("name_2", None, "git+https://github.com"),
         dict(name="name_2",
              version="2.0.0",
              __src_url="git+https://github.com")],
    ]

    pm = PackageManager(join(get_project_core_dir(), "packages"))
    for test in tests:
        manifest = pm.get_package(*test[0])
        if test[1] is None:
            assert manifest is None, test
            continue
        for key, value in test[1].items():
            assert manifest[key] == value, test
Пример #3
0
 def __init__(self, path=None, lock=False):
     self.path = path
     self.lock = lock
     if not self.path:
         self.path = join(get_project_core_dir(), "appstate.json")
     self._storage = {}
     self._lockfile = None
     self.modified = False
Пример #4
0
 def __exit__(self, type_, value, traceback):
     if self.modified:
         try:
             with open(self.path, "w") as fp:
                 fp.write(dump_json_to_unicode(self._storage))
         except IOError:
             raise exception.HomeDirPermissionsError(get_project_core_dir())
     self._unlock_state_file()
Пример #5
0
class AppRPC(object):

    APPSTATE_PATH = join(get_project_core_dir(), "homestate.json")

    IGNORE_STORAGE_KEYS = [
        "cid", "coreVersion", "coreSystype", "coreCaller", "coreSettings",
        "homeDir", "projectsDir"
    ]

    @staticmethod
    def load_state():
        with app.State(AppRPC.APPSTATE_PATH, lock=True) as state:
            storage = state.get("storage", {})

            # base data
            caller_id = app.get_session_var("caller_id")
            storage['cid'] = app.get_cid()
            storage['coreVersion'] = __version__
            storage['coreSystype'] = util.get_systype()
            storage['coreCaller'] = (str(caller_id).lower()
                                     if caller_id else None)
            storage['coreSettings'] = {
                name: {
                    "description": data['description'],
                    "default_value": data['value'],
                    "value": app.get_setting(name)
                }
                for name, data in app.DEFAULT_SETTINGS.items()
            }

            storage['homeDir'] = expanduser("~")
            storage['projectsDir'] = storage['coreSettings']['projects_dir'][
                'value']

            # skip non-existing recent projects
            storage['recentProjects'] = [
                p for p in storage.get("recentProjects", [])
                if is_platformio_project(p)
            ]

            state['storage'] = storage
            state.modified = False  # skip saving extra fields
            return state.as_dict()

    @staticmethod
    def get_state():
        return AppRPC.load_state()

    @staticmethod
    def save_state(state):
        with app.State(AppRPC.APPSTATE_PATH, lock=True) as s:
            s.clear()
            s.update(state)
            storage = s.get("storage", {})
            for k in AppRPC.IGNORE_STORAGE_KEYS:
                if k in storage:
                    del storage[k]
        return True
Пример #6
0
    def __init__(self, name, share, working_dir=None):
        RemoteClientBase.__init__(self)
        self.log_level = LogLevel.info
        self.working_dir = working_dir or join(get_project_core_dir(),
                                               "remote")
        if not isdir(self.working_dir):
            os.makedirs(self.working_dir)
        if name:
            self.name = str(name)[:50]
        self.join_options.update({
            "agent":
            True,
            "share": [s.lower().strip()[:50] for s in share]
        })

        self._acs = {}
Пример #7
0
def test_install_packages(isolated_pio_home, tmpdir):
    packages = [
        dict(id=1, name="name_1", version="shasum"),
        dict(id=1, name="name_1", version="2.0.0"),
        dict(id=1, name="name_1", version="2.1.0"),
        dict(id=1, name="name_1", version="1.2"),
        dict(id=1, name="name_1", version="1.0.0"),
        dict(name="name_2", version="1.0.0"),
        dict(name="name_2",
             version="2.0.0",
             __src_url="git+https://github.com"),
        dict(name="name_2",
             version="3.0.0",
             __src_url="git+https://github2.com"),
        dict(name="name_2",
             version="4.0.0",
             __src_url="git+https://github2.com"),
    ]

    pm = PackageManager(join(get_project_core_dir(), "packages"))
    for package in packages:
        tmp_dir = tmpdir.mkdir("tmp-package")
        tmp_dir.join("package.json").write(json.dumps(package))
        pm._install_from_url(package["name"], "file://%s" % str(tmp_dir))
        tmp_dir.remove(rec=1)

    assert len(pm.get_installed()) == len(packages) - 1

    pkg_dirnames = [
        "name_1_ID1",
        "[email protected]",
        "[email protected]",
        "[email protected]",
        "name_1_ID1@shasum",
        "name_2",
        "name_2@src-177cbce1f0705580d17790fda1cc2ef5",
        "name_2@src-f863b537ab00f4c7b5011fc44b120e1f",
    ]
    assert set([
        p.basename for p in isolated_pio_home.join("packages").listdir()
    ]) == set(pkg_dirnames)
Пример #8
0
    def get_boards(self, id_=None):

        def _append_board(board_id, manifest_path):
            config = PlatformBoardConfig(manifest_path)
            if "platform" in config and config.get("platform") != self.name:
                return
            if "platforms" in config \
                    and self.name not in config.get("platforms"):
                return
            config.manifest['platform'] = self.name
            self._BOARDS_CACHE[board_id] = config

        bdirs = [
            get_project_boards_dir(),
            join(get_project_core_dir(), "boards"),
            join(self.get_dir(), "boards"),
        ]

        if id_ is None:
            for boards_dir in bdirs:
                if not isdir(boards_dir):
                    continue
                for item in sorted(os.listdir(boards_dir)):
                    _id = item[:-5]
                    if not item.endswith(".json") or _id in self._BOARDS_CACHE:
                        continue
                    _append_board(_id, join(boards_dir, item))
        else:
            if id_ not in self._BOARDS_CACHE:
                for boards_dir in bdirs:
                    if not isdir(boards_dir):
                        continue
                    manifest_path = join(boards_dir, "%s.json" % id_)
                    if isfile(manifest_path):
                        _append_board(id_, manifest_path)
                        break
            if id_ not in self._BOARDS_CACHE:
                raise exception.UnknownBoard(id_)
        return self._BOARDS_CACHE[id_] if id_ else self._BOARDS_CACHE
Пример #9
0
def test_pkg_input_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)],
        [
            get_project_core_dir(),
            (".platformio", None, "file://" + get_project_core_dir()),
        ],
        [
            "LocalName=" + get_project_core_dir(),
            ("LocalName", None, "file://" + get_project_core_dir()),
        ],
        [
            "LocalName=%s@>2.3.0" % get_project_core_dir(),
            ("LocalName", ">2.3.0", "file://" + get_project_core_dir()),
        ],
        [
            "https://github.com/user/package.git",
            ("package", None, "git+https://github.com/user/package.git"),
        ],
        [
            "MyPackage=https://gitlab.com/user/package.git",
            ("MyPackage", None, "git+https://gitlab.com/user/package.git"),
        ],
        [
            "MyPackage=https://gitlab.com/user/[email protected],!=2",
            ("MyPackage", "3.2.1,!=2",
             "git+https://gitlab.com/user/package.git"),
        ],
        [
            "https://somedomain.com/path/LibraryName-1.2.3.zip",
            (
                "LibraryName-1.2.3",
                None,
                "https://somedomain.com/path/LibraryName-1.2.3.zip",
            ),
        ],
        [
            "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.zip@~1.2.3",
            ("branch", "~1.2.3",
             "https://github.com/user/package/archive/branch.zip"),
        ],
        [
            "https://github.com/user/package/archive/branch.tar.gz",
            (
                "branch.tar",
                None,
                "https://github.com/user/package/archive/branch.tar.gz",
            ),
        ],
        [
            "https://github.com/user/package/archive/branch.tar.gz@!=5",
            (
                "branch.tar",
                "!=5",
                "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://os.mbed.com/users/user/code/package/",
            ("package", None,
             "hg+https://os.mbed.com/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"),
        ],
        [
            "user/package",
            ("package", None, "git+https://github.com/user/package")
        ],
        [
            "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"),
        ],
        [
            "[email protected]:user/package.git#v1.2.0@~1.2.0",
            ("LocalName", "~1.2.0",
             "[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",
            ),
        ],
        [
            "git+ssh://[email protected]:1234/package#1.2.0",
            (
                "package",
                None,
                "git+ssh://[email protected]:1234/package#1.2.0",
            ),
        ],
        [
            "LocalName=git+ssh://[email protected]:1234"
            "/package#1.2.0@!=13",
            (
                "LocalName",
                "!=13",
                "git+ssh://[email protected]:1234/package#1.2.0",
            ),
        ],
    ]
    for params, result in items:
        if isinstance(params, tuple):
            assert PackageManager.parse_pkg_uri(*params) == result
        else:
            assert PackageManager.parse_pkg_uri(params) == result
Пример #10
0
    ("UPLOAD_PORT",)
)  # yapf: disable

DEFAULT_ENV_OPTIONS = dict(
    tools=[
        "ar", "gas", "gcc", "g++", "gnulink", "platformio", "pioplatform",
        "pioproject", "piowinhooks", "piolib", "pioupload", "piomisc", "pioide"
    ],
    toolpath=[join(util.get_source_dir(), "builder", "tools")],
    variables=clivars,

    # Propagating External Environment
    ENV=environ,
    UNIX_TIME=int(time()),
    PROJECT_DIR=project_helpers.get_project_dir(),
    PROJECTCORE_DIR=project_helpers.get_project_core_dir(),
    PROJECTPACKAGES_DIR=project_helpers.get_project_packages_dir(),
    PROJECTWORKSPACE_DIR=project_helpers.get_project_workspace_dir(),
    PROJECTLIBDEPS_DIR=project_helpers.get_project_libdeps_dir(),
    PROJECTINCLUDE_DIR=project_helpers.get_project_include_dir(),
    PROJECTSRC_DIR=project_helpers.get_project_src_dir(),
    PROJECTTEST_DIR=project_helpers.get_project_test_dir(),
    PROJECTDATA_DIR=project_helpers.get_project_data_dir(),
    PROJECTBUILD_DIR=project_helpers.get_project_build_dir(),
    BUILDCACHE_DIR=project_helpers.get_project_optional_dir("build_cache_dir"),
    BUILD_DIR=join("$PROJECTBUILD_DIR", "$PIOENV"),
    BUILDSRC_DIR=join("$BUILD_DIR", "src"),
    BUILDTEST_DIR=join("$BUILD_DIR", "test"),
    LIBPATH=["$BUILD_DIR"],
    LIBSOURCE_DIRS=[
        project_helpers.get_project_lib_dir(),