Skip to content

Commit

Permalink
finding & sorting in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrj committed Nov 21, 2023
1 parent fb71385 commit c6ed8a3
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 128 deletions.
33 changes: 24 additions & 9 deletions src/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ def __init__(self,label,path,log):
self.db = LibrerCoreData(label,path)

self.log = log
self.find_results = set()
self.find_results_list = []
self.find_results = []

self.info_line = ''
self.info_line_current = ''

Expand Down Expand Up @@ -632,8 +632,8 @@ def find_items(self,
error_kind_code = self.search_kind_code_tab['error']
fuzzy_kind_code = self.search_kind_code_tab['fuzzy']

find_results = self.find_results = set()
find_results_add = find_results.add
find_results = self.find_results = []
find_results_add = find_results.append

data_loc = self.db.data

Expand Down Expand Up @@ -671,6 +671,8 @@ def find_items(self,
print('format error:',data_entry_len,data_entry[0])
continue

next_level = parent_path_components + [name]

is_dir,is_file,is_symlink,is_bind,has_cd,has_files,cd_ok,is_compressed = entry_LUT_decode_loc[code]

sub_data = fifth_field if is_dir and has_files else None
Expand All @@ -684,11 +686,10 @@ def find_items(self,
#katalog moze spelniac kryteria naazwy pliku ale nie ma rozmiaru i custom data
if name_func_to_call:
if name_func_to_call(name):
single_res = parent_path_components + [name]
find_results_add( tuple(single_res) )
find_results_add( tuple([tuple(next_level),size,mtime]) )

if sub_data:
search_list_append( (sub_data,parent_path_components + [name]) )
search_list_append( (sub_data,next_level) )

elif is_file:
if use_size:
Expand Down Expand Up @@ -742,9 +743,17 @@ def find_items(self,
else:
continue

find_results_add( tuple(parent_path_components + [name]) )
find_results_add( tuple([tuple(next_level),size,mtime ]) )

self.find_results_list = list(find_results)
def find_items_sort(self,what,reverse):
if what=='data':
self.find_results.sort(key = lambda x : x[0],reverse=reverse)
elif what=='size':
self.find_results.sort(key = lambda x : (x[0][0:-1],x[1]),reverse=reverse)
elif what=='ctime':
self.find_results.sort(key = lambda x : (x[0][0:-1],x[2]),reverse=reverse)
else:
print('unknown sorting',what,mod)

def save(self) :
file_name=self.new_file_name()
Expand All @@ -755,6 +764,12 @@ def save(self) :
with gzip_open(file_path, "wb") as gzip_file:
pickle_dump(self.db, gzip_file)

try:
self.FILE_NAME = file_name
self.FILE_SIZE = stat(file_path).st_size
except Exception as e:
print('stat error:%s' % e )

self.info_line = ''

def load(self,db_dir,file_name):
Expand Down
Loading

0 comments on commit c6ed8a3

Please sign in to comment.