コード例 #1
0
def addConfig(attr, value, git_local = False, \
    git_global = False, git_system = False, directory = None):
    if isEmpty(attr):
        print("add attribute is empty!")
        return None
    cur_directory = os.getcwd()
    if not isEmpty(directory):
        os.chdir(directory)
    if isEmpty(value):
        value = ""
        print("add attribute:%s value is empty!" % attr)
    data = ConfigData()
    if git_system:
        result = execSetConfig("--system", attr, value, "--add")
        for value in result.splitlines():
            data.setSystemConfig(attr, value.strip())
    if git_global:
        result = execSetConfig("--global", attr, value, "--add")
        for value in result.splitlines():
            data.setGlobalConfig(attr, value.strip())
    if git_local:
        result = execSetConfig("--local", attr, value, "--add")
        for value in result.splitlines():
            data.setLocalConfig(attr, value.strip())
    if not git_local and not git_global and not git_system:
        result = execSetConfig("", attr, value, "--add")
        for value in result.splitlines():
            data.setLocalConfig(attr, value.strip())
    os.chdir(cur_directory)

    return data
コード例 #2
0
def getConfig(attr, get_all = False, git_local = False, \
    git_global = False, git_system = False, directory = None):
    if isEmpty(attr):
        print("get attribute is empty!")
        return None
    cur_directory = os.getcwd()
    if not isEmpty(directory):
        os.chdir(directory)
    get_mode = "--get"
    if get_all:
        get_mode = "--get-all"
    data = ConfigData()
    if git_system:
        result = execGetConfig("--system", attr, get_mode)
        for value in result.splitlines():
            data.setSystemConfig(attr, value.strip())
    if git_global:
        result = execGetConfig("--global", attr, get_mode)
        for value in result.splitlines():
            data.setGlobalConfig(attr, value.strip())
    if git_local:
        result = execGetConfig("--local", attr, get_mode)
        for value in result.splitlines():
            data.setLocalConfig(attr, value.strip())
    if not git_local and not git_global and not git_system:
        result = execGetConfig("", attr, get_mode)
        for value in result.splitlines():
            data.setLocalConfig(attr, value.strip())
    os.chdir(cur_directory)

    return data
コード例 #3
0
def loadConfig(git_local = False, git_global = False, \
    git_system = False, directory = None):
    cur_directory = os.getcwd()
    if not isEmpty(directory):
        os.chdir(directory)
    data = ConfigData()
    if not git_local and not git_global and not git_system:
        git_local = True
        git_global = True
        git_system = True
    if git_system:
        result = execLoadConfig("--system")
        for line in result.splitlines():
            key_value_pair = line.strip().split("=")
            if len(key_value_pair) == 1:
                data.setSystemConfig(key_value_pair[0], "")
            elif len(key_value_pair) == 2:
                data.setSystemConfig(key_value_pair[0].strip(),
                                     key_value_pair[1].strip())
            elif len(key_value_pair) > 2:
                raise Exception(
                    "git config --system %s not a key value pair!" % line)
    if git_global:
        result = execLoadConfig("--global")
        for line in result.splitlines():
            key_value_pair = line.strip().split("=")
            if len(key_value_pair) == 1:
                data.setGlobalConfig(key_value_pair[0], "")
            elif len(key_value_pair) == 2:
                data.setGlobalConfig(key_value_pair[0], key_value_pair[1])
            elif len(key_value_pair) > 2:
                raise Exception(
                    "git config --global %s not a key value pair!" % line)
    if git_local:
        result = execLoadConfig("--local")
        for line in result.splitlines():
            key_value_pair = line.strip().split("=")
            if len(key_value_pair) == 1:
                data.setLocalConfig(key_value_pair[0], "")
            elif len(key_value_pair) == 2:
                data.setLocalConfig(key_value_pair[0], key_value_pair[1])
            elif len(key_value_pair) > 2:
                raise Exception("git config --local %s not a key value pair!" %
                                line)
    os.chdir(cur_directory)

    return data