Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrj committed Nov 19, 2023
1 parent 7e2bd68 commit c7ea51b
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 92 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
### librer
# LIBRER
A file cataloging program with extensive customization options to suit user preferences.

**The software and this document are under development and in a pre-release state.**

## Features:
The primary purpose of this software is to enable users to catalog their files, particularly on removable media like memory cards and portable drives. It allows users to add metadata, referred to here as **custom data**, and facilitates future searching through the created records. **Custom data** consists of textual information acquired through the execution of user-chosen commands or scripts. **Custom data** may include any text data customized to meet the user's requirements, restricted only by the available memory and the software accessible for data retrieval. The retrieved data is stored in a newly created database record and can be utilized for search or verification purposes.
The primary purpose of this software is to enable users to catalog their files, particularly on removable media like memory cards and portable drives. It allows user to add metadata, referred to here as **custom data**, and facilitates future searching through the created records. **Custom data** consists of textual information acquired through the execution of user-chosen commands or scripts. **Custom data** may include any text data customized to meet the user's requirements, restricted only by the available memory and the software accessible for data retrieval. The retrieved data is stored in a newly created database record and can be utilized for search or verification purposes.

## Screenshots:

Expand Down Expand Up @@ -88,7 +88,7 @@ pip install -r requirements.txt
./scripts/icons.convert.sh
./scripts/version.gen.sh
python ./src/dude.py
python3 ./src/librer.py
```

## Licensing
Expand Down
36 changes: 19 additions & 17 deletions src/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
from os.path import join as path_join
from os.path import abspath
from os.path import normpath

from platform import system as platform_system
from platform import release as platform_release
from platform import node as platform_node

from os import remove as os_remove

from fnmatch import fnmatch
Expand Down Expand Up @@ -133,23 +138,14 @@ def test_regexp(expr):
#print(i, temp_tuple)

#######################################################################
data_format_version='1.0002'
data_format_version='1.0003'

class LibrerCoreData :
label = ""
creation_time = None
rid = None #data record id
scan_path = None
data = None
quant_files = 0
quant_folders = 0
data_format_version=''

def __init__(self,label,path):
def __init__(self,label='',path=''):
self.label=label
self.scan_path = path
self.creation_time = int(1000*time())
self.rid = self.creation_time
self.rid = self.creation_time #data record id

self.data = ()
self.quant_files = 0
Expand All @@ -165,6 +161,8 @@ def __init__(self,label,path):
self.files_cde_size_extracted = 0
self.files_cde_errors_quant = 0

self.creation_os,self.creation_host = f'{platform_system()} {platform_release()}',platform_node()

def get_time(self):
return self.creation_time/1000

Expand All @@ -183,13 +181,17 @@ def __init__(self,label,path,log):
self.files_search_progress = 0

self.crc_progress_info=0
self.FILE_NAME = ''

def file_name(self):
def new_file_name(self):
return f'{self.db.rid}.dat'

def abort(self):
self.abort_action = True

def get_info(self):
return f'name: {self.db.label}\nscan path: {self.db.scan_path}\nsize: {bytes_to_str(self.db.sum_size)}\nhost: {self.db.creation_host}\nOS: {self.db.creation_os}\ncreation time: {self.db.creation_time}\nfile: {self.FILE_NAME}'

def calc_crc(self,fullpath,size):
CRC_BUFFER_SIZE=4*1024*1024
buf = bytearray(CRC_BUFFER_SIZE)
Expand Down Expand Up @@ -690,7 +692,7 @@ def find_items(self,
self.find_results_list = list(find_results)

def save(self) :
file_name=self.file_name()
file_name=self.new_file_name()
self.info_line = f'saving {file_name}'
file_path=sep.join([self.db_dir,file_name])
self.log.info('saving %s' % file_path)
Expand All @@ -702,6 +704,8 @@ def save(self) :

def load(self,db_dir,file_name):
self.log.info('loading %s' % file_name)
self.FILE_NAME = file_name

try:
full_file_path = sep.join([db_dir,file_name])
with gzip_open(full_file_path, "rb") as gzip_file:
Expand Down Expand Up @@ -937,9 +941,7 @@ def find_items_in_all_records(self,
def delete_record_by_id(self,rid):
for record in self.records:
if record.db.rid == rid:
print('found record to delete:',rid)

file_path = sep.join([self.db_dir,record.file_name()])
file_path = sep.join([self.db_dir,record.FILE_NAME])
self.log.info('deleting file:%s',file_path)
try:
os_remove(file_path)
Expand Down
101 changes: 67 additions & 34 deletions src/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,20 @@

from os import name as os_name

import tkinter as tk
from tkinter import ttk
from tkinter import Frame
from tkinter import Label
from tkinter import BooleanVar
from tkinter import DoubleVar
from tkinter import StringVar
from tkinter import scrolledtext
from tkinter import Toplevel
from tkinter import Canvas

from tkinter.ttk import Button
from tkinter.ttk import Scrollbar
from tkinter.ttk import Progressbar
from tkinter.ttk import Checkbutton
from tkinter.ttk import Entry

def set_geometry_by_parent(widget,parent):
x_offset = int(parent.winfo_rootx()+0.5*(parent.winfo_width()-widget.winfo_width()))
Expand All @@ -45,7 +56,7 @@ def __init__(self,parent,icon,bg_color,title,pre_show=None,post_close=None,min_w
self.bg_color=bg_color

self.icon = icon
self.widget = tk.Toplevel(parent,bg=self.bg_color,bd=0, relief='flat')
self.widget = Toplevel(parent,bg=self.bg_color,bd=0, relief='flat')
self.widget.withdraw()
self.widget.update()
self.widget.protocol("WM_DELETE_WINDOW", lambda : self.hide())
Expand All @@ -57,7 +68,7 @@ def __init__(self,parent,icon,bg_color,title,pre_show=None,post_close=None,min_w

self.focus=None

self.widget.iconphoto(False, self.icon)
self.widget.iconphoto(False, *icon)

self.widget.title(title)
self.widget.bind('<Escape>', lambda event : self.hide() )
Expand All @@ -70,16 +81,16 @@ def __init__(self,parent,icon,bg_color,title,pre_show=None,post_close=None,min_w
self.pre_show=pre_show
self.post_close=post_close

self.area_main = tk.Frame(self.widget,bg=self.bg_color)
self.area_main = Frame(self.widget,bg=self.bg_color)
self.area_main.pack(side='top',expand=1,fill='both')

#only grid here
self.area_main.grid_columnconfigure(0, weight=1)

self.area_buttons = tk.Frame(self.widget,bg=self.bg_color)
self.area_buttons = Frame(self.widget,bg=self.bg_color)
self.area_buttons.pack(side='bottom',expand=0,fill='x')

self.wait_var=tk.BooleanVar()
self.wait_var=BooleanVar()
self.wait_var.set(False)

self.do_command_after_show=None
Expand Down Expand Up @@ -145,7 +156,7 @@ def show(self,wait=True):

#windows re-show workaround
try:
self.widget.iconphoto(False, self.icon)
self.widget.iconphoto(False, *self.icon)
except Exception as e:
print(e)

Expand Down Expand Up @@ -188,10 +199,10 @@ class LabelDialog(GenericDialog):
def __init__(self,parent,icon,bg_color,pre_show=None,post_close=None,min_width=300,min_height=120):
super().__init__(parent,icon,bg_color,'',pre_show,post_close,min_width,min_height)

self.label = tk.Label(self.area_main, text='',justify='center',bg=self.bg_color)
self.label = Label(self.area_main, text='',justify='center',bg=self.bg_color)
self.label.grid(row=0,column=0,padx=5,pady=5)

self.cancel_button=ttk.Button(self.area_buttons, text='OK', width=14, command=super().hide )
self.cancel_button=Button(self.area_buttons, text='OK', width=14, command=super().hide )
self.cancel_button.pack(side='bottom', anchor='n',padx=5,pady=5)

self.focus=self.cancel_button
Expand All @@ -202,6 +213,28 @@ def show(self,title='',message=''):

super().show()

class LabelDialogQuestion(LabelDialog):
def __init__(self,parent,icon,bg_color,pre_show=None,post_close=None,min_width=300,min_height=200,image=''):
super().__init__(parent,icon,bg_color,pre_show,post_close,min_width,min_height)

self.cancel_button.configure(text='Cancel')
self.cancel_button.pack(side='left', anchor='n',padx=5,pady=5)

self.ok_button=Button(self.area_buttons, text='OK', width=13, command=self.ok,image=image, compound='right' )
self.ok_button.pack(side='right', anchor='n',padx=5,pady=5)

self.focus=self.cancel_button

def ok (self):
self.res_bool=True
self.wait_var.set(True)
super().hide()

def show(self,title='',message=''):
self.res_bool=False
super().show(title,message)


class ProgressDialog(GenericDialog):
def __init__(self,parent,icon,bg_color,pre_show=None,post_close=None,min_width=550,min_height=120):
super().__init__(parent,icon,bg_color,'',pre_show,post_close,min_width,min_height)
Expand All @@ -210,37 +243,37 @@ def __init__(self,parent,icon,bg_color,pre_show=None,post_close=None,min_width=5
self.prev_text={}
self.prev_image={}
for i in range(5):
self.lab[i] = tk.Label(self.area_main, text='',justify='center',bg=self.bg_color)
self.lab[i] = Label(self.area_main, text='',justify='center',bg=self.bg_color)
self.lab[i].grid(row=i+1,column=0,padx=5)
self.prev_text[i]=''
self.prev_image[i]=None

self.abort_button=ttk.Button(self.area_buttons, text='Abort', width=10,command=lambda : self.hide() )
self.abort_button=Button(self.area_buttons, text='Abort', width=10,command=lambda : self.hide() )

self.abort_button.pack(side='bottom', anchor='n',padx=5,pady=5)

(frame_0:=tk.Frame(self.area_main,bg=self.bg_color)).grid(row=0, column=0, sticky='news')
self.progr1var = tk.DoubleVar()
self.progr1=ttk.Progressbar(frame_0,orient='horizontal',length=100, mode='determinate',variable=self.progr1var)
(frame_0:=Frame(self.area_main,bg=self.bg_color)).grid(row=0, column=0, sticky='news')
self.progr1var = DoubleVar()
self.progr1=Progressbar(frame_0,orient='horizontal',length=100, mode='determinate',variable=self.progr1var)
self.progr1.grid(row=0,column=1,padx=1,pady=4,sticky='news')

self.lab_l1=tk.Label(frame_0,width=22,bg=self.bg_color)
self.lab_l1=Label(frame_0,width=22,bg=self.bg_color)
self.lab_l1.grid(row=0,column=0,padx=1,pady=4)
self.lab_l1.config(text='l1')

self.lab_r1=tk.Label(frame_0,width=22,bg=self.bg_color)
self.lab_r1=Label(frame_0,width=22,bg=self.bg_color)
self.lab_r1.grid(row=0,column=2,padx=1,pady=4)
self.lab_r1.config(text='r1')

self.progr2var = tk.DoubleVar()
self.progr2=ttk.Progressbar(frame_0,orient='horizontal',length=100, mode='determinate',variable=self.progr2var)
self.progr2var = DoubleVar()
self.progr2=Progressbar(frame_0,orient='horizontal',length=100, mode='determinate',variable=self.progr2var)
self.progr2.grid(row=1,column=1,padx=1,pady=4,sticky='news')

self.lab_l2=tk.Label(frame_0,width=22,bg=self.bg_color)
self.lab_l2=Label(frame_0,width=22,bg=self.bg_color)
self.lab_l2.grid(row=1,column=0,padx=1,pady=4)
self.lab_l2.config(text='l2')

self.lab_r2=tk.Label(frame_0,width=22,bg=self.bg_color)
self.lab_r2=Label(frame_0,width=22,bg=self.bg_color)
self.lab_r2.grid(row=1,column=2,padx=1,pady=4)
self.lab_r2.config(text='r2')

Expand Down Expand Up @@ -290,7 +323,7 @@ def __init__(self,parent,icon,bg_color,pre_show=None,post_close=None,min_width=1

self.area_main.grid_rowconfigure(0, weight=1)

self.cancel_button=ttk.Button(self.area_buttons, text='Close', width=14, command=super().hide )
self.cancel_button=Button(self.area_buttons, text='Close', width=14, command=super().hide )
self.cancel_button.pack(side='bottom', anchor='n',padx=5,pady=5)

self.focus=self.cancel_button
Expand Down Expand Up @@ -318,7 +351,7 @@ def __init__(self,parent,icon,bg_color,pre_show=None,post_close=None,min_width=8
self.cancel_button.configure(text='Cancel')
self.cancel_button.pack(side='left', anchor='n',padx=5,pady=5)

self.ok_button=ttk.Button(self.area_buttons, text='OK', width=14, command=self.ok,image=image, compound='right' )
self.ok_button=Button(self.area_buttons, text='OK', width=14, command=self.ok,image=image, compound='right' )
self.ok_button.pack(side='right', anchor='n',padx=5,pady=5)

self.focus=self.cancel_button
Expand All @@ -337,12 +370,12 @@ def __init__(self,parent,icon,bg_color,pre_show=None,post_close=None,min_width=4

self.cancel_button.configure(text='Cancel')

self.entry_val=tk.StringVar()
self.entry_val=StringVar()

self.entry = ttk.Entry(self.area_main, textvariable=self.entry_val,justify='left')
self.entry = Entry(self.area_main, textvariable=self.entry_val,justify='left')
self.entry.grid(row=2,column=0,padx=5,pady=5,sticky="wens")

self.button_ok = ttk.Button(self.area_buttons, text='OK', width=14, command=self.ok )
self.button_ok = Button(self.area_buttons, text='OK', width=14, command=self.ok )
self.button_ok.pack(side='left', anchor='n',padx=5,pady=5)

self.cancel_button.pack(side='right')
Expand Down Expand Up @@ -371,9 +404,9 @@ class CheckboxEntryDialogQuestion(EntryDialogQuestion):
def __init__(self,parent,icon,bg_color,pre_show=None,post_close=None,min_width=400,min_height=120):
super().__init__(parent,icon,bg_color,pre_show,post_close,min_width,min_height)

self.check_val=tk.BooleanVar()
self.check_val=BooleanVar()

self.check = ttk.Checkbutton(self.area_main, variable=self.check_val)
self.check = Checkbutton(self.area_main, variable=self.check_val)
self.check.grid(row=1,column=0,padx=5,pady=5,sticky="wens")
self.result2=None

Expand All @@ -392,10 +425,10 @@ class FindEntryDialog(CheckboxEntryDialogQuestion):
def __init__(self,parent,icon,bg_color,mod_cmd,prev_cmd,next_cmd,pre_show=None,post_close=None,min_width=400,min_height=120):
super().__init__(parent,icon,bg_color,pre_show,post_close,min_width,min_height)

self.button_prev = ttk.Button(self.area_buttons, text='prev (Shift+F3)', width=14, command=self.prev )
self.button_prev = Button(self.area_buttons, text='prev (Shift+F3)', width=14, command=self.prev )
self.button_prev.pack(side='left', anchor='n',padx=5,pady=5)

self.button_next = ttk.Button(self.area_buttons, text='next (F3)', width=14, command=self.next )
self.button_next = Button(self.area_buttons, text='next (F3)', width=14, command=self.next )
self.button_next.pack(side='right', anchor='n',padx=5,pady=5)

self.mod_cmd=mod_cmd
Expand Down Expand Up @@ -445,15 +478,15 @@ def show(self,title='',message='',initial='',checkbutton_text='',checkbutton_ini
except Exception as e:
print(e)

class SFrame(tk.Frame):
class SFrame(Frame):
def __init__(self, parent,bg,width=200,height=100):
super().__init__(parent,bg=bg)

self.windows = bool(os_name=='nt')

self.canvas = tk.Canvas(self, bd=0, bg=bg,highlightcolor=bg,width=width,height=height,relief='flat')
self.f = tk.Frame(self.canvas, bg=bg,takefocus=False)
self.vsb = ttk.Scrollbar(self, orient="vertical", command=self.canvas.yview)
self.canvas = Canvas(self, bd=0, bg=bg,highlightcolor=bg,width=width,height=height,relief='flat')
self.f = Frame(self.canvas, bg=bg,takefocus=False)
self.vsb = Scrollbar(self, orient="vertical", command=self.canvas.yview)
self.canvas.configure(yscrollcommand=self.vsb.set)
self.canvas.configure(highlightthickness=0,takefocus=False)

Expand Down
1 change: 0 additions & 1 deletion src/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
from psutil import Process
from signal import SIGTERM


class Executor :
def __init__(self):
self.command_list_to_execute = None
Expand Down
Loading

0 comments on commit c7ea51b

Please sign in to comment.