3

I want to create an app with Quickly but i have a question: Lots of applications create config files under ~/.config or ~/.application/config in home folder of current user and keep configs, user settings in that files. Applications use that config files for next run. I can use gsettings for app's configurations but i want to create a config text file and use it. How can i do this with ubuntu Quickly application template? I took a look to ~/myapp/myapp_lib/Builder.py and ~/myapp/myapp_lib/myappconfig.py but could not find any solution. Thanks

1 Answer 1

2

Quickly doesn't offer any helpers to set up a text config file, you'll have to do that yourself. GLib give you an easy way to get the user config directory, GLib.get_user_config_dir() and you can use ConfigParser to handle the file itself.

Something like so:

from gi.repository import GLib
import ConfigParser

[....]

    confDir =  os.path.join(GLib.get_user_config_dir(), 'myapp/')
    confFile = os.path.join(confDir + "conf.ini")
    config = ConfigParser.ConfigParser()

    if os.path.isfile(confFile):
        config.read(confFile)
        some_setting = config.get('Some Section', 'some_setting')
    else:
        if not os.path.exists(confDir):
            os.makedirs(confDir)
        config.add_section('Some Section')
        config.set('Some Section', 'some_setting', 'some_value')
        with open(confFile, 'wb') as confFile:
            config.write(confFile)
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .