Gentoo Archives: gentoo-catalyst

From: Matt Turner <mattst88@g.o>
To: gentoo-catalyst@l.g.o
Cc: Matt Turner <mattst88@g.o>
Subject: [gentoo-catalyst] [PATCH 3/4] catalyst: Remove fallback make.conf parsing code
Date: Sun, 24 Jan 2021 15:07:31
Message-Id: 20210124150722.760520-3-mattst88@gentoo.org
In Reply to: [gentoo-catalyst] [PATCH 1/4] catalyst: Remove unused import by Matt Turner
1 Signed-off-by: Matt Turner <mattst88@g.o>
2 ---
3 catalyst/support.py | 42 +++---------------------------------------
4 1 file changed, 3 insertions(+), 39 deletions(-)
5
6 diff --git a/catalyst/support.py b/catalyst/support.py
7 index f3a865a7..fa652987 100644
8 --- a/catalyst/support.py
9 +++ b/catalyst/support.py
10 @@ -2,7 +2,6 @@
11 import glob
12 import sys
13 import os
14 -import re
15 import shutil
16 import time
17 from pathlib import Path
18 @@ -12,6 +11,8 @@ import libmount
19
20 from portage.repository.config import RepoConfig
21
22 +from snakeoil.bash import read_bash_dict
23 +
24 from catalyst import log
25
26 BASH_BINARY = "/bin/bash"
27 @@ -135,47 +136,10 @@ defined are not preserved. In other words, "foo", "bar", "oni" ordering is prese
28 print_traceback=True)
29
30
31 -def parse_makeconf(mylines):
32 - mymakeconf = {}
33 - pos = 0
34 - pat = re.compile("([0-9a-zA-Z_]*)=(.*)")
35 - while pos < len(mylines):
36 - if len(mylines[pos]) <= 1:
37 - # skip blanks
38 - pos += 1
39 - continue
40 - if mylines[pos][0] in ["#", " ", "\t"]:
41 - # skip indented lines, comments
42 - pos += 1
43 - continue
44 - else:
45 - myline = mylines[pos]
46 - mobj = pat.match(myline)
47 - pos += 1
48 - if mobj.group(2):
49 - clean_string = re.sub(r"\"", r"", mobj.group(2))
50 - mymakeconf[mobj.group(1)] = clean_string
51 - return mymakeconf
52 -
53 -
54 def read_makeconf(mymakeconffile):
55 if os.path.exists(mymakeconffile):
56 try:
57 - try:
58 - import snakeoil.bash # import snakeoil.fileutils
59 - return snakeoil.bash.read_bash_dict(mymakeconffile, sourcing_command="source")
60 - except ImportError:
61 - try:
62 - import portage.util
63 - return portage.util.getconfig(mymakeconffile, tolerant=1, allow_sourcing=True)
64 - except Exception:
65 - try:
66 - import portage_util
67 - return portage_util.getconfig(mymakeconffile, tolerant=1, allow_sourcing=True)
68 - except ImportError:
69 - with open(mymakeconffile, "r") as myf:
70 - mylines = myf.readlines()
71 - return parse_makeconf(mylines)
72 + return read_bash_dict(mymakeconffile, sourcing_command="source")
73 except Exception:
74 raise CatalystError("Could not parse make.conf file " +
75 mymakeconffile, print_traceback=True)
76 --
77 2.26.2