From 3cf84a096128da3328ab5a48b6795329d120dfb4 Mon Sep 17 00:00:00 2001 From: piotrj Date: Thu, 14 Mar 2024 21:34:51 +0100 Subject: [PATCH] groups always sorted first, minor improvemens --- .github/workflows/run.yml | 2 +- src/core.py | 52 +++++++++++++----------------------- src/librer.py | 55 +++++++++++++++++++++++---------------- 3 files changed, 51 insertions(+), 58 deletions(-) diff --git a/.github/workflows/run.yml b/.github/workflows/run.yml index c151f3c..9ac5d13 100644 --- a/.github/workflows/run.yml +++ b/.github/workflows/run.yml @@ -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 diff --git a/src/core.py b/src/core.py index ebbba8e..28cb4e0 100755 --- a/src/core.py +++ b/src/core.py @@ -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 = '%' @@ -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 @@ -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) @@ -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, @@ -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}') diff --git a/src/librer.py b/src/librer.py index d16f668..9087c7a 100755 --- a/src/librer.py +++ b/src/librer.py @@ -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) ####################################################################### @@ -2259,12 +2261,14 @@ 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() @@ -2272,16 +2276,17 @@ def record_import_wii(self): 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 @@ -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 @@ -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: @@ -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) @@ -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) @@ -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] @@ -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') @@ -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]) @@ -3721,7 +3730,7 @@ 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) @@ -3729,7 +3738,7 @@ def column_sort(self, tree): 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): @@ -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