1717# under the License.
1818from __future__ import annotations
1919
20+ import posixpath
2021from functools import wraps
21- from pathlib import PurePosixPath , PureWindowsPath
2222from shutil import copyfileobj
23- from typing import TYPE_CHECKING , Any , Literal
23+ from typing import TYPE_CHECKING , Any
2424
2525import smbclient
2626
@@ -41,21 +41,14 @@ class SambaHook(BaseHook):
4141 :param share:
4242 An optional share name. If this is unset then the "schema" field of
4343 the connection is used in its place.
44- :param share_type:
45- An optional share type name. If this is unset then it will assume a posix share type.
4644 """
4745
4846 conn_name_attr = "samba_conn_id"
4947 default_conn_name = "samba_default"
5048 conn_type = "samba"
5149 hook_name = "Samba"
5250
53- def __init__ (
54- self ,
55- samba_conn_id : str = default_conn_name ,
56- share : str | None = None ,
57- share_type : Literal ["posix" , "windows" ] | None = None ,
58- ) -> None :
51+ def __init__ (self , samba_conn_id : str = default_conn_name , share : str | None = None ) -> None :
5952 super ().__init__ ()
6053 conn = self .get_connection (samba_conn_id )
6154
@@ -65,13 +58,6 @@ def __init__(
6558 if not conn .password :
6659 self .log .info ("Password not provided" )
6760
68- self ._share_type = share_type or conn .extra_dejson .get ("share_type" , "posix" )
69- if self ._share_type not in {"posix" , "windows" }:
70- self ._share_type = "posix"
71- self .log .warning (
72- "Invalid share_type specified. It must be either 'posix' or 'windows'. Falling back to 'posix'"
73- )
74-
7561 connection_cache : dict [str , smbprotocol .connection .Connection ] = {}
7662
7763 self ._host = conn .host
@@ -98,18 +84,8 @@ def __exit__(self, exc_type, exc_value, traceback):
9884 connection .disconnect ()
9985 self ._connection_cache .clear ()
10086
101- @staticmethod
102- def _join_posix_path (host : str , share : str , path : str ) -> str :
103- return str (PurePosixPath ("//" + host , share , path .lstrip ("/" )))
104-
105- @staticmethod
106- def _join_windows_path (host : str , share : str , path : str ) -> str :
107- return "\\ {}" .format (PureWindowsPath (rf"\\ { host } \\ { share } " , path .lstrip (r"\/" )))
108-
10987 def _join_path (self , path ):
110- if self ._share_type == "windows" :
111- return self ._join_windows_path (self ._host , self ._share , path )
112- return self ._join_posix_path (self ._host , self ._share , path )
88+ return f"//{ posixpath .join (self ._host , self ._share , path .lstrip ('/' ))} "
11389
11490 @wraps (smbclient .link )
11591 def link (self , src , dst , follow_symlinks = True ):
@@ -317,20 +293,6 @@ def push_from_local(self, destination_filepath: str, local_filepath: str, buffer
317293 def get_ui_field_behaviour (cls ) -> dict [str , Any ]:
318294 """Return custom field behaviour."""
319295 return {
320- "hidden_fields" : [],
296+ "hidden_fields" : ["extra" ],
321297 "relabeling" : {"schema" : "Share" },
322298 }
323-
324- @classmethod
325- def get_connection_form_widgets (cls ) -> dict [str , Any ]:
326- """Return connection widgets to add to connection form."""
327- from flask_babel import lazy_gettext
328- from wtforms import StringField
329-
330- return {
331- "share_type" : StringField (
332- label = lazy_gettext ("Share Type" ),
333- description = "The share OS type (`posix` or `windows`). Used to determine the formatting of file and folder paths." ,
334- default = "posix" ,
335- )
336- }
0 commit comments