Example #1
0
 def RenameNode(self, node, name):
     newpath = os.path.join(os.path.dirname(node.path), name)
     if newpath != node.path:
         try:
             if (yield async_call(os.path.exists, newpath)):
                 if not dialogs.ask_overwrite(self, newpath):
                     return
             yield async_call(fileutil.rename, node.path, newpath)
             self.SelectLater(self.GetItemParent(node.item), name)
         except OSError, e:
             dialogs.error(self, str(e))
Example #2
0
    def find(self, details, filter=None):
        self.stop()

        matcher = make_matcher(details.find,
            case_sensitive=details.case, is_regexp=details.regexp)

        self.start_time = time.time()
        self.details = details
        self.finder = Search(details.path, matcher, output=self, filter=filter)
        async_call(self.finder.search)
        self.Clear()
        self.output.start()
Example #3
0
 def add(self, name, tree, monitor, filter):
     try:
         file_info = (yield async_call(get_file_info, self.path, name))
         if file_info.node_type and filter(file_info):
             yield dirtree_create_node(tree, self.item, file_info)
     except OSError as e:
         pass
Example #4
0
    def LoadFile(self, path):
        self.SetReadOnly(True)
        self.Disable()

        old_path = self.path
        self.path = path
        self.sig_title_changed.signal(self)

        try:
            text = (yield async_call(read_file, path, "r"))
            text, self.file_encoding = decode_text(text)
            text = clean_text(text)

            self.modified_externally = False
            self.SetReadOnly(False)
            self.SetSyntaxFromFilename(path)
            self.SetText(text)
            self.SetSavePoint()

            if old_path:
                self.env.remove_monitor_path(old_path)
            self.env.add_monitor_path(path)
        except:
            self.path = old_path
            self.sig_title_changed.signal(self)
            self.sig_status_changed.signal(self)
            raise
        finally:
            self.Enable()
            self.SetReadOnly(False)
Example #5
0
def shell_copy(srcpath, dstpath, parent=None):
    if destination_is_same(srcpath, dstpath):
        return
    if ask_copy_file(parent, srcpath, dstpath):
        try:
            yield async_call(shutil.copy2, srcpath, dstpath)
        except Exception as e:
            dialogs.error(parent, "Error copying file:\n\n%s" % e)
Example #6
0
 def NewFolder(self, node, name):
     path = os.path.join(node.path, name)
     try:
         yield async_call(os.mkdir, path)
         if self.IsExpanded(node.item):
             self.SelectLater(node.item, name)
     except OSError, e:
         dialogs.error(self, str(e))
Example #7
0
    def WriteFile(self, path):
        def do_write_file(path, text):
            mkpath(os.path.dirname(path))
            atomic_write_file(path, text)

        text, self.file_encoding = encode_text(self.GetText(), self.file_encoding)
        text = clean_text(text)
        with self.env.updating_path(path):
            yield async_call(do_write_file, path, text)
        self.modified_externally = False
        self.SetSavePoint()
Example #8
0
    def find(self, details):
        self.stop()

        matcher = make_matcher(details.find,
            case_sensitive=details.case, is_regexp=details.regexp)

        if details.hidden:
            def dir_filter(info):
                return True
        else:
            def dir_filter(info):
                return bool(not info.hidden
                    and not re_hidden_dirs.match(info.filename))

        if details.file_patterns.strip():
            file_pattern_re = compile_file_patterns(details.file_patterns)
            if details.hidden:
                def file_filter(info):
                    return bool(file_pattern_re.match(info.filename))
            else:
                def file_filter(info):
                    return bool(not info.hidden
                        and not re_hidden_files.match(info.filename)
                        and file_pattern_re.match(info.filename))
        else:
            if details.hidden:
                def file_filter(info):
                    return True
            else:
                def file_filter(info):
                    return bool(not info.hidden
                        and not re_hidden_files.match(info.filename))

        self.start_time = time.time()
        self.details = details
        self.finder = Search(details.path, matcher, output=self, file_filter=file_filter, dir_filter=dir_filter)
        async_call(self.finder.search)
        self.Clear()
        self.output.start()
Example #9
0
 def expand(self, tree, monitor, filter):
     if self.type == 'd' and not self.populated:
         try:
             if not self.watch:
                 self.watch = monitor.add_dir_watch(self.path, user=self)
             for file_info in (yield async_call(list_dir_file_info_sorted, self.path)):
                 if file_info.node_type and filter(file_info):
                     dirtree_create_node(tree, self.item, file_info)
             tree.SetItemImage(self.item, IM_FOLDER)
             tree.SetItemHasChildren(self.item, tree.GetFirstChild(self.item)[0].IsOk())
         except Exception:
             self.populated = False
             print traceback.format_exc()
         else:
             self.populated = True
Example #10
0
def shell_move(srcpath, dstpath, parent=None):
    if destination_is_same(srcpath, dstpath):
        return
    if ask_move_file(parent, srcpath, dstpath):
        dstfile = os.path.join(dstpath, os.path.basename(srcpath))
        if os.path.exists(dstfile):
            if not ask_overwrite_file(parent, dstfile):
                return
            try:
                os.remove(dstfile)
            except Exception as e:
                dialogs.error(parent, "Error overwriting file file:\n\n%s" % e)
                return
        try:
            yield async_call(shutil.move, srcpath, dstpath)
        except Exception as e:
            dialogs.error(parent, "Error moving file:\n\n%s" % e)
Example #11
0
 def add(self, name, tree, monitor, filter):
     if self.state == NODE_POPULATED:
         try:
             info = (yield async_call(get_file_info, self.path, name))
         except OSError, e:
             return
         if not filter(info):
             return
         if info.is_file:
             type = 'f'
             image = IM_FILE
         elif info.is_dir:
             type = 'd'
             image = IM_FOLDER
         item = dirtree_insert(tree, self.item, name, image)
         node = FSNode(info.path, type)
         tree.SetItemNode(item, node)
         if type == 'd':
             tree.SetItemHasChildren(item, True)
         tree.SetItemHasChildren(self.item, True)
         yield item
Example #12
0
 def _do_expand(self, tree, monitor, filter):
     self.watch = monitor.add_dir_watch(self.path, user=self)
     dirs = []
     files = []            
     for info in (yield async_call(listdir, self.path)):
         if not filter(info):
             continue
         path = os.path.join(self.path, info.filename)
         if info.is_file:
             files.append(FSNode(path, 'f'))
         elif info.is_dir:
             dirs.append((FSNode(path, 'd'), info.listable))
     for node, listable in dirs:
         image = IM_FOLDER if listable else IM_FOLDER_DENIED
         item = tree.AppendItem(self.item, node.label, image)
         tree.SetItemNode(item, node)
         tree.SetItemHasChildren(item, listable)
     for node in files:
         item = tree.AppendItem(self.item, node.label, IM_FILE)
         tree.SetItemNode(item, node)
     tree.SetItemImage(self.item, IM_FOLDER)
     tree.SetItemHasChildren(self.item, tree.GetFirstChild(self.item)[0].IsOk())
Example #13
0
def shell_remove(path, parent=None):
    if ask_delete_file(parent, path):
        try:
            yield async_call(remove, path)
        except Exception as e:
            dialogs.error(parent, "Error deleting file:\n\n%s" % e)
Example #14
0
 def _shell_open(self, path):
     try:
         self.cm.add(async_call(fileutil.shell_open, path, workdir=os.path.dirname(path)))
     except OSError, e:
         dialogs.error(self, str(e))