📄 lftp_client.py
字号:
if path == '': path = '/' LftpCommand.__init__(self, lftp, 'cd "%s"' % path) def parse_result(self): cpl = self.proc.compile_pattern_list([ LftpClient.PROMPT_STRING, ".*: Access failed: (\d*) (.*)\r"]) index = -1 error = None while index != 0: index = self.proc.expect(cpl) if index == 1: m = self.proc.match error = FTPAccessFailedException(string.atoi(m.group(1)), m.group(2)) if error: raise errorclass LftpListdCommand(LftpCommand): def __init__(self, lftp, apath): LftpCommand.__init__(self, lftp, 'ls -d -q "%s"' % apath)class LftpListCommand(LftpCommand): def __init__(self, lftp, updater=None, dir='', clear_cache=0): self.__updater = updater if clear_cache: LftpCommand.__init__(self, lftp, 'rels %s' % dir) else: LftpCommand.__init__(self, lftp, 'ls %s' % dir) def parse_result(self): first = self.proc.compile_pattern_list([ LftpClient.PROMPT_STRING, '([drwxsS\-]{10,11}) ']) digit = self.proc.compile_pattern_list(['(\d+) ']) word = self.proc.compile_pattern_list(['([\w\:]+) ']) lastany = self.proc.compile_pattern_list([ '(?: *)(.*)\r\n']) filelist = [] while 1: index = self.proc.expect(first) if index == 0: break attr = self.proc.match.group(1) self.proc.expect(digit) childnum = self.proc.match.group(1) self.proc.expect(word) owner = self.proc.match.group(1) self.proc.expect(word) group = self.proc.match.group(1) self.proc.expect(digit) size = self.proc.match.group(1) self.proc.expect(word) month = self.proc.match.group(1) self.proc.expect(digit) day = self.proc.match.group(1) self.proc.expect(word) year_or_time = self.proc.match.group(1) self.proc.expect(lastany) name = unicode(self.proc.match.group(1), self.lftp.ftp_engine.site_info.remote_charset) while ord(name[0]) == 27: pos = string.find(name, 'm') name = name[pos+1:] epos = string.rfind(name, chr(27)) while epos >= 0: name = name[0:epos] epos = string.rfind(name, chr(27)) filelist.append((attr, childnum, owner, group, size, month, day, year_or_time, name)) if len(filelist) == 10: gtk.idle_add(self.__updater, filelist) filelist = [] if len(filelist) > 0: gtk.idle_add(self.__updater, filelist) return class LftpQuitCommand(LftpCommand): def __init__(self, lftp): LftpCommand.__init__(self, lftp, "quit") def parse_result(self): self.proc.expect([pexpect.EOF]) returnclass LftpPwdCommand(LftpCommand): def __init__(self, lftp, updater): LftpCommand.__init__(self, lftp, "pwd") self.__updater = updater def parse_result(self): r = LftpCommand.parse_result(self) gtk.idle_add(self.__updater, unicode( r, self.lftp.ftp_engine.site_info.remote_charset)) return rclass LftpTransferCommand(LftpCommand): def __init__(self, lftp, command, running_updater, finish_updater): LftpCommand.__init__(self, lftp, command) self.__rupdater = running_updater self.__fupdater = finish_updater def parse_result(self): rec = re.compile(".*' at (\d+) .*\[(.+)\]") rec_prompt = re.compile(LftpClient.PROMPT_STRING) rec_failed = re.compile(".*: Access failed: (\d*) (.*)") line = '' error = None while 1: c = self.proc.read(1) if ord(c) == 13: #print 'line', len(line), line m = rec.match(line) if m != None: gtk.idle_add(self.__rupdater, m.group(1), m.group(2)) while ord(c) == 13: c = self.proc.read(1) if ord(c) == 10: break line = c else: line = line + c m = rec_prompt.match(line) if m != None: # nothing transfered gtk.idle_add(self.__fupdater) return m = rec_failed.match(line) if m != None: error = FTPAccessFailedException(string.atoi(m.group(1)), m.group(2)) if error: gtk.idle_add(self.__fupdater, 1) raise error if re.match('.*bytes transferred', line): gtk.idle_add(self.__fupdater) r = LftpCommand.parse_result(self) returnclass LftpPutCommand(LftpTransferCommand): def __init__(self, lftp, source, target, running_updater, finish_updater): cmd = 'put "%s" -o "%s"' % (source, target) LftpTransferCommand.__init__(self, lftp, cmd, running_updater, finish_updater) class LftpGetCommand(LftpTransferCommand): def __init__(self, lftp, source, target, resume, running_updater, finish_updater): if resume: cmd = 'get -c "%s" -o "%s"' % (source, target) else: cmd = 'get "%s" -o "%s"' % (source, target) LftpTransferCommand.__init__(self, lftp, cmd, running_updater, finish_updater)class LftpDeleteCommand(LftpCommand): def __init__(self, lftp, name, isdir): if not isdir: LftpCommand.__init__(self, lftp, 'rm "%s"' % name) else: LftpCommand.__init__(self, lftp, 'rmdir "%s"' % name) def parse_result(self): cpl = self.proc.compile_pattern_list([ LftpClient.PROMPT_STRING, ".* ok, (.*)\r", ".*: Access failed: (\d*) (.*)\r"]) index = -1 error = None while index != 0: index = self.proc.expect(cpl) if index == 1: # rm ok pass elif index == 2: m = self.proc.match error = FTPAccessFailedException(string.atoi(m.group(1)), m.group(2)) if error: raise error returnclass LftpMoveCommand(LftpCommand): def __init__(self, lftp, old_name, new_name): LftpCommand.__init__(self, lftp, 'mv "%s" "%s"' % (old_name, new_name)) def parse_result(self): cpl = self.proc.compile_pattern_list([ LftpClient.PROMPT_STRING, "rename successful", ".*: Access failed: (\d*) (.*)\r"]) index = -1 error = None while index != 0: index = self.proc.expect(cpl) if index == 1: # rename ok pass elif index == 2: error = FTPAccessFailedException(string.atoi(m.group(1)), m.group(2)) pass if error: raise error returnclass LftpMkdirCommand(LftpCommand): def __init__(self, lftp, name): LftpCommand.__init__(self, lftp, 'mk "%s"' % (name)) def parse_result(self): cpl = self.proc.compile_pattern_list([ LftpClient.PROMPT_STRING, "mkdir ok", "Access failed"]) index = -1 while index != 0: index = self.proc.expect(cpl) if index == 1: # rename ok pass elif index == 2: # rename fail pass return
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -