From 19ae07d0d443ff8b777f46bcbe97119483356bfd Mon Sep 17 00:00:00 2001 From: tpearson Date: Sat, 13 Mar 2010 05:43:39 +0000 Subject: Added KDE3 version of KDE Guidance utilities git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kde-guidance@1102646 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- displayconfig/infimport.py | 297 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 297 insertions(+) create mode 100755 displayconfig/infimport.py (limited to 'displayconfig/infimport.py') diff --git a/displayconfig/infimport.py b/displayconfig/infimport.py new file mode 100755 index 0000000..f51475d --- /dev/null +++ b/displayconfig/infimport.py @@ -0,0 +1,297 @@ +#!/usr/bin/python +# +# Based on inf2mondb.py from RedHat +# +# originally by Matt Wilson +# option parsing and database comparison by Fred New +# ini parsing completely rewritten by Matt Domsch 2006 +# +# Copyright 2002 Red Hat, Inc. +# Copyright 2006 Dell, Inc. +# Copyright 2007 Sebastian Heinlein +# +# This software may be freely redistributed under the terms of the GNU +# library public license. +# +# You should have received a copy of the GNU Library Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +""" +Provides an importer for Microsoft Windows monitor descriptions + +The code can be used as a python module for or as a script to add new monitor +definitions to a monitor database. + +In code example: Read the list of monitors from an inf file. + +import infimport +monitors = infimport.get_monitors_from_inf(PATH) + +Script example: To check for monitors of an inf file that are not yet in the database. + +./infimport.py MONITORS.inf /usr/share/hwdata/MonitorsDB +""" + +import sys +import string +import re +import ConfigParser +import os + +import logging + +logging.basicConfig() +log = logging.getLogger("infimport") +#log.setLevel(logging.DEBUG) +log.setLevel(logging.INFO) + +# this is a class to deal with various file line endings and leading whitespace +# converts all \r line endings to \n. +# It also strips leading whitespace. +# NOTE: be sure to always return _something_, even if it is just "\n", or we +# break the file API. (nothing == eof) +class myFile(object): + def __init__(self, *args): + self.fd = open(*args) + + def close(self): + return self.fd.close() + + def readline(self, *args): + line = self.fd.readline(*args) + line = line.replace('\r', '\n') + line = line.replace('\n\n', '\n') + line = line.lstrip(" \t") + return line + + +# we will use this to override default option parsing in ConfigParser to handle +# Microsoft-style "INI" files. (Which do not necessarily have " = value " after +# the option name +OPTCRE = re.compile( + r'(?P