Skip to content

Commit 1345f0e

Browse files
author
Ysf
committed
Source/Target does not have to be local2blob
1 parent 4a7dcf0 commit 1345f0e

File tree

2 files changed

+55
-55
lines changed

2 files changed

+55
-55
lines changed

azpype/commands/copy.py

Lines changed: 49 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import time
55
from .base_command import BaseCommand
66
from 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

99
class 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()

azpype/validators.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from logging import Logger
77

88
# Source Desination formatting validators
9-
109
def validate_azure_blob_url(url: str, logger: Logger) -> bool:
1110
parsed_url = urlparse(url)
1211
if not parsed_url.scheme or not parsed_url.netloc:
@@ -18,17 +17,21 @@ def validate_azure_blob_url(url: str, logger: Logger) -> bool:
1817
if 'blob.core.windows.net' not in parsed_url.netloc:
1918
logger.info(f"Invalid URL: {url}\nURL must be a valid Azure Blob Storage URL.")
2019
return False
20+
logger.info(f"Provided URL appears to be valid: {url}")
2121
return True
2222

2323
def validate_local_path(path: str, logger: Logger) -> bool:
2424
if not Path(path).exists():
25-
logger.info(f"File or Directory at path does not exist: {path}")
25+
logger.info(f"File or Directory does not exist locally at path: {path}")
2626
return False
27+
logger.info(f"Found File or Directory locally at path: {path}")
2728
return True
2829

30+
def is_valid_path_or_url(path:str, logger: Logger) -> bool:
31+
return validate_local_path(path, logger) or validate_azure_blob_url(path, logger)
2932

30-
# Auth validators
3133

34+
# Auth validators
3235
def validate_azcopy_envs(vars:list, logger: Logger):
3336
"""
3437
Checks for the existence of an environment variable.

0 commit comments

Comments
 (0)