Esempio n. 1
0
    def show_selected_files(self, cfg):
        panes = self.pane.window.get_panes()
        pane_id = panes.index(self.pane)
        cfg_show_hidden_files = load_json(
            'Panes.json')[pane_id]['show_hidden_files']
        selected = self.pane.get_selected_files()
        dir_folders = 0
        dir_files = 0
        dir_filesize = 0

        if selected:
            if cfg_show_hidden_files:
                for f in selected:
                    if is_dir(f):
                        dir_folders += 1
                    else:
                        dir_files += 1
                        dir_filesize += query(f, 'size_bytes')
            else:
                for f in selected:
                    if not is_hidden(as_path(f)):
                        if is_dir(f):
                            dir_folders += 1
                        else:
                            dir_files += 1
                            dir_filesize += query(f, 'size_bytes')

            bc = ByteConverter(dir_filesize)
            bcc = str(bc.calc())
            jFd = cfg['Justify']['folder']
            jFl = cfg['Justify']['file']
            jSz = cfg['Justify']['size']
            dir_foldK = "{0:,}".format(dir_folders)
            dir_fileK = "{0:,}".format(dir_files)
            statusbar = "Selected* "
            if dir_folders > 0:
                statusbar += "Dirs: " + dir_foldK.rjust(jFd, ' ') + "  "
                if dir_folders <= 9999:
                    statusbar += " "
            else:
                statusbar += "      " + ''.rjust(jFd, ' ') + "   "
            if dir_files > 0:
                statusbar += "Files: " + dir_fileK.rjust(jFl, ' ') + "   "
                if dir_files <= 9999:
                    statusbar += " "
            else:
                statusbar += "       " + ''.rjust(jFl, ' ') + "    "
            statusbar += "∑ Size: " + bcc.rjust(jSz, ' ') + "   "
            show_status_message(statusbar)

        else:
            StatusBarExtended.refresh(self, cfg)
Esempio n. 2
0
 def isADir(self, path):
     result = False
     try:
         result = is_dir(path)
     except Exception:
         result = False
     return (result)
Esempio n. 3
0
 def __call__(self, url=None):
     if url is None:
         url = self.pane.get_file_under_cursor() or self.pane.get_path()
     if not is_dir(url):
         url = dirname(url)
     new_url = Flat.scheme + splitscheme(url)[1]
     self.pane.set_path(new_url)
Esempio n. 4
0
    def __call__(self):
        # check file under cursor
        current_file = self.pane.get_file_under_cursor()
        # simply checking the file extension
        if re.compile(r'\.lnk$').search(current_file):
            # ok, let's receive the real folder containing the target of that shortcut
            shellscript = os.path.dirname(__file__) + "\link_target.ps1 "
            command = "powershell -ExecutionPolicy Bypass -NoLogo -Noninteractive -noprofile"
            command += ' -file "' + shellscript + '"'
            command += ' -link "' + as_human_readable(current_file) + '"'
            #show_status_message("Command: " + command) # temporary
            target = as_url(os.popen(command).read().strip())
            show_status_message("Target: " + target, 2)

            # what did we get?
            if False == exists(target):
                # target is not reachable...
                show_alert(target + " doesn't exist.")
            elif is_dir(target):
                # target is a folder, we go to it
                self.pane.set_path(target)
            else:
                # target is a file, we go to its directory
                self.pane.set_path(dirname(target))
        else:
            # nope, wrong thing
            show_alert(current_file + " is not a shortcut.")
Esempio n. 5
0
 def __call__(self, url=None):
     if url is None:
         file_under_cursor = self.pane.get_file_under_cursor()
         if file_under_cursor and is_dir(file_under_cursor):
             url = file_under_cursor
     if url:
         self.pane.set_path(url)
Esempio n. 6
0
def getURL(url):
    if not "drives://" in url:
        files = list(iterdir(url))
        if len(files) == 1:
            newUrl = join(url, files[0])
            if is_dir(newUrl):
                url = getURL(newUrl)
    return url
Esempio n. 7
0
 def __call__(self, url=None):
     text, ok = show_prompt('Enter Filter e.g. *.txt',
                            default="*.txt",
                            selection_start=2)
     if url is None:
         url = self.pane.get_file_under_cursor() or self.pane.get_path()
     if not is_dir(url):
         url = dirname(url)
     Flat.filtertext = text
     new_url = Flat.scheme + splitscheme(url)[1]
     # Not working yet
     if ok and text:
         self.pane.set_path(new_url + '?' + text)
