def access(self, path): if not self._url_concat(self.baseAddress, path).startswith('ftp://'): return Accessor.access(self, path) url = self._url_concat(self.baseAddress, path) # if FTP, override by actually checking the file exists because urllib2 seems # to be not so good at this. try: (scheme, netloc, path, params, query) = urlparse.urlsplit(url) (hostname, username, password) = util.splitNetloc(netloc) fname = os.path.basename(path) directory = self._url_decode(os.path.dirname(path[1:])) # now open a connection to the server and verify that fname is in ftp = ftplib.FTP(hostname) ftp.login(username, password) ftp.cwd(directory) if ftp.size(fname) is not None: return True lst = ftp.nlst() return fname in lst except: # couldn't parse the server name out: return False
def get_ftp_dest(answers): text = "Please enter the URL for your FTP directory and, optionally, a username and password" url_field = snack.Entry(50) user_field = snack.Entry(16) passwd_field = snack.Entry(16, password=1) url_text = snack.Textbox(11, 1, "URL:") user_text = snack.Textbox(11, 1, "Username:"******"Password:"******"Specify Path", 'getftpdest', 1, 3) bb = snack.ButtonBar(tui.screen, ['Ok', 'Back']) t = snack.TextboxReflowed(50, text) entry_grid = snack.Grid(2, 3) entry_grid.setField(url_text, 0, 0) entry_grid.setField(url_field, 1, 0) entry_grid.setField(user_text, 0, 1) entry_grid.setField(user_field, 1, 1, anchorLeft=1) entry_grid.setField(passwd_text, 0, 2) entry_grid.setField(passwd_field, 1, 2, anchorLeft=1) gf.add(t, 0, 0, padding=(0, 0, 0, 1)) gf.add(entry_grid, 0, 1, padding=(0, 0, 0, 1)) gf.add(bb, 0, 2, growx=1) button = bb.buttonPressed(gf.runOnce()) if button == 'back': return uicontroller.LEFT_BACKWARDS url = url_field.value() if not url.startswith('ftp://'): url = 'ftp://' + url if user_field.value() != '': if passwd_field.value() != '': answers['dest-address'] = url.replace( '//', '//%s:%s@' % (user_field.value(), passwd_field.value()), 1) else: answers['dest-address'] = url.replace('//', '//%s@' % user_field.value(), 1) else: answers['dest-address'] = url return uicontroller.RIGHT_FORWARDS
def get_url_location(answers, require_base_repo): text = "Please enter the URL for your HTTP or FTP repository and, optionally, a username and password" url_field = Entry(50) user_field = Entry(16) passwd_field = Entry(16, password = 1) url_text = Textbox(11, 1, "URL:") user_text = Textbox(11, 1, "Username:"******"Password:"******"Specify Repository", 'geturlloc', 1, 3) bb = ButtonBar(tui.screen, [ 'Ok', 'Back' ]) t = TextboxReflowed(50, text) entry_grid = Grid(2, 3) entry_grid.setField(url_text, 0, 0) entry_grid.setField(url_field, 1, 0) entry_grid.setField(user_text, 0, 1) entry_grid.setField(user_field, 1, 1, anchorLeft = 1) entry_grid.setField(passwd_text, 0, 2) entry_grid.setField(passwd_field, 1, 2, anchorLeft = 1) gf.add(t, 0, 0, padding = (0, 0, 0, 1)) gf.add(entry_grid, 0, 1, padding = (0, 0, 0, 1)) gf.add(bb, 0, 2, growx = 1) button = bb.buttonPressed(gf.runOnce()) if button == 'back': return LEFT_BACKWARDS if user_field.value() != '': if passwd_field.value() != '': answers['source-address'] = url_field.value().replace('//', '//%s:%s@' % (user_field.value(), passwd_field.value()), 1) else: answers['source-address'] = url_field.value().replace('//', '//%s@' % user_field.value(), 1) else: answers['source-address'] = url_field.value() if len(answers['source-address']) > 0: done = interactive_check_repo_def((answers['source-media'], answers['source-address']), require_base_repo) return RIGHT_FORWARDS
def get_ftp_dest(answers): text = "Please enter the URL for your FTP directory and, optionally, a username and password" url_field = snack.Entry(50) user_field = snack.Entry(16) passwd_field = snack.Entry(16, password = 1) url_text = snack.Textbox(11, 1, "URL:") user_text = snack.Textbox(11, 1, "Username:"******"Password:"******"Specify Path", 'getftpdest', 1, 3) bb = snack.ButtonBar(tui.screen, [ 'Ok', 'Back' ]) t = snack.TextboxReflowed(50, text) entry_grid = snack.Grid(2, 3) entry_grid.setField(url_text, 0, 0) entry_grid.setField(url_field, 1, 0) entry_grid.setField(user_text, 0, 1) entry_grid.setField(user_field, 1, 1, anchorLeft = 1) entry_grid.setField(passwd_text, 0, 2) entry_grid.setField(passwd_field, 1, 2, anchorLeft = 1) gf.add(t, 0, 0, padding = (0, 0, 0, 1)) gf.add(entry_grid, 0, 1, padding = (0, 0, 0, 1)) gf.add(bb, 0, 2, growx = 1) button = bb.buttonPressed(gf.runOnce()) if button == 'back': return uicontroller.LEFT_BACKWARDS url = url_field.value() if not url.startswith('ftp://'): url = 'ftp://' + url if user_field.value() != '': if passwd_field.value() != '': answers['dest-address'] = url.replace('//', '//%s:%s@' % (user_field.value(), passwd_field.value()), 1) else: answers['dest-address'] = url.replace('//', '//%s@' % user_field.value(), 1) else: answers['dest-address'] = url return uicontroller.RIGHT_FORWARDS
def __init__(self, baseAddress): if not True in [ baseAddress.startswith(prefix) for prefix in self.url_prefixes ]: xelogging.log( "Base address: no known protocol specified, prefixing http://") baseAddress = "http://" + baseAddress if not baseAddress.endswith('/'): xelogging.log( "Base address: did not end with '/' but should be a directory so adding it." ) baseAddress += '/' if baseAddress.startswith('http://'): (scheme, netloc, path, params, query) = urlparse.urlsplit(baseAddress) if netloc.endswith(':'): baseAddress = baseAddress.replace(netloc, netloc[:-1]) netloc = netloc[:-1] pos = baseAddress[7:].index('/') + 7 path2 = baseAddress[pos:] if '#' in path2: new_path = path2.replace('#', '%23') baseAddress = baseAddress.replace(path2, new_path) (hostname, username, password) = util.splitNetloc(netloc) if username != None: xelogging.log("Using basic HTTP authentication: %s %s" % (username, password)) self.passman = urllib2.HTTPPasswordMgrWithDefaultRealm() self.passman.add_password(None, hostname, username, password) self.authhandler = urllib2.HTTPBasicAuthHandler(self.passman) self.opener = urllib2.build_opener(self.authhandler) urllib2.install_opener(self.opener) if password == None: self.baseAddress = baseAddress.replace( '%s@' % username, '', 1) else: self.baseAddress = baseAddress.replace( '%s:%s@' % (username, password), '', 1) else: self.baseAddress = baseAddress else: self.baseAddress = baseAddress self.fullAddress = baseAddress xelogging.log( "Initializing URLRepositoryAccessor with base address %s" % self.baseAddress)
def get_url_location(answers, require_base_repo): text = "Please enter the URL for your HTTP or FTP repository and, optionally, a username and password" url_field = Entry(50) user_field = Entry(16) passwd_field = Entry(16, password=1) url_text = Textbox(11, 1, "URL:") user_text = Textbox(11, 1, "Username:"******"Password:"******"Specify Repository", 'geturlloc', 1, 3) bb = ButtonBar(tui.screen, ['Ok', 'Back']) t = TextboxReflowed(50, text) entry_grid = Grid(2, 3) entry_grid.setField(url_text, 0, 0) entry_grid.setField(url_field, 1, 0) entry_grid.setField(user_text, 0, 1) entry_grid.setField(user_field, 1, 1, anchorLeft=1) entry_grid.setField(passwd_text, 0, 2) entry_grid.setField(passwd_field, 1, 2, anchorLeft=1) gf.add(t, 0, 0, padding=(0, 0, 0, 1)) gf.add(entry_grid, 0, 1, padding=(0, 0, 0, 1)) gf.add(bb, 0, 2, growx=1) button = bb.buttonPressed(gf.runOnce()) if button == 'back': return LEFT_BACKWARDS if user_field.value() != '': quoted_user = urllib.quote(user_field.value(), safe='') if passwd_field.value() != '': quoted_passwd = urllib.quote(passwd_field.value(), safe='') answers['source-address'] = url_field.value().replace( '//', '//%s:%s@' % (quoted_user, quoted_passwd), 1) else: answers['source-address'] = url_field.value().replace( '//', '//%s@' % quoted_user, 1) else: answers['source-address'] = url_field.value() if len(answers['source-address']) > 0: done = interactive_check_repo_def( (answers['source-media'], answers['source-address']), require_base_repo) return RIGHT_FORWARDS