diff --git a/src/python/dm/common/utility/ftpUtility.py b/src/python/dm/common/utility/ftpUtility.py index 6987a6c0afb6808f1dc5246cbd510b6932c5001d..3f29c0300704459d748e3c2292eda81058c3d5b1 100755 --- a/src/python/dm/common/utility/ftpUtility.py +++ b/src/python/dm/common/utility/ftpUtility.py @@ -35,6 +35,38 @@ class FtpUtility: dirPath = parseResult.path return (scheme, host, port, dirPath) + @classmethod + def parseUrl(cls, url, defaultHost=None, defaultPort=None): + host = defaultHost + port = defaultPort + parseResult = urlparse.urlparse(url) + scheme = parseResult.scheme + netlocTokens = parseResult.netloc + if netlocTokens: + netlocTokens = netlocTokens.split(':') + host = netlocTokens[0] + if len(netlocTokens) > 1: + port = int(netlocTokens[1]) + dirPath = parseResult.path + dirPath = os.path.normpath(dirPath) + return (scheme, host, port, dirPath) + + @classmethod + def assembleUrl(cls, scheme, host, port, dirPath): + url = '' + if scheme: + url += '%s://' % scheme + if host: + url += '%s' % (host) + if port: + url += ':%s' % (port) + if dirPath: + if len(url) and not dirPath.startswith('/'): + url += '/%s' % (os.path.normpath(dirPath)) + else: + url += '%s' % (os.path.normpath(dirPath)) + return url + @classmethod def getFtpClient(cls, host, port, username=None, password=None): ftp = FTP()