Permalink
Browse files

Do our own URL parsing for LT propagation.

Python urlparse comes up short again, especially on Py 2.4
  • Loading branch information...
1 parent 8917a3c commit 614966a357225c05b93ee00f8989e36fc60e66d7 @labisso labisso committed Nov 15, 2010
Showing with 36 additions and 13 deletions.
  1. +36 −13 control/src/python/workspacecontrol/defaults/imageprocurement/propagate_lantorrent.py
View
49 control/src/python/workspacecontrol/defaults/imageprocurement/propagate_lantorrent.py 100755 → 100644
@@ -1,12 +1,8 @@
from commands import getstatusoutput
import os
-import string
-from propagate_adapter import PropagationAdapter
from workspacecontrol.api.exceptions import *
import propagate_scp
-import urlparse
import workspacecontrol.main.wc_args as wc_args
-import socket
class LantorrentPropadapter(propagate_scp.propadapter):
@@ -101,17 +97,10 @@ def _lt_command(self, local, remote):
if lt_exe == None:
raise InvalidInput("the prop-extra-args parameter must be used and be a path to the remote execution script")
-
- parts = url.split('://', 1)
- fake_url = "http://" + parts[1]
- up = urlparse.urlparse(fake_url)
-
- xfer_host = up.hostname
- xfer_user = up.username
- xfer_port = int(up.port)
+ (xfer_scheme, xfer_user, xfer_pw, xfer_host, xfer_port, xfer_path) =_url_parse(url)
+
if xfer_port == None:
xfer_port = 22
- xfer_path = up.path
if xfer_user:
self.c.log.info("allowing client to specify this account: %s" % xfer_user)
@@ -140,3 +129,37 @@ def _lt_command(self, local, remote):
self.c.log.debug("lantorrent command %s " % (cmd))
return cmd
+
+def _url_parse(url):
+ parts = url.split('://', 1)
+ scheme = parts[0]
+ rest = parts[1]
+
+ parts = rest.split('@', 1)
+ if len(parts) == 1:
+ user = None
+ password = None
+ else:
+ rest = parts[1]
+ u_parts = parts[0].split(':')
+ user = parts[0]
+ if len(u_parts) == 1:
+ password = None
+ else:
+ password = parts[1]
+
+ parts = rest.split('/', 1)
+ contact_string = parts[0]
+ if len(parts) > 1:
+ path = '/' + parts[1]
+ else:
+ path = None
+
+ parts = contact_string.split(':')
+ hostname = parts[0]
+ if len(parts) == 1:
+ port = None
+ else:
+ port = int(parts[1])
+
+ return (scheme, user, password, hostname, port, path)

0 comments on commit 614966a

Please sign in to comment.