d543551bcee16369ca27d5a83b8fc89d6dd4fe8b
[findit] / src / searchfile.py
1 #!/usr/bin/env python
2 # -*-coding: utf-8 -*-
3 # vim: sw=4 ts=4 expandtab ai
4 # pylint: disable-msg=C0301
5
6 class SearchFile(object):
7
8     def filesorter(self, dir):
9         import os
10         # Проходим по всем папкам вглубь от заданного пути
11         for dirpath, dirname, names in os.walk(dir):
12             for name in names:
13                 flpath = os.path.join(dirpath, name)
14                 # Возвращаем размер и полный путь файла
15                 yield (os.path.getsize(flpath), flpath)
16
17     def run(self):
18         from file import File
19         import heapq
20         file = File(self.ui)
21         for fsize, fpath in heapq.nlargest(self.count, self.filesorter(self.path)):
22             file.add(fpath, fsize)
23             file.show()
24
25     def __init__(self, input, config, ui):
26         self.path, self.count = input.get_st_par()
27         if not self.path:
28             self.path = config.get("default_start_dir")
29         if not self.count:
30             self.count = config.get("default_count")
31         self.ui = ui