A simple X.Org parser

  Add it to your Download Basket!

 Add it to your Watch List!


Rate it!

What's new in XorgParser

  • xutils.py:
  • make isDriverInSection() return True only if all of the specified sections contain the driver. This prevents isDriverEnabled() from returning false positives.
  • 1-test.py:
Read full changelog
send us
an update
GPL (GNU General Public License) 
Alberto Milone
ROOT \ System \ System Administration
XorgParser is a simple, transparent and easy to extend X.Org parser. It was written with the following aims in mind:

* Simple API.
* Easy to extend.
* Dependent only on Python (no external libraries)

X-Kit was designed to be distribution agnostic so as to provide a standard way to manipulate the content of the xorg.conf from different applications.


The Parser class in xorgparser.py is the core of the project since it includes all the main methods for the manipulation and validation of the xorg.conf. The XUtils subclass in xutils.py contains some not fundamental but still quite useful methods mainly focussed on dealing with the several relationships between the different sections of the xorg.conf.

The most important attribute of the Parser class is globaldict i.e. a dictionary which contains a structured representation of the content of the xorg.conf. The section types are its keys (see self.sections). "SubSection" is treated as a special section type.

As regards normal sections, the value assigned to each key of globaldict is another dictionary which has the position of each section as a key.

self.globaldict = {
                   'Device': {
                              0: [option1, option2, etc.],
                              1: [...], etc.
                   'Screen': {
                              0: [option1, option2, etc.],
                              1: [...], etc.},

For example self.globaldict['Device'][0] corresponds to a list of the options available in the 1st "Device" section of the xorg.conf.

SubSections are treated differently from sections:

self.globaldict = {
                   'Device': {
                              0: [option1, option2, etc.],
                              1: [...], etc.
                   'Screen': {
                              0: [option1, option2, etc.],
                              1: [...], etc.
                   'SubSection': {
                                  0: {
                                      'section': 'Screen',
                                      'identifier': 'Display',
                                      'position': 0,
                                      'options': [option1, option2, etc.]
                                  1: {...}, etc.

In this case they keys of self.globaldict['Device'] (i.e. 0, 1, etc.)  represent the position of the "Display" SubSection inside the "Screen" section. The following are the keys of self.globaldict['Device'][0], [1], etc.:

- section    = the section in which the SubSection is located (e.g. "Screen")
- position   = the position of the section (e.g. "Screen") in the xorg.conf
               e.g. position would be 0 if the SubSection was located in the
               1st "Screen" section of the xorg.conf (whose options are
               stored in "self.globaldict['Screen'][0]")
- identifier = the name of the SubSection (e.g. "Display")
- options    = a list with the options available in the SubSection

Another important concept to consider is that each line in each section is considered as an option. No more than one instance of the same option should be found in the same section (e.g. Driver "nv" and Driver "vesa" cannot  cohexist in the same Device section). References (e.g. Screen "Default Screen" in the Device section), however, are treated as a special kind of option and more than one reference of the same kind can be found in the same section (e.g. Screen "Screen 1" and Screen "Screen 2" in the same ServerLayout section)

IMPORTANT NOTE ON CASE SENSITIVE SECTION NAMES: the parser will accept sections in either lowercase and uppercase when reading a configuration file. The same is not true when the methods are called and the name of the section is passed as a parameter, as in such case the names of the sections must be exactly as in "self.sections" i.e. the 1st letter of each word which is part of the name must be in uppercase:

e.g. invalid: "screen", "serverlayout", "Serverlayout"
     valid:   "Screen", "ServerLayout"

If you don't respect this rule, a KeyError will be raised.

For further information you can have a look at the documentation by typing:

import XKit

How to install X-Kit

If you use Ubuntu you should be able to find the source package on Launchpad (see the "Development" section of this file) and in the Ubuntu repository (starting from Ubuntu 8.10).

The easiest way to install it is by typing the following command:

    # ./setup.py install

    (as root).

Last updated on April 20th, 2010


#X.Org parser #xorg parser #X.Org #xorg #parser #Python

Add your review!