Esempio n. 8
0
    def __call__(self):
        url = self.pane.get_path()
        scheme, path = splitscheme(url)

        if scheme != 'file://':
            show_alert('{} is not supported'.format(url))
            return

        paths = []
        paths.append(as_url(path))
        chosen_files = self.get_chosen_files()

        if chosen_files:
            for file in chosen_files:
                if not is_dir(file):
                    paths.append(file)

        openCommand(["-n", "-a"], paths, path)
Esempio n. 9
0
    def __call__(self):
        valid_methods = "\n".join(f" - {hm}" for hm in hash_map.keys())
        chosen_files = self.get_chosen_files()
        results = []

        # perform some checks on the selected files
        # as of now, only individual files are allowed, not directories
        dirs_in_selection = any([is_dir(fl) for fl in chosen_files])
        if dirs_in_selection:
            show_alert("Please specify individual files, not directories.")
            return
        else:
            hmeth, okay = show_prompt(
                f"Enter one of the following hashing methods:\n{valid_methods}"
            )
            hmeth = hmeth.strip()
            if hmeth not in hash_map.keys():
                response = show_alert(
                    "Invalid hashing method. No action taken.")
                return
        s = None
        if hmeth in ["shake_128", "shake_256"]:
            s, okay = show_prompt("Enter the size of the hash:")
            if not s.isnumeric():
                response = show_alert("Invalid integer. Goodbye!")
                return
            s = int(s)

        # perform the actual hash calculations
        num_selected_files = len(chosen_files)
        for fl in chosen_files:
            fl = as_human_readable(fl)
            fhash = file_hash(fl, hmeth, s)
            hstr = f"{fl}: {fhash}"
            results.append(hstr)
            all_results = "\n".join(results)
            clipboard.set_text(all_results)
        if num_selected_files == 1:
            msg = (
                f"The path and {hmeth} hash of the specified file has been copied to your clipboard as well as being attached here:\n\n{all_results}"
            )
        else:
            msg = f"The paths and {hmeth} hashes of the {num_selected_files} selected files have been copied to your clipboard as well as being attached here:\n\n{all_results}"
        response = show_alert(msg)
Esempio n. 10
0
 def __call__(self):
     file_under_cursor = self.pane.get_file_under_cursor()
     if file_under_cursor:
         try:
             f_is_dir = is_dir(file_under_cursor)
         except OSError as e:
             show_alert('Could not read from %s (%s)' %
                        (as_human_readable(file_under_cursor), e))
             return
         if f_is_dir:
             self.pane.set_path(file_under_cursor)
         else:
             # Archive handling:
             scheme, path = splitscheme(file_under_cursor)
             if scheme == 'file://':
                 new_scheme = self._get_handler_for_archive(path)
                 if new_scheme:
                     new_url = new_scheme + path
                     self.pane.run_command('open_directory',
                                           {'url': new_url})
Esempio n. 11
0
 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)
Esempio n. 12
0
    def __call__(self, url=None):

        sourceDirUrl = self.pane.get_path()
        archiveName = basename(sourceDirUrl) + '.7z'

        oppositePane = _get_opposite_pane(self.pane)
        oppositePaneUrl = oppositePane.get_path()

        archiveUrl = join(oppositePaneUrl, archiveName)

        sourceDir = as_human_readable(sourceDirUrl)
        archive = as_human_readable(archiveUrl)

        if exists(archiveUrl):

            if is_dir(archiveUrl):
                message = archiveName + " exists and is a directory, aborting!"
                show_alert(message)
                return

            choice = show_alert("Archive exists!\nReplace?",
                                buttons=YES | CANCEL,
                                default_button=CANCEL)
            if choice == YES:
                try:
                    move_to_trash(archiveUrl)
                except NotImplementedError:
                    show_alert("Failed to delete archive, aborting!")
                    return

            elif choice == CANCEL:
                return

        submit_task(CreateArchive(archive, sourceDir))
        oppositePane.reload()

        return
Esempio n. 13
0
    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
Esempio n. 14
0
 def __call__(self):
     file_under_cursor = self.pane.get_file_under_cursor()
     if file_under_cursor and is_dir(file_under_cursor):
         self.pane.set_path(file_under_cursor)
Esempio n. 15
0
_CHECK_EXTENSION = True
_COMPRESS_ARGS = ['a']
_HASH = 'sha256'

settings = load_json('SevenZipTools.json', default={})
result = settings.get('7zip', {})
with open('R:/out.txt', 'w') as myfile:
    myfile.write(str(settings) + '\n')
