Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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)
share|improve this answer
    
Thanks! ConfigParser works for me :) –  mnrl Aug 22 '13 at 19:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.