-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathinstructions.py
104 lines (82 loc) · 2.56 KB
/
instructions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# Copyright (C) 2012 Anaconda, Inc
# SPDX-License-Identifier: BSD-3-Clause
"""Define the instruction set (constants) for conda operations."""
from logging import getLogger
from os.path import isfile, join
from .core.link import UnlinkLinkTransaction
from .core.package_cache_data import ProgressiveFetchExtract
from .deprecations import deprecated
from .exceptions import CondaFileIOError
from .gateways.disk.link import islink
log = getLogger(__name__)
# op codes
CHECK_FETCH = "CHECK_FETCH"
FETCH = "FETCH"
CHECK_EXTRACT = "CHECK_EXTRACT"
EXTRACT = "EXTRACT"
RM_EXTRACTED = "RM_EXTRACTED"
RM_FETCHED = "RM_FETCHED"
deprecated.constant("24.9", "25.3", "PREFIX", "PREFIX")
PRINT = "PRINT"
PROGRESS = "PROGRESS"
SYMLINK_CONDA = "SYMLINK_CONDA"
UNLINK = "UNLINK"
LINK = "LINK"
UNLINKLINKTRANSACTION = "UNLINKLINKTRANSACTION"
PROGRESSIVEFETCHEXTRACT = "PROGRESSIVEFETCHEXTRACT"
PROGRESS_COMMANDS = {EXTRACT, RM_EXTRACTED}
ACTION_CODES = (
CHECK_FETCH,
FETCH,
CHECK_EXTRACT,
EXTRACT,
UNLINK,
LINK,
SYMLINK_CONDA,
RM_EXTRACTED,
RM_FETCHED,
)
def PRINT_CMD(state, arg): # pragma: no cover
if arg.startswith(("Unlinking packages", "Linking packages")):
return
getLogger("conda.stdout.verbose").info(arg)
def FETCH_CMD(state, package_cache_entry):
raise NotImplementedError()
def EXTRACT_CMD(state, arg):
raise NotImplementedError()
def PROGRESSIVEFETCHEXTRACT_CMD(state, progressive_fetch_extract): # pragma: no cover
assert isinstance(progressive_fetch_extract, ProgressiveFetchExtract)
progressive_fetch_extract.execute()
def UNLINKLINKTRANSACTION_CMD(state, arg): # pragma: no cover
unlink_link_transaction = arg
assert isinstance(unlink_link_transaction, UnlinkLinkTransaction)
unlink_link_transaction.execute()
def check_files_in_package(source_dir, files):
for f in files:
source_file = join(source_dir, f)
if isfile(source_file) or islink(source_file):
return True
else:
raise CondaFileIOError(source_file, f"File {f} does not exist in tarball")
# Map instruction to command (a python function)
commands = {
PRINT: PRINT_CMD,
FETCH: FETCH_CMD,
PROGRESS: lambda x, y: None,
EXTRACT: EXTRACT_CMD,
RM_EXTRACTED: lambda x, y: None,
RM_FETCHED: lambda x, y: None,
UNLINK: None,
LINK: None,
SYMLINK_CONDA: lambda x, y: None,
UNLINKLINKTRANSACTION: UNLINKLINKTRANSACTION_CMD,
PROGRESSIVEFETCHEXTRACT: PROGRESSIVEFETCHEXTRACT_CMD,
}
OP_ORDER = (
RM_FETCHED,
FETCH,
RM_EXTRACTED,
EXTRACT,
UNLINK,
LINK,
)