#-*- codding:UTF-8 -*- #!/usr/bin/env python import os, sys, json from utils import load_config class PortageConfig(): def __init__(self): self.Config = load_config() self.TargetParse =['USE', 'USE_EXPAN', 'VIDEO_CARDS', 'ACCEPT_CHOSTS', 'ACCEPT_LICENSE','CCACHE_DIR', 'CCACHE_SIZE', 'EMERGE_DEFAULT_OPTS', 'CFLAGS', 'CXXFLAGS', 'MAKEOPTS'] self.MakeConfig={} def getLines(self, filename): with open (filename, 'r') as f: lines = f.read().split("\n") return lines def parseMakeConf(self): StateBox = 'Null' Lines = self.getlines(self.Config.Portage['make.conf']) for line in lines: if not line.startswith('#'): if StateBox is 'Null' and not line.endswith('"'): StateBox = line.split('=')[0] MakeConfig[StateBox] = line.split('=')] = [] for i in line.split('=')] = line.split(" ") MakeConfig[StateBox].append(i) elif StateBox is not 'Null' and not line.endswith('"') StateBox ='Null' for i in line.split('=')] = line.split(" ") MakeConfig[StateBox].append(i) elif StateBox is 'Null' and line.endswith('"'): MakeConfig[StateBox] = line.split(" ") print(MakeConfig) def parsePackageUse(self): Lines = self.getlines(self.Config.Portage['package.use']) def parsePackageMasks(self): Lines = self.getlines(self.Config.Portage['package.mask']) def def parsePackageKeywords(self): Lines = self.getlines(self.Config.Portage['package.keywords']) if __name__ == '__main__': test = TestConfig() test.parseMakeConfig()