Beispiel #1
0
    def test_user_config_dir_osx(self,
                                 monkeypatch: pytest.MonkeyPatch) -> None:
        monkeypatch.setenv("HOME", "/home/test")

        if os.path.isdir("/home/test/Library/Application Support/"):
            assert (appdirs.user_config_dir("pip") ==
                    "/home/test/Library/Application Support/pip")
        else:
            assert appdirs.user_config_dir("pip") == "/home/test/.config/pip"
Beispiel #2
0
    def test_user_config_dir_osx(self, monkeypatch):
        monkeypatch.setattr(_appdirs, "system", "darwin")
        monkeypatch.setattr(os, "path", posixpath)
        monkeypatch.setenv("HOME", "/home/test")
        monkeypatch.setattr(sys, "platform", "darwin")

        if os.path.isdir('/home/test/Library/Application Support/'):
            assert (appdirs.user_config_dir("pip") ==
                    "/home/test/Library/Application Support/pip")
        else:
            assert (appdirs.user_config_dir("pip") == "/home/test/.config/pip")
Beispiel #3
0
    def test_user_config_dir_linux_home_slash(
            self, monkeypatch: pytest.MonkeyPatch) -> None:
        # Verify that we are not affected by https://bugs.python.org/issue14768
        monkeypatch.delenv("XDG_CONFIG_HOME", raising=False)
        monkeypatch.setenv("HOME", "/")

        assert appdirs.user_config_dir("pip") == "/.config/pip"
Beispiel #4
0
    def test_user_config_dir_linux_override(self, monkeypatch):
        monkeypatch.setattr(appdirs, "WINDOWS", False)
        monkeypatch.setattr(os, "path", posixpath)
        monkeypatch.setenv("XDG_CONFIG_HOME", "/home/test/.other-config")
        monkeypatch.setenv("HOME", "/home/test")
        monkeypatch.setattr(sys, "platform", "linux2")

        assert appdirs.user_config_dir("pip") == "/home/test/.other-config/pip"
Beispiel #5
0
    def test_user_config_dir_linux(self, monkeypatch):
        monkeypatch.setattr(_appdirs, "system", "linux2")
        monkeypatch.setattr(os, "path", posixpath)
        monkeypatch.delenv("XDG_CONFIG_HOME", raising=False)
        monkeypatch.setenv("HOME", "/home/test")
        monkeypatch.setattr(sys, "platform", "linux2")

        assert appdirs.user_config_dir("pip") == "/home/test/.config/pip"
Beispiel #6
0
    def test_user_config_dir_linux_override(self, monkeypatch):
        monkeypatch.setattr(_appdirs, "system", "linux2")
        monkeypatch.setattr(os, "path", posixpath)
        monkeypatch.setenv("XDG_CONFIG_HOME", "/home/test/.other-config")
        monkeypatch.setenv("HOME", "/home/test")
        monkeypatch.setattr(sys, "platform", "linux2")

        assert appdirs.user_config_dir("pip") == "/home/test/.other-config/pip"
Beispiel #7
0
    def test_user_config_dir_linux_home_slash(self, monkeypatch):
        monkeypatch.setattr(appdirs, "WINDOWS", False)
        monkeypatch.setattr(os, "path", posixpath)
        # Verify that we are not affected by http://bugs.python.org/issue14768
        monkeypatch.delenv("XDG_CONFIG_HOME", raising=False)
        monkeypatch.setenv("HOME", "/")
        monkeypatch.setattr(sys, "platform", "linux2")

        assert appdirs.user_config_dir("pip") == "/.config/pip"
Beispiel #8
0
    def test_user_config_dir_linux_home_slash(self, monkeypatch):
        monkeypatch.setattr(_appdirs, "system", "linux2")
        monkeypatch.setattr(os, "path", posixpath)
        # Verify that we are not affected by https://bugs.python.org/issue14768
        monkeypatch.delenv("XDG_CONFIG_HOME", raising=False)
        monkeypatch.setenv("HOME", "/")
        monkeypatch.setattr(sys, "platform", "linux2")

        assert appdirs.user_config_dir("pip") == "/.config/pip"