if result:
    try:
        exePath = result['path']
    except (KeyError, TypeError):
        pass
    else:
        exePathUrl = as_url(exePath)
        if exists(exePathUrl) and not is_dir(exePathUrl):
            _USER_7ZIP = exePath
            _SUPPORTED_EXTENSIONS += ['.rar']

result = settings.get('additional extensions', [])
if result and isinstance(result, list):
    _SUPPORTED_EXTENSIONS += result

result = settings.get('ignore extension', None)
if result:
    _CHECK_EXTENSION = False

result = settings.get('compress args', [])
if result and isinstance(result, list):
    _COMPRESS_ARGS += result
Esempio n. 16
0
    def refresh(self, cfg):

        panes = self.pane.window.get_panes()
        pane_id = panes.index(self.pane)
        statusbar_pane = ""

        cfg_show_hidden_files = load_json(
            'Panes.json')[pane_id]['show_hidden_files']
        pane_show_hidden_files = cfg['SymbolHiddenF'][0] if cfg_show_hidden_files else\
                                 cfg['SymbolHiddenF'][1]
        cur_dir_url = self.pane.get_path()
        current_dir = as_path(cur_dir_url)
        dir_folders = 0
        dir_files = 0
        dir_filesize = 0
        dir_files_in_dir = glob.glob(current_dir + "/*")
        if PLATFORM == 'Windows' and not cfg['HideDotfile']:
            # .dotfiles=regular (always shown unless have a 'hidden' attr)
            dir_files_in_dir += glob.glob(current_dir + "/.*")
        elif cfg_show_hidden_files:  # .dotfile=hidden (internal option shows)
            dir_files_in_dir += glob.glob(current_dir + "/.*")
        f_url = ""
        aboveMax = False

        if not dir_files_in_dir:
            pass
        elif len(dir_files_in_dir) > cfg['MaxGlob']:
            aboveMax = True
        else:
            if cfg_show_hidden_files:
                for f in dir_files_in_dir:
                    f_url = as_url(f)
                    if is_dir(f_url):
                        dir_folders += 1
                    else:
                        dir_files += 1
                        try:
                            dir_filesize += query(f_url, 'size_bytes')
                        except Exception as e:
                            continue
            else:
                for f in dir_files_in_dir:
                    f_url = as_url(f)
                    if not is_hidden(f):
                        if is_dir(f_url):
                            dir_folders += 1
                        else:
                            dir_files += 1
                            try:
                                dir_filesize += query(f_url, 'size_bytes')
                            except Exception as e:
                                continue

        bc = ByteConverter(dir_filesize)
        bcc = str(bc.calc())
        maxG = str("{0:,}".format(cfg['MaxGlob']))
        jFd = cfg['Justify']['folder']
        jFl = cfg['Justify']['file']
        jSz = cfg['Justify']['size']
        dir_foldK = str(
            "{0:,}".format(dir_folders))  # to ','→' ' add .replace(',', ' ')
        dir_fileK = str("{0:,}".format(dir_files))
        if (self.pane == panes[0]):
            statusbar_pane += cfg['SymbolPane'][0]
        else:
            statusbar_pane += cfg['SymbolPane'][1]
        statusbar_pane += "   " + pane_show_hidden_files + "     "
        if dir_folders > 0:
            statusbar_pane += "Dirs: " + dir_foldK.rjust(jFd, ' ') + "  "
            if dir_folders <= 9999:
                statusbar_pane += " "
        elif aboveMax:
            statusbar_pane += "Dirs  " + '+  '.rjust(jFd, ' ') + "   "
        else:
            statusbar_pane += "      " + ''.rjust(jFd, ' ') + "   "
        if dir_files > 0:
            statusbar_pane += "Files: " + dir_fileK.rjust(jFl, ' ') + "   "
            if dir_files <= 9999:
                statusbar_pane += " "
        elif aboveMax:
            statusbar_pane += "Files >" + maxG.rjust(jFl, ' ') + "    "
        else:
            statusbar_pane += "       " + ''.rjust(jFl, ' ') + "    "
        if not aboveMax:
            statusbar_pane += "  Size: " + bcc.rjust(jSz, ' ') + "   "
            #        to align with "∑ Size: "

        show_status_message(statusbar_pane, 5000)
Esempio n. 17
0
 def is_dir(self, path):
     # path=remove_query_text(path)
     return is_dir(to_file_url(path))