dkriegner / micro-flakes

https://dkriegner.github.io/micro-flakes/
GNU General Public License v3.0
0 stars 0 forks source link

CACHE file is generated in the current working folder. #19

Closed dkriegner closed 10 months ago

dkriegner commented 11 months ago

I believe the CACHE file needs to be generated in one and the same place, but not in the folder where I execute the script.

ji-ze commented 11 months ago

I tried to use os.path.dirname(__file__), but it doesn't work for an exe-file. It uses the path: .../AppData/local/... After restarting the script, CACHE is created new.

ji-ze commented 11 months ago

Is it a good idea if the script stores the cache file to C:/Users/{username}/AppData/Local/{appname}?

ji-ze commented 11 months ago

It works!!!

import os
import sys

# Get the path of the executable file
exe_path = sys.executable
print("The path of the executable file is:", exe_path)

# Get the directory name from the path
exe_dir = os.path.dirname(exe_path)
print("The directory of the executable file is:", exe_dir)
dkriegner commented 11 months ago

Two problems I see:

1) I believe this only works in windows and potentially only when using pyinstaller. In linux I get

$ python GUI/Test.py 
The path of the executable file is: /usr/bin/python
The directory of the executable file is: /usr/bin
Press a key!

And /usr/bin is certainly not the directly the CACHE should be placed in. I would say C:/Users/{username}/AppData/Local/{appname} sounds good for Windows. In 2) The command line app still uses the executation directory to store the CACHE

Maybe one could use this package to simplify your life: https://github.com/platformdirs/platformdirs

It would work on all platforms like this:

import platformdirs
platformdirs.user_config_dir("micro-flakes")
dkriegner commented 11 months ago

Also I believe the CACHE file should likely be compatible with the configparser package. this allows to specify fallback values and make type conversion more straight-forwardly

ji-ze commented 10 months ago

I integrated the configparser to the code.