44import time
55from .base_command import BaseCommand
66from azpype .logging_config import CopyLogger
7- from azpype .validators import validate_azcopy_envs , validate_login_type , validate_azure_blob_url , validate_local_path , validate_network_available
7+ from azpype .validators import validate_azcopy_envs , validate_login_type , is_valid_path_or_url , validate_local_path , validate_network_available
88
99class Copy (BaseCommand ):
1010 def __init__ (self , source : str , destination : str , sas_token :str = None , ** options ):
@@ -81,12 +81,10 @@ def __init__(self, source: str, destination: str, sas_token:str = None, **option
8181
8282 def prevalidation (self ):
8383 validation_results = {
84- "is_valid_local_path " : validate_local_path (self .source , self .logger ),
85- "is_valid_blob_url_format " : validate_azure_blob_url (self .destination , self .logger )
84+ "source " : is_valid_path_or_url (self .source , self .logger ),
85+ "destination " : is_valid_path_or_url (self .destination , self .logger )
8686 }
87-
8887 failed_checks = [check for check , result in validation_results .items () if not result ]
89-
9088 return not failed_checks , failed_checks
9189
9290
@@ -102,51 +100,50 @@ def execute(self):
102100 args = [self .source , self .destination ]
103101 return super ().execute (args , self .options )
104102
105-
106-
107- class MonitoredCopy (Copy ):
108- def __init__ (self , source : str , destination : str , ** options ):
109- super ().__init__ (source , destination , ** options )
110- self .source = source
111- self .destination = destination
112- self .observer = Observer ()
113-
114- def _is_network_filesystem (self ):
115- if platform .system () == 'Windows' and self .source .startswith ('\\ \\ ' ):
116- return True
117-
118- elif platform .system () in ('Linux' , 'Darwin' ):
119- try :
120- df_output = subprocess .check_output (['df' , self .source ]).decode ().split ("\n " )
121- fs_type = df_output [1 ].split ()[- 1 ]
122- return fs_type in ('nfs' , 'smbfs' , 'cifs' )
123- except :
124- pass
125- return False
126-
127- def _set_observer (self ):
128- if _is_network_filesystem :
129- self .observer = PollingObserver ()
130- else :
131- self .observer = Observer ()
132-
133- class CopyHandler (FileSystemEventHandler ):
134- def __init__ (self , monitored_copy ):
135- self .monitored_copy = monitored_copy
136-
137- def on_any_event (self , event ):
138- if not event .is_directory :
139- self .monitored_copy .execute ()
103+ # TODO: Add support for filewatching agent
104+ # class MonitoredCopy(Copy):
105+ # def __init__(self, source: str, destination: str, **options):
106+ # super().__init__(source, destination, **options)
107+ # self.source = source
108+ # self.destination = destination
109+ # self.observer = Observer()
110+
111+ # def _is_network_filesystem(self):
112+ # if platform.system() == 'Windows' and self.source.startswith('\\\\'):
113+ # return True
114+
115+ # elif platform.system() in ('Linux', 'Darwin'):
116+ # try:
117+ # df_output = subprocess.check_output(['df', self.source]).decode().split("\n")
118+ # fs_type = df_output[1].split()[-1]
119+ # return fs_type in ('nfs', 'smbfs', 'cifs')
120+ # except:
121+ # pass
122+ # return False
123+
124+ # def _set_observer(self):
125+ # if _is_network_filesystem:
126+ # self.observer = PollingObserver()
127+ # else:
128+ # self.observer = Observer()
129+
130+ # class CopyHandler(FileSystemEventHandler):
131+ # def __init__(self, monitored_copy):
132+ # self.monitored_copy = monitored_copy
133+
134+ # def on_any_event(self, event):
135+ # if not event.is_directory:
136+ # self.monitored_copy.execute()
140137
141- def execute_with_monitoring (self ):
142- event_handler = self .CopyHandler (self )
143- self .observer .schedule (event_handler , path = self .source , recursive = False )
144- self .observer .start ()
145-
146- try :
147- while True :
148- time .sleep (1 )
149- except KeyboardInterrupt :
150- self .observer .stop ()
151-
152- self .observer .join ()
138+ # def execute_with_monitoring(self):
139+ # event_handler = self.CopyHandler(self)
140+ # self.observer.schedule(event_handler, path=self.source, recursive=False)
141+ # self.observer.start()
142+
143+ # try:
144+ # while True:
145+ # time.sleep(1)
146+ # except KeyboardInterrupt:
147+ # self.observer.stop()
148+
149+ # self.observer.join()
0 commit comments