1010from cryptography .hazmat .primitives import hashes
1111from cryptography .hazmat .primitives .kdf .pbkdf2 import PBKDF2HMAC
1212from kivy import Config
13- from kivy .lang import Builder
1413from kivy .properties import ObjectProperty
1514from kivy .uix .boxlayout import BoxLayout
1615from kivymd .app import MDApp
@@ -60,7 +59,6 @@ def change_screen(self, name):
6059class PyPassword (MDApp ):
6160 """Main application wrapper."""
6261 Logger .info ('Application: Building application' )
63- icon = file ('icon.ico' , 'p' )
6462
6563 def __init__ (self , ** kwargs ):
6664 super ().__init__ (** kwargs )
@@ -93,7 +91,6 @@ def build(self):
9391 # Change theme (light/dark)
9492 self .theme_cls .theme_style = 'Light'
9593 Logger .info (f'Application: Theme style set to { self .theme_cls .theme_style } ' )
96- return Builder .load_file (file ('PyPassword.kv' , 'p' ))
9794
9895 def on_start (self ):
9996 self .update_passwords ()
@@ -178,7 +175,7 @@ def add_password(self):
178175 ok_alias = self .validate_input (alias_box , 3 )
179176 ok_value = self .validate_input (value_box , 6 )
180177
181- password_alias = alias_box .text
178+ password_alias = alias_box .text . capitalize ()
182179 password_value = value_box .text
183180
184181 if ok_alias is True and ok_value is True :
@@ -228,7 +225,7 @@ def copy_password(self, password=None):
228225 if n is not None :
229226 to_decrypt = to_decrypt [0 ][0 ]
230227 if type (to_decrypt ) is bytes :
231- with open (file (Files .alpha_key ), 'rb' ) as f :
228+ with open (appdata (Files .alpha_key ), 'rb' ) as f :
232229 key = f .read ()
233230 f = Fernet (key )
234231 try :
@@ -265,7 +262,9 @@ def del_password(self, password=None):
265262 Logger .trace ('Called: del_password' )
266263
267264 if password is None :
268- password = self .root .ids .del_password_alias .text
265+ password = self .root .ids .del_password_alias .text .capitalize ()
266+
267+ self .root .ids .del_password_alias .text = ''
269268
270269 to_del = query (
271270 'SELECT `password` FROM `passwords` WHERE `name` LIKE ?;' ,
@@ -307,7 +306,6 @@ def del_password(self, password=None):
307306 text = 'That password do not exists in database'
308307 ).alert ()
309308 result_dialog .open ()
310- self .update_passwords ()
311309
312310 def del_password_confirm (self , password ):
313311 """This method is called after pressing ``Yes`` in ``del_password`` dialog."""
@@ -327,6 +325,7 @@ def del_password_confirm(self, password):
327325 ]
328326 )
329327 result_dialog .open ()
328+ self .update_passwords ()
330329
331330 # ================================
332331 # Alpha password
@@ -352,24 +351,24 @@ def change_alpha(self, preset=None):
352351 else :
353352 password_box .error = False
354353 try :
355- open (file (Files .beta_key ))
354+ open (appdata (Files .beta_key ))
356355 except FileNotFoundError :
357356 generate_salt ()
358357 finally :
359358 try :
360- open (file (Files .alpha_key ))
359+ open (appdata (Files .alpha_key ))
361360 except FileNotFoundError :
362- open (file (Files .alpha_key ), 'x' )
361+ open (appdata (Files .alpha_key ), 'x' )
363362 finally :
364- with open (file (Files .beta_key ), 'rb' ) as f :
363+ with open (appdata (Files .beta_key ), 'rb' ) as f :
365364 kdf = PBKDF2HMAC (
366365 algorithm = hashes .SHA256 (),
367366 length = 32 ,
368367 salt = f .read (),
369368 iterations = 100000 ,
370369 backend = default_backend ()
371370 )
372- with open (file (Files .alpha_key ), 'wb' ) as f :
371+ with open (appdata (Files .alpha_key ), 'wb' ) as f :
373372 key = base64 .urlsafe_b64encode (kdf .derive (password .encode ()))
374373 f .write (key )
375374 Logger .info ('Passwords: Alpha password has changed' )
@@ -562,15 +561,14 @@ def validate_input(self, instance, length):
562561if __name__ == '__main__' :
563562 kivy .require ('1.11.1' )
564563
565- Config .set ('kivy' , 'window_icon' , file ('icon.ico' , 'p' ))
566564 Config .set ('kivy' , 'desktop' , 1 )
567565 Config .set ('kivy' , 'exit_on_esc' , 0 )
568566 Config .set ('kivy' , 'pause_on_minimize' , 0 )
569- Config .set ('graphics' , 'resizable' , 0 )
567+ Config .set ('graphics' , 'resizable' , 1 )
570568
571- Config .set ('kivy' , 'log_dir' , file ( './ logs/' , 'p ' ))
572- Config .set ('kivy' , 'log_enable' , 0 )
573- Config .set ('kivy' , 'log_level' , 'debug ' )
569+ Config .set ('kivy' , 'log_dir' , appdata ( f'. { os . sep } logs{ os . sep } ' ))
570+ Config .set ('kivy' , 'log_enable' , 1 )
571+ Config .set ('kivy' , 'log_level' , 'error ' )
574572 Config .set ('kivy' , 'log_maxfiles' , 10 )
575573
576574 Config .write ()
0 commit comments