instructions.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. # Copyright (C) 2012 Anaconda, Inc
  2. # SPDX-License-Identifier: BSD-3-Clause
  3. from logging import getLogger
  4. from os.path import isfile, join
  5. from .core.link import UnlinkLinkTransaction
  6. from .core.package_cache_data import ProgressiveFetchExtract
  7. from .deprecations import deprecated
  8. from .exceptions import CondaFileIOError
  9. from .gateways.disk.link import islink
  10. log = getLogger(__name__)
  11. # op codes
  12. CHECK_FETCH = "CHECK_FETCH"
  13. FETCH = "FETCH"
  14. CHECK_EXTRACT = "CHECK_EXTRACT"
  15. EXTRACT = "EXTRACT"
  16. RM_EXTRACTED = "RM_EXTRACTED"
  17. RM_FETCHED = "RM_FETCHED"
  18. PREFIX = "PREFIX"
  19. PRINT = "PRINT"
  20. PROGRESS = "PROGRESS"
  21. SYMLINK_CONDA = "SYMLINK_CONDA"
  22. UNLINK = "UNLINK"
  23. LINK = "LINK"
  24. UNLINKLINKTRANSACTION = "UNLINKLINKTRANSACTION"
  25. PROGRESSIVEFETCHEXTRACT = "PROGRESSIVEFETCHEXTRACT"
  26. PROGRESS_COMMANDS = {EXTRACT, RM_EXTRACTED}
  27. ACTION_CODES = (
  28. CHECK_FETCH,
  29. FETCH,
  30. CHECK_EXTRACT,
  31. EXTRACT,
  32. UNLINK,
  33. LINK,
  34. SYMLINK_CONDA,
  35. RM_EXTRACTED,
  36. RM_FETCHED,
  37. )
  38. @deprecated("23.9", "24.3", addendum="Unused.")
  39. def PREFIX_CMD(state, prefix):
  40. state["prefix"] = prefix
  41. def PRINT_CMD(state, arg): # pragma: no cover
  42. if arg.startswith(("Unlinking packages", "Linking packages")):
  43. return
  44. getLogger("conda.stdout.verbose").info(arg)
  45. def FETCH_CMD(state, package_cache_entry):
  46. raise NotImplementedError()
  47. def EXTRACT_CMD(state, arg):
  48. raise NotImplementedError()
  49. def PROGRESSIVEFETCHEXTRACT_CMD(state, progressive_fetch_extract): # pragma: no cover
  50. assert isinstance(progressive_fetch_extract, ProgressiveFetchExtract)
  51. progressive_fetch_extract.execute()
  52. def UNLINKLINKTRANSACTION_CMD(state, arg): # pragma: no cover
  53. unlink_link_transaction = arg
  54. assert isinstance(unlink_link_transaction, UnlinkLinkTransaction)
  55. unlink_link_transaction.execute()
  56. def check_files_in_package(source_dir, files):
  57. for f in files:
  58. source_file = join(source_dir, f)
  59. if isfile(source_file) or islink(source_file):
  60. return True
  61. else:
  62. raise CondaFileIOError(source_file, "File %s does not exist in tarball" % f)
  63. # Map instruction to command (a python function)
  64. commands = {
  65. PREFIX: PREFIX_CMD,
  66. PRINT: PRINT_CMD,
  67. FETCH: FETCH_CMD,
  68. PROGRESS: lambda x, y: None,
  69. EXTRACT: EXTRACT_CMD,
  70. RM_EXTRACTED: lambda x, y: None,
  71. RM_FETCHED: lambda x, y: None,
  72. UNLINK: None,
  73. LINK: None,
  74. SYMLINK_CONDA: lambda x, y: None,
  75. UNLINKLINKTRANSACTION: UNLINKLINKTRANSACTION_CMD,
  76. PROGRESSIVEFETCHEXTRACT: PROGRESSIVEFETCHEXTRACT_CMD,
  77. }
  78. OP_ORDER = (
  79. RM_FETCHED,
  80. FETCH,
  81. RM_EXTRACTED,
  82. EXTRACT,
  83. UNLINK,
  84. LINK,
  85. )