kash-shell 0.3.13__py3-none-any.whl → 0.3.15__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.
@@ -1,56 +0,0 @@
1
- from pathlib import Path
2
-
3
- from kash.config.logger import get_logger
4
- from kash.file_storage.file_store import FileStore
5
- from kash.model.items_model import Item, ItemType
6
- from kash.model.paths_model import StorePath
7
- from kash.utils.common.url import Locator, Url, is_url
8
- from kash.utils.errors import InvalidInput
9
- from kash.utils.file_utils.file_formats_model import Format
10
- from kash.web_content.canon_url import canonicalize_url
11
-
12
- # TODO: Clean this up, move into FileStore.
13
-
14
- log = get_logger(__name__)
15
-
16
-
17
- def import_url(ws: FileStore, url: Url) -> Item:
18
- """
19
- Import a URL as a resource. Does not fetch metadata.
20
- """
21
- canon_url = canonicalize_url(url)
22
- log.message(
23
- "Importing URL: %s%s", canon_url, f" canonicalized from {url}" if url != canon_url else ""
24
- )
25
- item = Item(ItemType.resource, url=canon_url, format=Format.url)
26
- # No need to overwrite any resource we already have for the identical URL.
27
- store_path = ws.save(item, skip_dup_names=True)
28
- # Load to fill in any metadata we may already have.
29
- item = ws.load(store_path)
30
- return item
31
-
32
-
33
- def import_and_load(ws: FileStore, locator: Locator | str) -> Item:
34
- """
35
- Ensure that a URL or file path is imported into the workspace and
36
- return the Item.
37
- """
38
-
39
- if isinstance(locator, str) and is_url(locator):
40
- log.message("Importing locator as URL: %r", locator)
41
- item = import_url(ws, Url(locator))
42
- else:
43
- if isinstance(locator, StorePath):
44
- log.info("Locator is in the file store: %r", locator)
45
- # It's already a StorePath.
46
- item = ws.load(locator)
47
- else:
48
- log.info("Importing locator as local path: %r", locator)
49
- path = Path(locator)
50
- if not path.exists():
51
- raise InvalidInput(f"File not found: {path}")
52
-
53
- store_path = ws.import_item(path)
54
- item = ws.load(store_path)
55
-
56
- return item