Skip to content

Commit

Permalink
groups always sorted first, minor improvemens
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrj committed Mar 14, 2024
1 parent 79fbc96 commit 3cf84a0
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ jobs:
tag_name: ${{ steps.version.outputs.version }}
name: librer Release ${{ steps.version.outputs.version }}
draft: false
prerelease: true
prerelease: false
files: |
librer.${{ steps.version.outputs.version }}.portable.linux.zip
librer.${{ steps.version.outputs.version }}.portable.linux.nuitka.zip
Expand Down
52 changes: 18 additions & 34 deletions src/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,36 +34,33 @@
from time import sleep, perf_counter,time,strftime,localtime,mktime
from threading import Thread
from os import cpu_count,scandir,stat,sep,name as os_name,remove as os_remove,rename
from fnmatch import fnmatch

windows = bool(os_name=='nt')

if windows:
from subprocess import CREATE_NO_WINDOW
else:
from os import getpgid, killpg

from os.path import abspath,normpath,basename,dirname,join as path_join

from zipfile import ZipFile
from platform import system as platform_system,release as platform_release,node as platform_node

from re import search as re_search
from re import search as re_search,compile as re_compile
import sys
from collections import defaultdict
from pathlib import Path as pathlib_Path
from signal import SIGTERM

from re import compile as re_compile
from copy import deepcopy

from pickle import dumps,loads
from fnmatch import fnmatch
from zstandard import ZstdCompressor,ZstdDecompressor
from pympler.asizeof import asizeof
from send2trash import send2trash as send2trash_delete
from psutil import Process
from ciso8601 import parse_datetime

windows = bool(os_name=='nt')

if windows:
from subprocess import CREATE_NO_WINDOW
else:
from os import getpgid, killpg

is_frozen = bool(getattr(sys, 'frozen', False) or "__compiled__" in globals())

record_exe = ( ('record.exe') if is_frozen else ('python','src\\record.py') ) if windows else ( ('./record') if is_frozen else ('python3','./src/record.py') )

PARAM_INDICATOR_SIGN = '%'