Beispiel #9
0
    def test_user_config_dir_win_yes_roaming(
            self, monkeypatch: pytest.MonkeyPatch) -> None:
        _get_win_folder = mock.Mock(
            return_value="C:\\Users\\test\\AppData\\Roaming")

        monkeypatch.setattr(
            platformdirs.windows,  # type: ignore
            "get_win_folder",
            _get_win_folder,
            raising=False,
        )

        assert (appdirs.user_config_dir("pip") ==
                "C:\\Users\\test\\AppData\\Roaming\\pip")
        assert _get_win_folder.call_args_list == [mock.call("CSIDL_APPDATA")]
Beispiel #10
0
def get_configuration_files():
    # type: () -> Dict[Kind, List[str]]
    global_config_files = [
        os.path.join(path, CONFIG_BASENAME) for path in appdirs.site_config_dirs("pip")
    ]

    site_config_file = os.path.join(sys.prefix, CONFIG_BASENAME)
    legacy_config_file = os.path.join(
        expanduser("~"), "pip" if WINDOWS else ".pip", CONFIG_BASENAME
    )
    new_config_file = os.path.join(appdirs.user_config_dir("pip"), CONFIG_BASENAME)
    return {
        kinds.GLOBAL: global_config_files,
        kinds.SITE: [site_config_file],
        kinds.USER: [legacy_config_file, new_config_file],
    }
Beispiel #11
0
    def test_user_config_dir_win_yes_roaming(self, monkeypatch):
        @pretend.call_recorder
        def _get_win_folder(base):
            return "C:\\Users\\test\\AppData\\Roaming"

        monkeypatch.setattr(
            _appdirs,
            "_get_win_folder",
            _get_win_folder,
            raising=False,
        )
        monkeypatch.setattr(_appdirs, "system", "win32")
        monkeypatch.setattr(os, "path", ntpath)

        assert (appdirs.user_config_dir("pip") ==
                "C:\\Users\\test\\AppData\\Roaming\\pip")
        assert _get_win_folder.calls == [pretend.call("CSIDL_APPDATA")]
Beispiel #12
0
    def test_user_config_dir_win_yes_roaming(self, monkeypatch):
        @pretend.call_recorder
        def _get_win_folder(base):
            return "C:\\Users\\test\\AppData\\Roaming"

        monkeypatch.setattr(
            appdirs,
            "_get_win_folder",
            _get_win_folder,
            raising=False,
        )
        monkeypatch.setattr(appdirs, "WINDOWS", True)
        monkeypatch.setattr(os, "path", ntpath)

        assert (appdirs.user_config_dir("pip") ==
                "C:\\Users\\test\\AppData\\Roaming\\pip")
        assert _get_win_folder.calls == [pretend.call("CSIDL_APPDATA")]
Beispiel #13
0
    def test_user_config_dir_win_no_roaming(self, monkeypatch):
        @pretend.call_recorder
        def _get_win_folder(base):
            return "C:\\Users\\test\\AppData\\Local"

        monkeypatch.setattr(
            appdirs,
            "_get_win_folder",
            _get_win_folder,
            raising=False,
        )
        monkeypatch.setattr(appdirs, "WINDOWS", True)
        monkeypatch.setattr(os, "path", ntpath)

        assert (appdirs.user_config_dir(
            "pip", roaming=False) == "C:\\Users\\test\\AppData\\Local\\pip")
        assert _get_win_folder.calls == [pretend.call("CSIDL_LOCAL_APPDATA")]
def get_configuration_files():
    global_config_files = [
        os.path.join(path, CONFIG_BASENAME)
        for path in appdirs.site_config_dirs('pip')
    ]

    site_config_file = os.path.join(sys.prefix, CONFIG_BASENAME)
    legacy_config_file = os.path.join(
        expanduser('~'),
        'pip' if WINDOWS else '.pip',
        CONFIG_BASENAME,
    )
    new_config_file = os.path.join(appdirs.user_config_dir("pip"),
                                   CONFIG_BASENAME)
    return {
        kinds.GLOBAL: global_config_files,
        kinds.SITE: [site_config_file],
        kinds.USER: [legacy_config_file, new_config_file],
    }
