def getProperty(buffers, option): patt = re.compile("^ *" + option + " *:(.*)") for i in buffers: m = patt.match(i) if utilities.checkMatched(m): return m.group(1).strip() return ""
def getProperties(buffers): patt = re.compile(r"^ *(.*?):.*") returnme = {} for i in buffers: m = patt.match(i) if utilities.checkMatched(m): returnme[m.group(1)] = getProperty(buffers, m.group(1)) return returnme
def cleanComments(buffers): patt = re.compile("^ *#.*") returnme = [] for i in buffers: m = patt.match(i) if not utilities.checkMatched(m): returnme.append(i) return returnme
def cleanEmptyLines(buffers): patt = re.compile("^ *$") returnme = [] for i in buffers: m = patt.match(i) if not utilities.checkMatched(m): returnme.append(i) return returnme
def getOptions(buffers): patt = re.compile("^ *Option *.*") returnme = [] for i in buffers: m = patt.match(i) if utilities.checkMatched(m): returnme.append(i.split()[1].strip()) return returnme
def getMultipleValues(buffers): returnme = [] patt = re.compile("^ *(.*)") m = patt.match(buffers.strip()) if utilities.checkMatched(m): for i in m.group(1).split(): si = i.strip() returnme.append(si) return returnme
def _varEditor(self, line, lists): patt = re.compile("^.*? *([A-Za-z_-]*?)=.*$") m = patt.match(line) if utilities.checkMatched(m): for i in lists.keys(): if m.group(1) == i: bak = copy.copy(lists[i]) lists[i] = None return [True, "export " + i + "=\"" + bak + "\"\n"] patt = re.compile("^ *#.*$") m = patt.match(line) if utilities.checkMatched(m): return [True, line] patt = re.compile("^ *$") m = patt.match(line) if utilities.checkMatched(m): return [True, line] return [False, ""]
def _varEditor(self, line, lists, export_str="export "): patt = re.compile("^.*? *([A-Za-z_-]*?)=.*$") m = patt.match(line) if utilities.checkMatched(m): for i in lists.keys(): if m.group(1) == i: bak = copy.copy(lists[i]) lists[i] = None return [True, export_str + i + "=\"" + bak + "\"\n"] patt = re.compile("^ *#.*$") m = patt.match(line) if utilities.checkMatched(m): return [True, line] patt = re.compile("^ *$") m = patt.match(line) if utilities.checkMatched(m): return [True, line] return [False, ""]
def getChoices(buffers): returnme = [] patt = re.compile("^ *" + choice + " *: *(.*)") m = patt.match(buffers.strip()) if utilities.checkMatched(m): for i in m.group(1).split(","): si = i.strip() returnme.append(si) else: return None return returnme
def getSFSInstSize(files): # Not optimal, but it works # Sample line: # drwxr-xr-x root/root 377 2012-04-25 10:04 squashfs-root # ^^^ # Size in bytes patt = re.compile("^ *[dlspcb-][rwx-][rwx-][rwx-][rwx-][rwx-][rwx-][rwx-][rwx-][rwx-] *[A-Za-z0-9]*/[A-Za-z0-9]* *([0-9]*).*") output = os.popen("unsquashfs -lls " + files) totsize = 0 for line in output: m = patt.match(line) if utilities.checkMatched(m): totsize = totsize + int(m.group(1)) return totsize
def getSFSInstSize(files): # Not optimal, but it works # Sample line: # drwxr-xr-x root/root 377 2012-04-25 10:04 squashfs-root # ^^^ # Size in bytes patt = re.compile( "^ *[dlspcb-][rwx-][rwx-][rwx-][rwx-][rwx-][rwx-][rwx-][rwx-][rwx-] *[A-Za-z0-9]*/[A-Za-z0-9]* *([0-9]*).*" ) output = os.popen("unsquashfs -lls " + files) totsize = 0 for line in output: m = patt.match(line) if utilities.checkMatched(m): totsize = totsize + int(m.group(1)) return totsize
def getLinesWithinOption(buffers, option): patt = re.compile("^ *Option *" + option + ".*") patte = re.compile("^ *EndOption *.*") returnme = [] x = 0 for i in buffers: m = patt.match(i) if utilities.checkMatched(m): if x == 1: break x = 1 patt = patte else: if x == 1: returnme.append(i) return returnme
def checkMatched(m): return utilities.checkMatched(m)