Skip to content

Commit

Permalink
work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrj committed Oct 31, 2023
1 parent f222325 commit 8b11b41
Show file tree
Hide file tree
Showing 2 changed files with 305 additions and 299 deletions.
31 changes: 23 additions & 8 deletions src/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from os.path import join as path_join
from os.path import abspath
from os.path import normpath
from os import remove as os_remove

from fnmatch import fnmatch
from time import time
Expand Down Expand Up @@ -95,7 +96,7 @@ def file_name(self,main=True):
else:
return f'{self.db.rid}.cd.dat' #custom data

def abort():
def abort(self):
self.abort_action = True

def do_scan(self, path, dictionary) :
Expand Down Expand Up @@ -256,7 +257,8 @@ def extract_custom_data(self,cde_list):
#print(self.custom_data)

def find_items_rec(self,func_to_call,local_dict,parent_path_components=[]):
for name,(is_dir,is_file,is_symlink,size,mtime,sub_dict) in local_dict.items():
#print(' find_items_rec',func_to_call,parent_path_components)
for name,(is_dir,is_file,is_symlink,size,mtime,inode,dev,sub_dict) in local_dict.items():
if func_to_call(name):
single_res = parent_path_components.copy()
single_res.append(name)
Expand All @@ -266,7 +268,8 @@ def find_items_rec(self,func_to_call,local_dict,parent_path_components=[]):
self.find_items_rec(func_to_call,sub_dict,parent_path_components + [name])

def find_items(self,func_to_call):
self.find_results = set()
#print('find_items',func_to_call)
self.find_results = []

local_dict = self.db.data
parent_path_components = []
Expand Down Expand Up @@ -325,11 +328,12 @@ def create(self,label='',path=''):
self.records.add(new_record)
return new_record

def abort(self):
print('LibrerCore abort')
pass
#def abort(self):
# self.abort_action
# print('LibrerCore abort')
# pass

def read_list(self,callback=None):
def read_list(self,callback_pre,callback=None):
self.log.info('read_list: %s',self.db_dir)
try:
with scandir(self.db_dir) as res:
Expand All @@ -339,6 +343,9 @@ def read_list(self,callback=None):
self.log.info('db:%s',ename)
new_record = self.create()

#print('ename',ename)
callback_pre(ename)

if new_record.load(self.db_dir,ename) :
self.log.warning('removing:%s',ename)
self.records.remove(new_record)
Expand All @@ -360,6 +367,7 @@ def read_list(self,callback=None):
def find_items_in_all_records(self,func_to_call):
res = []
for record in self.records:
#print('find_items_in_all_records - record',record)
sub_res = record.find_items(func_to_call)
if sub_res:
for single_res in sub_res:
Expand All @@ -371,5 +379,12 @@ def delete_record_by_id(self,rid):
for record in self.records:
if record.db.rid == rid:
print('found record to delete:',rid)
break

for file_path in [sep.join([self.db_dir,record.file_name(bool_param)]) for bool_param in (False,True)]:
self.log.info('deleting file:%s',file_path)
try:
os_remove(file_path)
except Exception as e:
self.log.error(e)


Loading

0 comments on commit 8b11b41

Please sign in to comment.