vscode-offline 0.1.0__py3-none-any.whl → 0.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- vscode_offline/app.py +55 -16
- vscode_offline/download.py +1 -1
- vscode_offline/install.py +7 -4
- vscode_offline/utils.py +56 -0
- {vscode_offline-0.1.0.dist-info → vscode_offline-0.1.1.dist-info}/METADATA +11 -8
- vscode_offline-0.1.1.dist-info/RECORD +10 -0
- vscode_offline/paths.py +0 -25
- vscode_offline-0.1.0.dist-info/RECORD +0 -10
- {vscode_offline-0.1.0.dist-info → vscode_offline-0.1.1.dist-info}/WHEEL +0 -0
- {vscode_offline-0.1.0.dist-info → vscode_offline-0.1.1.dist-info}/entry_points.txt +0 -0
vscode_offline/app.py
CHANGED
@@ -6,8 +6,12 @@ from pathlib import Path
|
|
6
6
|
|
7
7
|
from vscode_offline.download import download_vscode_extensions, download_vscode_server
|
8
8
|
from vscode_offline.install import install_vscode_extensions, install_vscode_server
|
9
|
-
from vscode_offline.
|
9
|
+
from vscode_offline.loggers import logger
|
10
|
+
from vscode_offline.utils import (
|
11
|
+
get_target_platform_from_installer,
|
10
12
|
get_vscode_cli_bin,
|
13
|
+
get_vscode_commit_from_code_version,
|
14
|
+
get_vscode_commit_from_installer,
|
11
15
|
get_vscode_extensions_config,
|
12
16
|
get_vscode_server_home,
|
13
17
|
)
|
@@ -18,6 +22,14 @@ cli_os_mapping = {
|
|
18
22
|
|
19
23
|
|
20
24
|
def download(args: Namespace) -> None:
|
25
|
+
if args.commit is None:
|
26
|
+
args.commit = get_vscode_commit_from_code_version()
|
27
|
+
if args.commit is None:
|
28
|
+
logger.info(
|
29
|
+
"Cannot determine commit from `code --version`, please specify --commit manually."
|
30
|
+
)
|
31
|
+
raise ValueError("Please specify --commit when installing.")
|
32
|
+
|
21
33
|
download_vscode_server(
|
22
34
|
args.commit,
|
23
35
|
output=args.installer / f"cli-{args.commit}",
|
@@ -31,9 +43,27 @@ def download(args: Namespace) -> None:
|
|
31
43
|
|
32
44
|
|
33
45
|
def install(args: Namespace) -> None:
|
46
|
+
if args.commit is None:
|
47
|
+
args.commit = get_vscode_commit_from_installer(args.installer)
|
48
|
+
if args.commit is None:
|
49
|
+
logger.info(
|
50
|
+
f"Cannot determine commit from `{args.installer}`, please specify --commit manually."
|
51
|
+
)
|
52
|
+
raise ValueError("Please specify --commit when installing.")
|
53
|
+
|
54
|
+
if args.target_platform is None:
|
55
|
+
args.target_platform = get_target_platform_from_installer(
|
56
|
+
args.installer / f"cli-{args.commit}"
|
57
|
+
)
|
58
|
+
if args.target_platform is None:
|
59
|
+
logger.info(
|
60
|
+
f"Cannot determine target platform from `{args.installer}`, please specify --target-platform manually."
|
61
|
+
)
|
62
|
+
raise ValueError("Please specify --target-platform when installing.")
|
63
|
+
|
34
64
|
install_vscode_server(
|
35
65
|
args.commit,
|
36
|
-
|
66
|
+
cli_installer=args.installer / f"cli-{args.commit}",
|
37
67
|
vscode_cli_bin=get_vscode_cli_bin(args.commit),
|
38
68
|
target_platform=args.target_platform,
|
39
69
|
cli_os=cli_os_mapping[args.target_platform],
|
@@ -48,18 +78,6 @@ def install(args: Namespace) -> None:
|
|
48
78
|
def make_argparser() -> ArgumentParser:
|
49
79
|
parent_parser = ArgumentParser(add_help=False)
|
50
80
|
|
51
|
-
parent_parser.add_argument(
|
52
|
-
"--commit",
|
53
|
-
type=str,
|
54
|
-
required=True,
|
55
|
-
help="The commit hash of the VSCode server to download, must match the version of the VSCode client.",
|
56
|
-
)
|
57
|
-
parent_parser.add_argument(
|
58
|
-
"--target-platform",
|
59
|
-
type=str,
|
60
|
-
default="linux-x64",
|
61
|
-
help="The target platform for the VSCode server.",
|
62
|
-
)
|
63
81
|
parent_parser.add_argument(
|
64
82
|
"--installer",
|
65
83
|
type=Path,
|
@@ -76,6 +94,17 @@ def make_argparser() -> ArgumentParser:
|
|
76
94
|
parents=[parent_parser],
|
77
95
|
)
|
78
96
|
download_parser.set_defaults(func=download)
|
97
|
+
download_parser.add_argument(
|
98
|
+
"--commit",
|
99
|
+
type=str,
|
100
|
+
help="The commit hash of the VSCode server to download, must match the version of the VSCode client.",
|
101
|
+
)
|
102
|
+
download_parser.add_argument(
|
103
|
+
"--target-platform",
|
104
|
+
type=str,
|
105
|
+
required=True,
|
106
|
+
help="The target platform of the VSCode server to download.",
|
107
|
+
)
|
79
108
|
download_parser.add_argument(
|
80
109
|
"--extensions-config",
|
81
110
|
type=Path,
|
@@ -83,12 +112,22 @@ def make_argparser() -> ArgumentParser:
|
|
83
112
|
help="Path to the extensions configuration file. Will search for extensions to download.",
|
84
113
|
)
|
85
114
|
|
86
|
-
|
115
|
+
install_parser = subparsers.add_parser(
|
87
116
|
"install",
|
88
117
|
help="Install VSCode server and extensions",
|
89
118
|
parents=[parent_parser],
|
90
119
|
)
|
91
|
-
|
120
|
+
install_parser.set_defaults(func=install)
|
121
|
+
install_parser.add_argument(
|
122
|
+
"--commit",
|
123
|
+
type=str,
|
124
|
+
help="The commit hash of the VSCode server to install.",
|
125
|
+
)
|
126
|
+
install_parser.add_argument(
|
127
|
+
"--target-platform",
|
128
|
+
type=str,
|
129
|
+
help="The target platform of the VSCode server to install.",
|
130
|
+
)
|
92
131
|
|
93
132
|
return parser
|
94
133
|
|
vscode_offline/download.py
CHANGED
@@ -13,7 +13,7 @@ def _download_file(url: str, filename: str) -> None:
|
|
13
13
|
with urlopen(url) as resp:
|
14
14
|
content_encoding = resp.headers.get("Content-Encoding")
|
15
15
|
if content_encoding in {"gzip", "deflate"}:
|
16
|
-
logger.info(f"Content
|
16
|
+
logger.info(f"Content-Encoding is {content_encoding}, using GzipFile")
|
17
17
|
reader = GzipFile(fileobj=resp)
|
18
18
|
elif not content_encoding:
|
19
19
|
reader = resp
|
vscode_offline/install.py
CHANGED
@@ -6,8 +6,9 @@ from pathlib import Path
|
|
6
6
|
from tempfile import TemporaryDirectory
|
7
7
|
|
8
8
|
from vscode_offline.loggers import logger
|
9
|
-
from vscode_offline.
|
9
|
+
from vscode_offline.utils import get_vscode_server_home
|
10
10
|
|
11
|
+
# These extensions are excluded because they are not needed in a VSCode server.
|
11
12
|
EXCLUDE_EXTENSIONS = {
|
12
13
|
"ms-vscode-remote.remote-ssh",
|
13
14
|
"ms-vscode-remote.remote-ssh-edit",
|
@@ -39,14 +40,14 @@ def install_vscode_extensions(vscode_bin: os.PathLike[str], vsix_dir: str) -> No
|
|
39
40
|
|
40
41
|
def install_vscode_server(
|
41
42
|
commit: str,
|
42
|
-
|
43
|
+
cli_installer: str,
|
43
44
|
vscode_cli_bin: os.PathLike[str],
|
44
45
|
target_platform: str,
|
45
46
|
cli_os: str,
|
46
47
|
) -> None:
|
47
48
|
cli_os_ = cli_os.replace("-", "_")
|
48
49
|
|
49
|
-
vscode_cli_tarball = Path(
|
50
|
+
vscode_cli_tarball = Path(cli_installer) / f"vscode_{cli_os_}_cli.tar.gz"
|
50
51
|
with TemporaryDirectory() as tmpdir:
|
51
52
|
subprocess.check_call(["tar", "-xzf", vscode_cli_tarball, "-C", tmpdir])
|
52
53
|
tmpfile = Path(tmpdir) / "code"
|
@@ -56,7 +57,9 @@ def install_vscode_server(
|
|
56
57
|
os.rename(tmpfile, vscode_cli_bin)
|
57
58
|
logger.info(f"Extracted vscode_{cli_os_}_cli.tar.gz to {vscode_cli_bin}")
|
58
59
|
|
59
|
-
vscode_server_tarball =
|
60
|
+
vscode_server_tarball = (
|
61
|
+
Path(cli_installer) / f"vscode-server-{target_platform}.tar.gz"
|
62
|
+
)
|
60
63
|
vscode_server_home = get_vscode_server_home(commit)
|
61
64
|
os.makedirs(vscode_server_home, exist_ok=True)
|
62
65
|
subprocess.check_call(
|
vscode_offline/utils.py
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
3
|
+
import os
|
4
|
+
import subprocess
|
5
|
+
from pathlib import Path
|
6
|
+
from vscode_offline.loggers import logger
|
7
|
+
|
8
|
+
VSCODE_DATA = Path("~/.vscode").expanduser()
|
9
|
+
VSCODE_SERVER_DATA = Path("~/.vscode-server").expanduser()
|
10
|
+
|
11
|
+
|
12
|
+
def get_vscode_cli_bin(commit: str) -> os.PathLike[str]:
|
13
|
+
return VSCODE_SERVER_DATA / f"code-{commit}"
|
14
|
+
|
15
|
+
|
16
|
+
def get_vscode_server_home(commit: str) -> os.PathLike[str]:
|
17
|
+
return VSCODE_SERVER_DATA / f"cli/servers/Stable-{commit}/server"
|
18
|
+
|
19
|
+
|
20
|
+
def get_vscode_extensions_config() -> os.PathLike[str]:
|
21
|
+
p = VSCODE_DATA / "extensions/extensions.json"
|
22
|
+
if p.exists():
|
23
|
+
return p
|
24
|
+
s = VSCODE_SERVER_DATA / "extensions/extensions.json"
|
25
|
+
if s.exists():
|
26
|
+
return s
|
27
|
+
return p # default to this path
|
28
|
+
|
29
|
+
|
30
|
+
def get_vscode_commit_from_installer(installer: os.PathLike[str]) -> str | None:
|
31
|
+
directories = list(Path(installer).glob("cli-*"))
|
32
|
+
if len(directories) == 1:
|
33
|
+
return directories[0].name[len("cli-") :]
|
34
|
+
return None
|
35
|
+
|
36
|
+
|
37
|
+
def get_vscode_commit_from_code_version() -> str | None:
|
38
|
+
res = subprocess.run(["code", "--version"], stdout=subprocess.PIPE)
|
39
|
+
if res.returncode != 0:
|
40
|
+
return None
|
41
|
+
lines = res.stdout.splitlines()
|
42
|
+
if len(lines) < 2:
|
43
|
+
return None # Unexpected output
|
44
|
+
|
45
|
+
# The commit hash is usually on the second line
|
46
|
+
commit = lines[1].strip().decode("utf-8")
|
47
|
+
logger.info(f"Getting commit from `code --version`: {commit}")
|
48
|
+
|
49
|
+
return lines[1].strip().decode("utf-8")
|
50
|
+
|
51
|
+
|
52
|
+
def get_target_platform_from_installer(cli_installer: str) -> str | None:
|
53
|
+
directories = list(Path(cli_installer).glob("vscode-server-*.tar.gz"))
|
54
|
+
if len(directories) == 1:
|
55
|
+
return directories[0].name[len("vscode-server-") : -len(".tar.gz")]
|
56
|
+
return None
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: vscode-offline
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.1
|
4
4
|
Summary: Download and install vscode server for offline environments
|
5
5
|
Author: Chuck Fan
|
6
6
|
Author-email: Chuck Fan <fanck0605@qq.com>
|
@@ -17,17 +17,23 @@ vscode-offline 主要用于在无网环境下安装 VSCode Server,方便使用
|
|
17
17
|
pip install -U vscode-offline
|
18
18
|
```
|
19
19
|
|
20
|
+
## 优势
|
21
|
+
|
22
|
+
1. 自动识别并下载所有 `.vsix` 文件(包括间接依赖)
|
23
|
+
2. 一键安装 VSCode server 以及所有插件
|
24
|
+
|
20
25
|
## 用法
|
21
26
|
|
22
27
|
(1)在联网环境安装好 VSCode 和你需要的插件。
|
23
28
|
|
24
|
-
(2
|
29
|
+
(2)联网环境执行如下命令,将会自动下载 VSCode server,和目前安装的所有的插件
|
25
30
|
|
26
|
-
> `--commit`
|
31
|
+
> `--commit` 可以指定对应 VSCode 的 Commit,默认自动获取当前环境 VSCode 的 Commit。
|
32
|
+
>
|
33
|
+
> 手动查看方式:*帮助* -> *关于* -> *Commit*,
|
27
34
|
|
28
35
|
```shell
|
29
36
|
vscode-offline download \
|
30
|
-
--commit 385651c938df8a906869babee516bffd0ddb9829 \
|
31
37
|
--target-platform linux-x64 \
|
32
38
|
--installer ./vscode-offline-installer
|
33
39
|
```
|
@@ -35,10 +41,7 @@ vscode-offline download \
|
|
35
41
|
(3)复制 `vscode-offline-installer` 到内网服务器
|
36
42
|
|
37
43
|
```shell
|
38
|
-
vscode-offline install
|
39
|
-
--commit 385651c938df8a906869babee516bffd0ddb9829 \
|
40
|
-
--target-platform linux-x64 \
|
41
|
-
--installer ./vscode-offline-installer
|
44
|
+
vscode-offline install --installer ./vscode-offline-installer
|
42
45
|
```
|
43
46
|
|
44
47
|
## 贡献
|
@@ -0,0 +1,10 @@
|
|
1
|
+
vscode_offline/__init__.py,sha256=dr6Jtj0XT9eQEC4fzNigEYsAIEfCsaom3HDbUsS-2O4,57
|
2
|
+
vscode_offline/app.py,sha256=OXvwedUn8RepP37Ps-jXCBrBVqsl8Fd5hJni355fRnM,4623
|
3
|
+
vscode_offline/download.py,sha256=EpKgNLF6jU26vH-tI9UJx_acTUPIXpDnofGpY6RWmGI,3478
|
4
|
+
vscode_offline/install.py,sha256=_LwsxCqSu8_9uaSY1zuJc9nxTYbXo6f9FKzMAL9DeJo,2662
|
5
|
+
vscode_offline/loggers.py,sha256=vX91NMtNo1xfxq5y4BCtm_uhCTKtCODqBJHNvcT7JdQ,104
|
6
|
+
vscode_offline/utils.py,sha256=Unmb8V-q_s4tyxfzmh7wayyM4OM83K-HqlQKqe49LpI,1749
|
7
|
+
vscode_offline-0.1.1.dist-info/WHEEL,sha256=-neZj6nU9KAMg2CnCY6T3w8J53nx1kFGw_9HfoSzM60,79
|
8
|
+
vscode_offline-0.1.1.dist-info/entry_points.txt,sha256=zIMeh_ENKKzlt9lDao8icofSI0TeCQxH8eCwxIRI2G8,56
|
9
|
+
vscode_offline-0.1.1.dist-info/METADATA,sha256=xzRd7KZw0gVgZPu5ZN8SEv3lDS7r18ql3V-L6IDHJYY,1283
|
10
|
+
vscode_offline-0.1.1.dist-info/RECORD,,
|
vscode_offline/paths.py
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
from __future__ import annotations
|
2
|
-
|
3
|
-
import os
|
4
|
-
from pathlib import Path
|
5
|
-
|
6
|
-
VSCODE_DATA = Path("~/.vscode").expanduser()
|
7
|
-
VSCODE_SERVER_DATA = Path("~/.vscode-server").expanduser()
|
8
|
-
|
9
|
-
|
10
|
-
def get_vscode_cli_bin(commit: str) -> os.PathLike[str]:
|
11
|
-
return VSCODE_SERVER_DATA / f"code-{commit}"
|
12
|
-
|
13
|
-
|
14
|
-
def get_vscode_server_home(commit: str) -> os.PathLike[str]:
|
15
|
-
return VSCODE_SERVER_DATA / f"cli/servers/Stable-{commit}/server"
|
16
|
-
|
17
|
-
|
18
|
-
def get_vscode_extensions_config() -> os.PathLike[str]:
|
19
|
-
p = VSCODE_DATA / "extensions/extensions.json"
|
20
|
-
if p.exists():
|
21
|
-
return p
|
22
|
-
s = VSCODE_SERVER_DATA / "extensions/extensions.json"
|
23
|
-
if s.exists():
|
24
|
-
return s
|
25
|
-
return p # default to this path
|
@@ -1,10 +0,0 @@
|
|
1
|
-
vscode_offline/__init__.py,sha256=dr6Jtj0XT9eQEC4fzNigEYsAIEfCsaom3HDbUsS-2O4,57
|
2
|
-
vscode_offline/app.py,sha256=pdr7F7vjDVIupkaZSoqL1ZAWNZPAGyPx52lLtcTUYpo,3052
|
3
|
-
vscode_offline/download.py,sha256=thEFFn4XuoHqH0f6cuUcOWWeUQwNhPjKO5d681xIyL4,3478
|
4
|
-
vscode_offline/install.py,sha256=D4klu6aKeqp6bSQkWLzFmaTNalvekw5L93Y4FQs-jFA,2554
|
5
|
-
vscode_offline/loggers.py,sha256=vX91NMtNo1xfxq5y4BCtm_uhCTKtCODqBJHNvcT7JdQ,104
|
6
|
-
vscode_offline/paths.py,sha256=WnOzG6a7PXFurgkVUirHtIyRDnF80PzjKHtdMXSlcbU,693
|
7
|
-
vscode_offline-0.1.0.dist-info/WHEEL,sha256=-neZj6nU9KAMg2CnCY6T3w8J53nx1kFGw_9HfoSzM60,79
|
8
|
-
vscode_offline-0.1.0.dist-info/entry_points.txt,sha256=zIMeh_ENKKzlt9lDao8icofSI0TeCQxH8eCwxIRI2G8,56
|
9
|
-
vscode_offline-0.1.0.dist-info/METADATA,sha256=Zi7Fel9ALNPmqHosPrBhRa0X8y8BAaS-9YkVbhONa08,1198
|
10
|
-
vscode_offline-0.1.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|