Expand Down Expand Up @@ -739,9 +736,10 @@ def threaded_cde(timeout_semi_list,thread_index,thread_data_list,cde_errors_quan
cde_thread_is_alive = {}
any_thread_alive = True

for thread_index in range(threads):
cde_threads[thread_index] = cde_thread = Thread(target = lambda : threaded_cde(timeout_semi_list_per_thread[thread_index],thread_index,all_threads_data_list[thread_index],all_threads_files_cde_errors_quant[thread_index],all_threads_customdata_stats_time[thread_index]),daemon=True)
cde_thread.start()
for thread_index_loop in range(threads):
thread_index = thread_index_loop
cde_threads[thread_index] = Thread(target = lambda : threaded_cde(timeout_semi_list_per_thread[thread_index],thread_index,all_threads_data_list[thread_index],all_threads_files_cde_errors_quant[thread_index],all_threads_customdata_stats_time[thread_index]),daemon=True)
cde_threads[thread_index].start()

self_killed = self.killed

Expand Down Expand Up @@ -2320,7 +2318,7 @@ def create_new_record(self,temp_dir,update_callback,group=None):

new_file_path = sep.join([self.db_dir,f'rep.{int(time())}.dat'])

command = self.record_exe()
command = list(record_exe)
command.append('create')
command.append(new_file_path)
command.append(temp_dir)
Expand Down Expand Up @@ -2449,20 +2447,6 @@ def threaded_run(command,info_semi_list,processes_semi_list):

return True

def record_exe(self):
is_frozen = bool(getattr(sys, 'frozen', False) or "__compiled__" in globals())

if windows:
if is_frozen:
return(['record.exe'])

return(['python','src\\record.py'])

if is_frozen:
return(['./record'])

return(['python3','./src/record.py'])

def find_items_in_records(self,
temp_dir,
#range_par,
Expand Down Expand Up @@ -2498,7 +2482,7 @@ def find_items_in_records(self,
record_command_list={}

for record_nr,record in enumerate(records_to_process):
curr_command_list = record_command_list[record_nr] = self.record_exe()
curr_command_list = record_command_list[record_nr] = list(record_exe)
curr_command_list.extend(['search',record.file_path,temp_dir])
self.log.info(f'curr_command_list: {curr_command_list}')

Expand Down
55 changes: 32 additions & 23 deletions src/librer.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,9 +701,11 @@ def help_cascade_post():

try:
self.column_sort_last_params = self.cfg_get(CFG_SORTING)
if len(self.column_sort_last_params)!=7:
raise
except:
#colname,sort_index,is_numeric,reverse,dir_code,non_dir_code
self.column_sort_last_params=('#0',self_REAL_SORT_COLUMN_INDEX['#0'],self_REAL_SORT_COLUMN_IS_NUMERIC['#0'],0,0,1)
#colname,sort_index,is_numeric,reverse,group_code,dir_code,non_dir_code
self.column_sort_last_params=('#0',self_REAL_SORT_COLUMN_INDEX['#0'],self_REAL_SORT_COLUMN_IS_NUMERIC['#0'],0,0,1,2)

#######################################################################

Expand Down Expand Up @@ -2259,29 +2261,32 @@ def record_import_wii(self):
if sub_res:
res.append(sub_res)

if not res:
if res:
self.info_dialog_on_main.show('Where Is It? Import failed','\n'.join(res))
else:
###########################
self.info_dialog_on_main.show('Where Is It? Import','Successful.')
#self.info_dialog_on_main.show('Where Is It? Import','Successful.')
self.find_clear()
else:
self.info_dialog_on_main.show('Where Is It? Import failed','\n'.join(res))
self.column_sort(self.tree)
self.status('Where Is It? Import completed successfully.')

else:
label = self.wii_import_label_var.get()
self.status(f'importing {label} ... ')

res = librer_core.import_records_wii_do(compr,postfix,label,quant_files,quant_folders,filenames_set,wii_path_tuple_to_data,wii_paths_dict,cd_set,self.single_record_show,group)

if not res:
if res:
self.info_dialog_on_main.show('Where Is It? Import failed',res)
else:
###########################
self.info_dialog_on_main.show('Where Is It? Import','Successful.')
#self.info_dialog_on_main.show('Where Is It? Import','Successful.')
self.find_clear()
else:
self.info_dialog_on_main.show('Where Is It? Import failed',res)
self.column_sort(self.tree)
self.status('Where Is It? Import completed successfully.')

self.column_sort(self.tree)

@restore_status_line
#@restore_status_line
@block
def record_import(self):
initialdir = self.last_dir if self.last_dir else self.cwd
Expand All @@ -2300,10 +2305,11 @@ def record_import(self):
if import_res := librer_core.import_records(import_filenames,self.single_record_show,group):
self.info_dialog_on_main.show('Import failed',import_res)
else:
self.info_dialog_on_main.show('Import','Successful.')
#self.info_dialog_on_main.show('Import','Successful.')
self.find_clear()

self.column_sort(self.tree)
self.status('Import completed successfully.')

@restore_status_line
@block
Expand All @@ -2315,7 +2321,7 @@ def record_export(self):
if export_res := librer_core.export_record(self.current_record,export_file_path):
self.info_dialog_on_main.show('Export failed',export_res)
else:
self.info_dialog_on_main.show('Export','Successful.')
self.info_dialog_on_main.show('Export','Completed successfully.')

def focusin(self):
if self.main_locked_by_child:
Expand Down Expand Up @@ -3153,7 +3159,7 @@ def find_items(self):

find_results_quant_sum = 0

colname,sort_index,is_numeric,reverse,dir_code,non_dir_code = self.column_sort_last_params
colname,sort_index,is_numeric,reverse,group_code,dir_code,non_dir_code = self.column_sort_last_params
#print('\npre sort info colname:',colname,'is_numeric',is_numeric,'reverse:',reverse)
colname_real = self.REAL_SORT_COLUMN[colname]
#print('colname_real:',colname_real)
Expand Down Expand Up @@ -3655,15 +3661,15 @@ def assign_to_group(self):

@logwrapper
def column_sort_click(self, tree, colname):
prev_colname,prev_sort_index,prev_is_numeric,prev_reverse,prev_dir_code,prev_non_dir_code=self.column_sort_last_params
prev_colname,prev_sort_index,prev_is_numeric,prev_reverse,prev_group_code,prev_dir_code,prev_non_dir_code = self.column_sort_last_params
reverse = not prev_reverse if colname == prev_colname else prev_reverse
tree.heading(prev_colname, text=self.org_label[prev_colname])

dir_code,non_dir_code = (1,0) if reverse else (0,1)
group_code,dir_code,non_dir_code = (2,1,0) if reverse else (0,1,2)

sort_index=self.REAL_SORT_COLUMN_INDEX[colname]
is_numeric=self.REAL_SORT_COLUMN_IS_NUMERIC[colname]
self.column_sort_last_params=(colname,sort_index,is_numeric,reverse,dir_code,non_dir_code)
self.column_sort_last_params=(colname,sort_index,is_numeric,reverse,group_code,dir_code,non_dir_code)
self.cfg.set(CFG_SORTING,self.column_sort_last_params)

#print('\npre sort info colname:',colname,'is_numeric',is_numeric,'reverse:',reverse)
Expand All @@ -3679,7 +3685,7 @@ def column_sort_click(self, tree, colname):
def tree_sort_item(self,parent_item):
tree = self.tree

colname,sort_index,is_numeric,reverse,dir_code,non_dir_code = self.column_sort_last_params
colname,sort_index,is_numeric,reverse,group_code,dir_code,non_dir_code = self.column_sort_last_params

real_column_to_sort=self.REAL_SORT_COLUMN[colname]

Expand All @@ -3693,6 +3699,9 @@ def tree_sort_item(self,parent_item):

#dont sort single item and dummy item
#if len(children)>1:

self_GROUP = self.GROUP

for item in children:
values = tree.item(item,'values')

Expand All @@ -3705,7 +3714,7 @@ def tree_sort_item(self,parent_item):

kind = tree_set(item,'kind')

code= dir_code if kind in dir_or_dirlink else non_dir_code
code = group_code if kind is self_GROUP else dir_code if kind in dir_or_dirlink else non_dir_code
tlist_append( ( (code,sortval),item) )

tlist.sort(reverse=reverse,key=lambda x: x[0])
Expand All @@ -3721,15 +3730,15 @@ def tree_sort_item(self,parent_item):
@block_and_log
def column_sort(self, tree):
self.status('Sorting...')
colname,sort_index,is_numeric,reverse,dir_code,non_dir_code = self.column_sort_last_params
colname,sort_index,is_numeric,reverse,group_code,dir_code,non_dir_code = self.column_sort_last_params

self.column_sort_set_arrow(tree)
self.tree_sort_item(None)

tree.update()

def column_sort_set_arrow(self, tree):
colname,sort_index,is_numeric,reverse,dir_code,non_dir_code = self.column_sort_last_params
colname,sort_index,is_numeric,reverse,group_code,dir_code,non_dir_code = self.column_sort_last_params
tree.heading(colname, text=self.org_label[colname] + ' ' + str('\u25BC' if reverse else '\u25B2') )

def path_to_scan_set(self,path):
Expand Down Expand Up @@ -4459,7 +4468,7 @@ def open_item(self,item=None):

LUT_decode_loc = LUT_decode
if opened=='0' and children:
colname,sort_index,is_numeric,reverse,dir_code,non_dir_code = self.column_sort_last_params
colname,sort_index,is_numeric,reverse,group_code,dir_code,non_dir_code = self.column_sort_last_params
sort_index_local=sort_index

sort_val_func = int if is_numeric else lambda x : x
Expand Down

0 comments on commit 3cf84a0

Please sign in to comment.