Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def set_conf(section, name, value):
CONF.set(section, name, value)
try:
res = self.dbx.users_get_space_usage()
except dropbox.exceptions.ApiError as err:
logging.debug("Failed to get space usage: %s", err)
return False
# convert from dropbox.users.SpaceUsage to SpaceUsage with nice string
# representation
res.__class__ = SpaceUsage
if res.allocation.is_team():
CONF.set("account", "usage_type", "team")
elif res.allocation.is_individual():
CONF.set("account", "usage_type", "individual")
CONF.set("account", "usage", str(res))
return res
except dropbox.exceptions.DropboxException as exc:
raise to_maestral_error(exc)
if res.account_type.is_basic():
account_type = 'basic'
elif res.account_type.is_business():
account_type = 'business'
elif res.account_type.is_pro():
account_type = 'pro'
else:
account_type = ''
CONF.set("account", "account_id", res.account_id)
CONF.set("account", "email", res.email)
CONF.set("account", "display_name", res.name.display_name)
CONF.set("account", "abbreviated_name", res.name.abbreviated_name)
CONF.set("account", "type", account_type)
return res
res = self.dbx.users_get_current_account()
if not dbid:
# save our own account info to config
if res.account_type.is_basic():
account_type = "basic"
elif res.account_type.is_business():
account_type = "business"
elif res.account_type.is_pro():
account_type = "pro"
else:
account_type = ""
CONF.set("account", "account_id", res.account_id)
CONF.set("account", "email", res.email)
CONF.set("account", "display_name", res.name.display_name)
CONF.set("account", "abbreviated_name", res.name.abbreviated_name)
CONF.set("account", "type", account_type)
return res
def config_add(name: str):
"""Set up and activate a fresh Maestral configuration."""
if name in list_configs():
click.echo("Configuration '{}' already exists.".format(name))
else:
from maestral.config.main import load_config
load_config(name)
from maestral.config.main import CONF
CONF.set("main", "default_dir_name", "Dropbox ({})".format(name.capitalize()))
click.echo("Created configuration '{}'.".format(name))
def _periodic_refresh(self):
while True:
# update account info
self.get_account_info()
self.get_space_usage()
self.get_profile_pic()
# check for maestral updates
res = self.check_for_updates()
if not res["error"]:
CONF.set("app", "latest_release", res["latest_release"])
time.sleep(60*60) # 60 min
raise to_maestral_error(exc)
if res.account_type.is_basic():
account_type = 'basic'
elif res.account_type.is_business():
account_type = 'business'
elif res.account_type.is_pro():
account_type = 'pro'
else:
account_type = ''
CONF.set("account", "account_id", res.account_id)
CONF.set("account", "email", res.email)
CONF.set("account", "display_name", res.name.display_name)
CONF.set("account", "abbreviated_name", res.name.abbreviated_name)
CONF.set("account", "type", account_type)
return res
# apply created files
with ThreadPoolExecutor(max_workers=10) as executor:
success = executor.map(self._create_local_entry, all_files)
if all(success) is False:
return False
# apply deleted items
with ThreadPoolExecutor(max_workers=10) as executor:
success = executor.map(self._create_local_entry, all_deleted)
if all(success) is False:
return False
# save cursor
if save_cursor:
self.last_cursor = results[-1].cursor
CONF.set("internal", "cursor", result.cursor)
return True
def delete_creds(self):
"""Deletes auth key from system keyring."""
CONF.set("account", "account_id", "")
try:
keyring.delete_password("Maestral", self.account_id)
print(" > Credentials removed.")
except KeyringLocked:
logger.error("Could not access the user keyring to delete your authentication"
" token. Please make sure that the keyring is unlocked.")