@@ -11,26 +11,15 @@ class Files:
11
11
sqlite = 'Passwords.db'
12
12
13
13
14
- def file (filename : str , file_type = 'u' ):
14
+ def appdata (filename : str ):
15
15
"""
16
- Add absolute path to file name.
17
- Linking to user data in ~/AppData/Local/PyPassword or
18
- program data directory next to ``.exe`` file.
16
+ Linking to user data in ~/AppData/Local/PyPassword/.
19
17
:param filename: File to access name.
20
- :param file_type: Is file program or user related.
21
18
:return: Absolute path to file with specified name.
22
19
"""
23
- Logger .trace (f'Files: Accessing { filename } file ({ file_type } type)' )
24
-
25
- # Program files
26
- if file_type == 'p' :
27
- return os .path .join (os .path .dirname (__file__ ), f'../PyPassword_data/{ filename } ' )
28
- # User files
29
- elif file_type == 'u' :
30
- return os .path .join (os .path .dirname (__file__ ), f'{ os .getenv ("LOCALAPPDATA" )} /PyPassword/{ filename } ' )
31
- else :
32
- Logger .critical (f'Files: Tried to access file of unknown type' )
33
- raise NameError ('That kind of files does not exist' )
20
+ Logger .trace (f'Files: Accessing { filename } file' )
21
+ return os .path .join (os .path .dirname (__file__ ),
22
+ f'{ os .getenv ("LOCALAPPDATA" )} { os .sep } PyPassword{ os .sep } { filename } ' )
34
23
35
24
36
25
def generate_appdata ():
@@ -43,13 +32,13 @@ def generate_salt(preset=None):
43
32
"""Generates salt - Beta.key file."""
44
33
try :
45
34
generate_appdata ()
46
- open (file (Files .beta_key ), 'x' )
35
+ open (appdata (Files .beta_key ), 'x' )
47
36
except FileExistsError :
48
37
pass
49
38
else :
50
39
Logger .info (f'Structure: { Files .beta_key } file not found, creating it.' )
51
40
finally :
52
41
custom_salt = os .urandom (16 ) if preset is None else preset
53
- with open (file (Files .beta_key ), 'wb' ) as f :
42
+ with open (appdata (Files .beta_key ), 'wb' ) as f :
54
43
f .write (custom_salt )
55
44
Logger .info ('Structure: Beta password changed.' )
0 commit comments