import os from izzylib.config import JsonConfig from izzylib.misc import get_current_user_info from izzylib.object_base import ObjectBase from izzylib.path import Path scriptpath = Path(__file__).resolve().parent def get_config(paths): cfg = JsonConfig(paths.config, name = paths.profile.name, description = '', dbtype = 'sqlite', dbhost = None, dbport = None, dbname = paths.database, dbuser = get_current_user_info().name, dbpass = None ) try: cfg.load() except FileNotFoundError: cfg.save() return cfg def get_paths(profile='DEFAULT'): home = Path(os.environ.get('HOME', '~')) data = Path(os.environ.get('XDG_CONFIG_HOME', home.join('.config', 'barkshark', 'web'))) profilepath = data.join(profile or 'DEFAULT') paths = ObjectBase( readonly_props = True, # misc paths downloads = home.join('Downloads'), data = data, script = scriptpath, # browser paths localweb = scriptpath.join('localweb'), resources = scriptpath.join('resources'), js = scriptpath.join('resources/ext_js'), # data paths profile = profilepath, avatars = profilepath.join('cache/avatar'), backup = profilepath.join('backup'), cache = profilepath.join('cache'), config = profilepath.join('config.json'), cookies = profilepath.join('cookies.sqlite3'), database = profilepath.join('database.sqlite3'), emojis = profilepath.join('cache/emoji'), extensions = profilepath.join('extensions'), favicon = profilepath.join('storage/favicon'), storage = profilepath.join('storage'), themes = profilepath.join('themes'), userscripts = profilepath.join('userscripts') ) for path in paths.values(): if not path.suffix and not path.exists(): logging.verbose('Create dir:', path) path.mkdir() return paths