Skip to content

Commit a97be27

Browse files
xcp/repository.py: Use Accessor.openText() for ConfigParser()
Use Accessor.openText() in _getVersion() for ConfigParser().read_file(). It simplifies _getVersion() dramatically and causes Accessor.openText() to be tested with xcp.accessor.FileAccessor and xcp.accessor.HTTPAccessor. Signed-off-by: Bernhard Kaindl <bernhard.kaindl@cloud.com>
1 parent 77028d9 commit a97be27

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

xcp/repository.py

Lines changed: 4 additions & 13 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -24,11 +24,9 @@
24
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25

25

26
from hashlib import md5
26
from hashlib import md5
27-
import io
28
import os.path
27
import os.path
29
import xml.dom.minidom
28
import xml.dom.minidom
30
import configparser
29
import configparser
31-
import sys
32

30

33
import six
31
import six
34

32

@@ -180,18 +178,11 @@ def _getVersion(cls, access, category):
180

178

181
access.start()
179
access.start()
182
try:
180
try:
183-
rawtreeinfofp = access.openAddress(cls.TREEINFO_FILENAME)
184-
if sys.version_info < (3, 0) or isinstance(rawtreeinfofp, io.TextIOBase):
185-
# e.g. with FileAccessor
186-
treeinfofp = rawtreeinfofp
187-
else:
188-
# e.g. with HTTPAccessor
189-
treeinfofp = io.TextIOWrapper(rawtreeinfofp, encoding='utf-8')
190
treeinfo = configparser.ConfigParser()
181
treeinfo = configparser.ConfigParser()
191-
treeinfo.read_file(treeinfofp)
182+
192-
if treeinfofp != rawtreeinfofp:
183+
with access.openText(cls.TREEINFO_FILENAME) as fp:
193-
treeinfofp.close()
184+
treeinfo.read_file(fp)
194-
rawtreeinfofp.close()
185+
195
if treeinfo.has_section('system-v1'):
186
if treeinfo.has_section('system-v1'):
196
ver_str = treeinfo.get('system-v1', category_map[category])
187
ver_str = treeinfo.get('system-v1', category_map[category])
197
else:
188
else:

0 commit comments

Comments
 (0)