def __call__(self): selected_files = self.pane.get_selected_files() if len(selected_files) >= 1 or (len(selected_files) == 0 and self.get_chosen_files()): if len(selected_files) == 0 and self.get_chosen_files(): selected_files.append(self.get_chosen_files()[0]) # # Loop through each file/directory selected. # for filedir in selected_files: p = as_human_readable(filedir) filepath = os.path.abspath(p) if os.path.isdir(filepath): # # It is a directory. Process as a directory. # newDir = filepath + "-copy" copy(as_url(filepath), as_url(newDir)) else: if os.path.isfile(filepath): # # It is a file. Process as a file. # dirPath, ofilenmc = os.path.split(filepath) ofilenm, ext = os.path.splitext(ofilenmc) nfilenm = os.path.join(dirPath, ofilenm + "-copy" + ext) copy(as_url(filepath), as_url(nfilenm)) else: show_alert('Bad file path : {0}'.format(filepath))
def on_command(self, command_name, args): if command_name != 'open_file': return url = args['url'] scheme, path = splitscheme(url) if not is_ftp(scheme): return tmp = NamedTemporaryFile(prefix=basename(path), delete=False) tmp_path = tmp.name tmp_url = 'file://' + tmp_path fs.copy(url, tmp_url) _open_local_file(tmp_path) choice = show_alert( 'Upload modified file?', buttons=YES | NO, default_button=YES ) if choice == YES: fs.move(tmp_url, url) return 'reload', {}
def move(self, src_url, dst_url): # Rename on same server src_scheme, src_path = splitscheme(src_url) dst_scheme, dst_path = splitscheme(dst_url) if src_scheme == dst_scheme and commonprefix([src_path, dst_path]): # TODO avoid second connection with FtpWrapper(src_url) as src_ftp, \ FtpWrapper(dst_url) as dst_ftp: src_ftp.conn.rename(src_ftp.path, dst_ftp.path) return fs.copy(src_url, dst_url) if fs.exists(src_url): fs.delete(src_url)
def __call__(self, method="move"): target_path = get_path_to_other_pane(self.pane) chosen_files = self.get_chosen_files() for filep in chosen_files: dest_url = join( target_path, basename(filep) ) if method == "move": move(filep, dest_url) elif method == "copy": copy(filep, dest_url) else: pass
def __call__(self): # get as list of all chosen filenames that need to be attached chosenFiles = self.get_chosen_files() # create the string for the attachment attachment_string = '' for it in chosenFiles: # human readable file name ithr = as_human_readable(it) foldername = ithr.split('/')[-1] # check if folder, if so, create a zip file of the folder and add that one to the filename list! if is_dir(it): # create zipname zipname = 'zip://' + ithr + '.zip' # make sure the sip file does not exist yet if exists(zipname): choice = show_alert( 'The zip file already exists. Do you want to overwrite it?', buttons=YES | NO, default_button=NO) if choice == NO: return # create a zip file, pack the folder into the zip file copy(it, zipname + '/' + foldername) # inform fman that the zip file exists now notify_file_added(zipname) # now we want to add the zip file instead of the selected file, so change it before adding it to the string ithr = zipname.replace('zip://', '') # attach the file to the string of what to attach to the e-mail message attachment_string += ithr if it is not chosenFiles[-1]: attachment_string += ',' # set up the command to start a new e-mail message and attach it cmd = 'thunderbird -compose \"attachment=\'' + attachment_string + '\'\"' # print the command - untoggle for checking before sending # show_alert(cmd) # send the command os.system(cmd)
def copy(self, src_url, dst_url): # Recursive copy if fs.is_dir(src_url): fs.mkdir(dst_url) for fname in fs.iterdir(src_url): fs.copy(urljoin(src_url, fname), urljoin(dst_url, fname)) return if is_ftp(src_url) and is_ftp(dst_url): with FtpWrapper(src_url) as src_ftp, \ FtpWrapper(dst_url) as dst_ftp: with src_ftp.conn.open(src_ftp.path, 'rb') as src, \ dst_ftp.conn.open(dst_ftp.path, 'wb') as dst: dst_ftp.conn.copyfileobj(src, dst) elif is_ftp(src_url) and is_file(dst_url): _, dst_path = splitscheme(dst_url) with FtpWrapper(src_url) as src_ftp: src_ftp.conn.download(src_ftp.path, dst_path) elif is_file(src_url) and is_ftp(dst_url): _, src_path = splitscheme(src_url) with FtpWrapper(dst_url) as dst_ftp: dst_ftp.conn.upload(src_path, dst_ftp.path) else: raise UnsupportedOperation