Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Disclosure: I write very little code targeted at non-technical endusers, in fact most my code is for my own use. These facts strongly influence my config file solution.

If find the need for a config file (I tend to like command line options better) 95% of the time I use python code and import.

The benefits are many; zero work required, known syntax, powerful syntax, arbitrarily complex, no parsing required, nice traceback/errors with screwed up syntax.

    #file config.py
    
    debug = True
    
    directories_to_backup = [
    #   path                  exclude these subdirs
       ("/media/programming", ("log_files","temp_files")),
       ("/media/documents",   ("archive",)),
    ]
    
    # or, if you relish verbosity
    directory_info = dict
    directories_to_backup = [
       directory_info(path="/media/programming", exclude=("log_files","temp_files")),
       directory_info(path="/media/documents", exclude=("archive",)),
       ]
    
    # the options are as endless as your knowledge of Python

Usage

    import config
    
    for path, excludes in config.directories_to_backup:
      garbleblaster(path, excludes)


Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: