mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Refactor stream_to_file out of galaxy.datatypes.sniff.
Doesn't do anything datatype specific, can be pushed into a lower package. galaxy.files.uris is better I think.
This commit is contained in:
@@ -26,6 +26,7 @@ from typing_extensions import Protocol
|
||||
|
||||
from galaxy import util
|
||||
from galaxy.files import ConfiguredFileSources
|
||||
from galaxy.files.uris import stream_to_file
|
||||
from galaxy.util import (
|
||||
compression_utils,
|
||||
file_reader,
|
||||
@@ -81,12 +82,6 @@ def stream_url_to_file(path: str, file_sources: Optional[ConfiguredFileSources]
|
||||
return temp_name
|
||||
|
||||
|
||||
def stream_to_file(stream, suffix="", prefix="", dir=None, text=False, **kwd):
|
||||
"""Writes a stream to a temporary file, returns the temporary file's name"""
|
||||
fd, temp_name = tempfile.mkstemp(suffix=suffix, prefix=prefix, dir=dir, text=text)
|
||||
return stream_to_open_named_file(stream, fd, temp_name, **kwd)
|
||||
|
||||
|
||||
def handle_composite_file(datatype, src_path, extra_files, name, is_binary, tmp_dir, tmp_prefix, upload_opts):
|
||||
if not is_binary:
|
||||
if upload_opts.get("space_to_tab"):
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import ipaddress
|
||||
import logging
|
||||
import socket
|
||||
import tempfile
|
||||
from typing import (
|
||||
List,
|
||||
Union,
|
||||
@@ -11,10 +12,21 @@ from galaxy.exceptions import (
|
||||
AdminRequiredException,
|
||||
ConfigDoesNotAllowException,
|
||||
)
|
||||
from galaxy.util import unicodify
|
||||
from galaxy.util import (
|
||||
stream_to_open_named_file,
|
||||
unicodify,
|
||||
)
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def stream_to_file(stream, suffix="", prefix="", dir=None, text=False, **kwd):
|
||||
"""Writes a stream to a temporary file, returns the temporary file's name"""
|
||||
fd, temp_name = tempfile.mkstemp(suffix=suffix, prefix=prefix, dir=dir, text=text)
|
||||
return stream_to_open_named_file(stream, fd, temp_name, **kwd)
|
||||
|
||||
|
||||
IpAddressT = Union[ipaddress.IPv4Address, ipaddress.IPv6Address]
|
||||
IpNetwrokT = Union[ipaddress.IPv4Network, ipaddress.IPv6Network]
|
||||
IpAllowedListEntryT = Union[IpAddressT, IpNetwrokT]
|
||||
|
||||
@@ -17,9 +17,8 @@ from sqlalchemy.orm import joinedload
|
||||
from webob.compat import cgi_FieldStorage
|
||||
|
||||
from galaxy import util
|
||||
from galaxy.datatypes.sniff import stream_to_file
|
||||
from galaxy.exceptions import RequestParameterInvalidException
|
||||
from galaxy.files.uris import validate_non_local
|
||||
from galaxy.files.uris import stream_to_file, validate_non_local
|
||||
from galaxy.model import (
|
||||
FormDefinition,
|
||||
LibraryDataset,
|
||||
|
||||
@@ -21,6 +21,7 @@ from galaxy.datatypes.upload_util import (
|
||||
handle_upload,
|
||||
UploadProblemException,
|
||||
)
|
||||
from galaxy.files.uris import stream_to_file
|
||||
from galaxy.util import (
|
||||
in_directory,
|
||||
safe_makedirs,
|
||||
@@ -154,7 +155,7 @@ def _fetch_target(upload_config, target):
|
||||
dataset_bunch = Bunch(
|
||||
name=name,
|
||||
)
|
||||
primary_file = sniff.stream_to_file(
|
||||
primary_file = stream_to_file(
|
||||
StringIO(datatype.generate_primary_file(dataset_bunch)), prefix="upload_auto_primary_file", dir="."
|
||||
)
|
||||
extra_files_path = f"{primary_file}_extra"
|
||||
@@ -436,7 +437,7 @@ def _has_src_to_path(upload_config, item, is_dataset=False) -> Tuple[str, str]:
|
||||
if name is None:
|
||||
name = url.split("/")[-1]
|
||||
elif src == "pasted":
|
||||
path = sniff.stream_to_file(StringIO(item["paste_content"]))
|
||||
path = stream_to_file(StringIO(item["paste_content"]))
|
||||
if name is None:
|
||||
name = "Pasted Entry"
|
||||
else:
|
||||
|
||||
@@ -15,14 +15,12 @@ from typing import (
|
||||
TYPE_CHECKING,
|
||||
)
|
||||
|
||||
from galaxy.datatypes import (
|
||||
data,
|
||||
sniff,
|
||||
)
|
||||
from galaxy.datatypes import data
|
||||
from galaxy.exceptions import (
|
||||
AdminRequiredException,
|
||||
ConfigDoesNotAllowException,
|
||||
)
|
||||
from galaxy.files.uris import stream_to_file
|
||||
from galaxy.util import (
|
||||
asbool,
|
||||
inflector,
|
||||
@@ -656,7 +654,7 @@ class UploadDataset(Group):
|
||||
dataset.name = self.get_composite_dataset_name(context)
|
||||
if dataset.datatype.composite_type == "auto_primary_file":
|
||||
# replace sniff here with just creating an empty file
|
||||
temp_name = sniff.stream_to_file(
|
||||
temp_name = stream_to_file(
|
||||
io.StringIO(d_type.generate_primary_file(dataset)), prefix="upload_auto_primary_file"
|
||||
)
|
||||
dataset.primary_file = temp_name
|
||||
|
||||
Reference in New Issue
Block a user