Friday, March 10, 2017

Pull SAP Client Options from saplogin.ini

Here is some code that allows you to pull the client options from the saplogin.ini file. This in itself isn't really all that useful but I'll show you a session selection module in a future post and in that I use this "getlogon" module to allow me to provide the user with a list of SAP client options such as PRD, QAS, or DEV.


def getsaplogonoptions():
    import ConfigParser
    Config = ConfigParser.ConfigParser()
    Config.read("C:\\SAP\saplogon.ini")

    def ConfigSectionMap(section):
        dict1 = {}
        options = Config.options(section)
        for option in options:
            try:
                dict1[option] = Config.get(section, option)
                if dict1[option] == -1:
                    DebugPrint("skip: %s" % option)
            except:
                print("exception on %s!" % option)
                dict1[option] = None
        return dict1

    loginlist=[]
    j=0
    Descriptions = ConfigSectionMap("Description")
    for i in Descriptions:
        try:
            tmp=''
            name=str('item' + str(j))
            j+=1
            loginlist.append(Descriptions[name])
        except:
            j+=1
            continue
    return loginlist

Note that ConfigParser can be installed via pip install configparser. Documentation for configparser is available here.

No comments:

Post a Comment