Saving data over sessions in a Python plugin #2377
Replies: 2 comments
-
I am not sure why this would be an issue regardless if the plugin is an executable or pure Python. What type of error are you getting? Flow Launcher allows plugins to read and write to their own settings file. It is sent to your plugin with Example:
Take note of the settings dictionary sent to your plugin. You can read your currently stored settings in this dict. You can write to your Example:
Keep in mind everything here is stored in plaintext. P.S. Keep in mind that some Python compilers use temp directories to unzip your "executable" to when run and storing any information in this temp directory is lost. https://nuitka.net/doc/user-manual.html#onefile-finding-files |
Beta Was this translation helpful? Give feedback.
-
The error I'm getting is TOKEN_FILE = os.path.join(os.path.dirname(sys.argv[0]), 'token.json')
def get_credentials(config):
creds = None
# The file token.json stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
if os.path.exists(TOKEN_FILE):
with open(TOKEN_FILE, 'r') as token:
token = json.load(token)
creds = Credentials.from_authorized_user_info(token, SCOPES)
# creds = Credentials.from_authorized_user_file(TOKEN_FILE, SCOPES)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
flow = InstalledAppFlow.from_client_config(config, SCOPES)
creds = flow.run_local_server(port=0)
# Save the credentials for the next run
with open(TOKEN_FILE, 'w') as token:
token.write(creds.to_json())
return creds The code does actually write the token to Thanks for the code example, if I can't get it to work with reading and writing the file I will try this. If I understand correctly, my function would then change like this right: def query(self, query):
# Some code here
return results
# CHANGED TO
def query(self, query):
# Some code here
return {"results": results, "SettingsChange": {"foo": "bar"}} Thanks in advance :) edit: I am buliding my code with nuitka by the way, so I changed my file paths based on the example you sent, but it resulted in the same error. |
Beta Was this translation helpful? Give feedback.
-
Currently I'm working on building my Python plugin as an executable, so it can be used by anyone independent of local Python installations and such. While making this transition, I found out that reading and writing to the filesystem can cause problems when running the plugin as an executable. It works perfectly fine when running the plugin as Python, but not as an executable.
While this is a problem on its own, a nicer solution would be to store the data I need to read and write within Flowlauncher in some way.
The data that I need to store are authentication tokens from Google. If I don't store these, you would need to re-authenticate in your browser each time you type the command for the plugin, so storing these tokens in some way would be preferable.
Is there any way to do this in a nice way? And if not, is there any reason for why reading/writing to the filesystem does not work when making an executable out of my Python plugin?
Beta Was this translation helpful? Give feedback.
All reactions