Beispiel #15
0
    def __init__(self):
        self.user_config_dir = appdirs.user_config_dir(appname="aip")
        self.config_file_path = str(Path(self.user_config_dir, 'aip.conf'))
        if os.path.exists(self.config_file_path):
            self.config_file = open(self.config_file_path, 'r+')
            self.cp = ConfigParser()
            self.cp.read(self.config_file_path)
            self.check_board_version()
        else:  #if first time execute aip, create defalut config file.
            if not os.path.exists(self.user_config_dir):
                os.mkdir(self.user_config_dir)
            if (os.path.exists(str(Path(self.user_config_dir, "ardupycore")))):
                shutil.rmtree(str(Path(self.user_config_dir, "ardupycore")))

            for path in os.listdir(self.user_config_dir):
                if path.find('json') != -1:
                    os.remove(str(Path(self.user_config_dir, path)))

            self.config_file = open(self.config_file_path, 'w+')
            self.cp = ConfigParser()
            self.cp.add_section('board')
            self.cp.set(
                "board", "additional_url",
                "http://files.seeedstudio.com/ardupy/package_new_seeeduino_ardupy_index.json"
            )
            self.cp.add_section('library')
            self.cp.set("library", "additional_url", "")
            self.cp.write(self.config_file)
            self.config_file.close()
            self.update_loacl_board_json()
            #self.update_loacl_library_json()

        self.boards = []
        self.packages = []

        self.parser_all_json()
        self.system = get_platform()
Beispiel #16
0
        -Wuninitialized \
        -Wno-unused-label \
        -std=gnu99 \
        -U_FORTIFY_SOURCE \
        -Os \
        "


def readonly_handler(func, path, execinfo):
    os.chmod(path, stat.S_IWRITE)
    func(path)


# List of supported board USB IDs.  Each board is a tuple of unique USB vendor
# ID, USB product ID.
user_config_dir = appdirs.user_config_dir(appname="aip")
today = date.today()
package_seeeduino_ardupy_index_json = str(
    Path(user_config_dir,
         "package_seeeduino_ardupy_index_" + today.isoformat() + ".json"))
if os.path.exists(package_seeeduino_ardupy_index_json):
    with open(package_seeeduino_ardupy_index_json, 'r') as load_f:
        json_dict = json.load(load_f)
        BOARD_IDS = json_dict['board']
else:
    try:
        for file in os.listdir(user_config_dir):
            if "package_seeeduino_ardupy_index_" in file:
                package_seeeduino_ardupy_index_json = str(
                    Path(user_config_dir, file))
                with open(package_seeeduino_ardupy_index_json, 'r') as load_f:
Beispiel #17
0
=======
    # type: () -> Dict[Kind, List[str]]
>>>>>>> development
    global_config_files = [
        os.path.join(path, CONFIG_BASENAME)
        for path in appdirs.site_config_dirs('pip')
    ]

    site_config_file = os.path.join(sys.prefix, CONFIG_BASENAME)
    legacy_config_file = os.path.join(
        expanduser('~'),
        'pip' if WINDOWS else '.pip',
        CONFIG_BASENAME,
    )
    new_config_file = os.path.join(
        appdirs.user_config_dir("pip"), CONFIG_BASENAME
    )
    return {
        kinds.GLOBAL: global_config_files,
        kinds.SITE: [site_config_file],
        kinds.USER: [legacy_config_file, new_config_file],
    }


