adding file with Saerch object
authorAlexandr Popov <popov2al@gmail.com>
Mon, 9 Mar 2009 16:12:00 +0000 (19:12 +0300)
committerAlexandr Popov <popov2al@gmail.com>
Mon, 9 Mar 2009 16:12:00 +0000 (19:12 +0300)
src/searchfile.py [new file with mode: 0644]

diff --git a/src/searchfile.py b/src/searchfile.py
new file mode 100644 (file)
index 0000000..d543551
--- /dev/null
@@ -0,0 +1,31 @@
+#!/usr/bin/env python
+# -*-coding: utf-8 -*-
+# vim: sw=4 ts=4 expandtab ai
+# pylint: disable-msg=C0301
+
+class SearchFile(object):
+
+    def filesorter(self, dir):
+        import os
+        # Проходим по всем папкам вглубь от заданного пути
+        for dirpath, dirname, names in os.walk(dir):
+            for name in names:
+                flpath = os.path.join(dirpath, name)
+                # Возвращаем размер и полный путь файла
+                yield (os.path.getsize(flpath), flpath)
+
+    def run(self):
+        from file import File
+        import heapq
+        file = File(self.ui)
+        for fsize, fpath in heapq.nlargest(self.count, self.filesorter(self.path)):
+            file.add(fpath, fsize)
+            file.show()
+
+    def __init__(self, input, config, ui):
+        self.path, self.count = input.get_st_par()
+        if not self.path:
+            self.path = config.get("default_start_dir")
+        if not self.count:
+            self.count = config.get("default_count")
+        self.ui = ui