Does it seem like to you sometimes when you have a lot of free time and even if you have your hands dipped, dirty, and stuck in so many other pies (projects) that would take you naturally a lot of time to eat and finish (complete), but you still want to reach out for the next big pie (New Project). That’s me in summers and oh man, the pies are piling up. FAST and FURIOUS.
I wouldn’t dare to share my pie business to you, it’s flourishing by the way as you saw the image on the top. But you like updates and here it is.
Let’s get this post started with what new I learned this past week and its ConfigParser.
So say, you have config files, INI files like the ones below we have in activities of Sugar Labs, used as a metadata file for each activity containing all information about the same. This file is used by ASLOv3 to showcase metadata about each of the activity which helps the user get more information about the activity that they are trying to download.
[Activity] name = Browse activity_version = 156 bundle_id = org.laptop.WebActivity icon = activity-web exec = sugar-activity webactivity.WebActivity -s mime_types = image/png;image/gif;image/jpeg;text/html;text/uri-list;application/xhtml+xml;application/rss+xml;application/xml;text/css license = GPLv2+ summary = Surf the world! Here you can do research, watch educational videos, take online courses, find books, connect with friends and more. update_url = http://host.net/bundles/FooBar tags = exploration;web single_instance = no max_participants = 4 repository = https://github.com/sugarlabs/browse-activity
So needless to say these files are pretty important. Now think about having about 160 of these in total, stored on GitHub or some code sharing website, in their separate repositories and you, sir need to fix all of them. Fixing here means adding, removing, editing details in and out of them. Extracting content and using it such as authentication and such. There is no one way to find what you need to fix each file. You can use the time-proven way of the mouse and ctrl+c and ctrl+v. But good luck spending your next 2 months on the job fixing them.
You, my friend, need automation. You need Python. You need ConfigParser.
Breaking it down for you.
The configparser module in Python is used for working with configuration files. It is much similar to Windows INI files. You can use it to manage user-editable configuration files for an application. The configuration files are organized into sections, and each section can contain name-value pairs for configuration data. Config file sections are identified by looking for lines starting with [ and ending with ]. The value between the square brackets is the section name, and can contain any characters except square brackets. Options are listed one per line within a section. The line starts with the name of the option, which is separated from the value by a colon (:) or equal sign (=). Whitespace around the separator is ignored when the file is parsed.
Enjoy the docs, Read the docs – https://docs.python.org/3/library/configparser.html
How to get started? (The How)
- Also, helpful examples in Python3 – https://pymotw.com/3/configparser/index.html
- Helpful examples in Python2 – https://pymotw.com/2/ (Who uses that anyway?)
Applications (The Woah)
- A no-nonsense example of ConfigParser -https://martin-thoma.com/configuration-files-in-python/#configparser
- Something I use, https://gist.github.com/jatindhankhar/84ad2f104412ca5778dbed666042506e#file-script-py
- I liked this answer – https://stackoverflow.com/questions/8884188/how-to-read-and-write-ini-file-with-python3
Other Parsers (.. umm)
Also, sorry. Usually I put my hyperlinks with a bit of more finesse in my blogs but with a sheer number of them this time and with my undying intent of not reinventing the wheel, I put up the links of the blogs from where I learned. For you to learn. Live in the mix guys.
Updates About Week #2
- Convened the 3rd meeting for GSoC and Mentors in which we shared what we did this week and what we will do in the following the week. All updates summed up here 
- I am done with the community Bonding task, of setting up my development environment and figuring out my project.
- Started writing the next blog post. All blog updates available here  – Sugar Tracker
 – GSoC #2018
Written by Vipul Gupta – vipulgupta2048