class Configuration(object):
    """Handles management of configuration.

    Provides an interface to accessing and managing configuration files.

    This class converts provides an API that takes "section.key-name" style
    keys and stores the value associated with it as "key-name" under the
Beispiel #18
0
    config_basename = "pip.conf"

    legacy_storage_dir = os.path.join(user_dir, ".pip")
    legacy_config_file = os.path.join(legacy_storage_dir, config_basename)
    # Forcing to use /usr/local/bin for standard macOS framework installs
    # Also log to ~/Library/Logs/ for use with the Console.app log viewer
    if sys.platform[:6] == "darwin" and sys.prefix[:16] == "/System/Library/":
        bin_py = "/usr/local/bin"

site_config_files = [
    os.path.join(path, config_basename)
    for path in appdirs.site_config_dirs("pip")
]

venv_config_file = os.path.join(sys.prefix, config_basename)
new_config_file = os.path.join(appdirs.user_config_dir("pip"), config_basename)


def distutils_scheme(dist_name,
                     user=False,
                     home=None,
                     root=None,
                     isolated=False,
                     prefix=None):
    """
    Return a distutils install scheme
    """
    from distutils.dist import Distribution

    scheme = {}
Beispiel #19
0
    legacy_config_file = os.path.join(
        legacy_storage_dir,
        config_basename,
    )
    # Forcing to use /usr/local/bin for standard macOS framework installs
    # Also log to ~/Library/Logs/ for use with the Console.app log viewer
    if sys.platform[:6] == 'darwin' and sys.prefix[:16] == '/System/Library/':
        bin_py = '/usr/local/bin'

global_config_files = [
    os.path.join(path, config_basename)
    for path in appdirs.site_config_dirs('pip')
]

site_config_file = os.path.join(sys.prefix, config_basename)
new_config_file = os.path.join(appdirs.user_config_dir("pip"), config_basename)


def distutils_scheme(dist_name, user=False, home=None, root=None,
                     isolated=False, prefix=None):
    # type:(str, bool, str, str, bool, str) -> dict
    """
    Return a distutils install scheme
    """
    from distutils.dist import Distribution

    scheme = {}

    if isolated:
        extra_dist_args = {"script_args": ["--no-user-cfg"]}
    else:
Beispiel #20
0
    def test_user_config_dir_linux_override(
            self, monkeypatch: pytest.MonkeyPatch) -> None:
        monkeypatch.setenv("XDG_CONFIG_HOME", "/home/test/.other-config")
        monkeypatch.setenv("HOME", "/home/test")

        assert appdirs.user_config_dir("pip") == "/home/test/.other-config/pip"
Beispiel #21
0
    def test_user_config_dir_linux(self,
                                   monkeypatch: pytest.MonkeyPatch) -> None:
        monkeypatch.delenv("XDG_CONFIG_HOME", raising=False)
        monkeypatch.setenv("HOME", "/home/test")

        assert appdirs.user_config_dir("pip") == "/home/test/.config/pip"
Beispiel #22
0
def main(args=None):

    # type: (Optional[List[str]]) -> int
    if args is None:
        args = sys.argv[1:]

    # is update package_seeeduino_ardupy_index.json
    user_config_dir = str(appdirs.user_config_dir(appname="aip"))
    if not os.path.exists(user_config_dir):
        os.makedirs(user_config_dir)
    today = date.today()
    user_config_dir_files = os.listdir(user_config_dir)
    current_package_seeeduino_ardupy = "xxxxx"
    is_update = True
    for files in user_config_dir_files:
        if files[0:30] == "package_seeeduino_ardupy_index":
            file_data = datetime.strptime(files[31:41], '%Y-%m-%d').date()
            current_package_seeeduino_ardupy = files
            if file_data == today:
                is_update = False
                break
    if is_update:
        log.info("update latest package_seeeduino_ardupy_index.json ...")
        try:
            urllib.request.urlretrieve(
                'https://files.seeedstudio.com/ardupy/package_seeeduino_ardupy_index.json',
                str(
                    Path(
                        user_config_dir, "package_seeeduino_ardupy_index_" +
                        today.isoformat() + ".json")))
            if os.path.exists(
                    str(Path(user_config_dir,
                             current_package_seeeduino_ardupy))):
                os.remove(
                    str(Path(user_config_dir,
                             current_package_seeeduino_ardupy)))
        except Exception as e:
            log.error(e)
            log.warning(
                "update latest package_seeeduino_ardupy_index.json Failed! Please check you network connction!"
            )
            sys.exit(1)

    from aip.command import commands_dict, parse_command

    # Configure our deprecation warnings to be sent through loggers
    deprecation.install_warning_logger()

    autocomplete()
    try:
        cmd_name, cmd_args = parse_command(args)
    except PipError as exc:
        sys.stderr.write("ERROR: {}".format(exc))
        sys.stderr.write(os.linesep)
        sys.exit(1)

    # Needed for locale.getpreferredencoding(False) to work
    # in pip._internal.utils.encoding.auto_decode
    try:
        locale.setlocale(locale.LC_ALL, '')
    except locale.Error as e:
        # setlocale can apparently crash if locale are uninitialized
        print("Ignoring error %s when setting locale", e)

    module = importlib.import_module("aip." + cmd_name)

    command_class = getattr(module, cmd_name + "Command")
    command = command_class(name=cmd_name, summary="...")

    return command.main(cmd_args)