# Contributors:
# - S-Core Co., Ltd
+import re
+import logging
from lxml import etree
from tic.utils.error import TICError
from tic.utils.rpmmisc import archPolicies, default_arch
-import logging
-import re
+from tic.config import configmgr
-meta_prefix = 'building-blocks'
-meta_prefix_root = 'building-blocks-root-'
-meta_prefix_sub1 = 'building-blocks-sub1-'
-meta_pattern = re.compile(''.join(['^', meta_prefix, '-(?P<meta>root|sub1|sub2)-(?P<pkgname>.+)']), re.I)
-meta_sub1_pattern = re.compile("(?P<root>.+)-(?P<sub1>.+)")
-meta_sub2_pattern = re.compile("(?P<root>.+)-(?P<sub1>.+)-(?P<sub2>.+)")
+# meta pkg
+META_PREFIX = configmgr.regularexp['meta_prefix']
+META_PREFIX_ROOT = configmgr.regularexp['meta_prefix_root']
+META_PREFIX_SUB1 = configmgr.regularexp['meta_prefix_sub1']
+META_PATTERN = re.compile(''.join(['^', META_PREFIX, configmgr.regularexp['meta_pattern']]), re.I)
+META_SUB1_PATTERN = re.compile(configmgr.regularexp['meta_sub1_pattern'])
+META_SUB2_PATTERN = re.compile(configmgr.regularexp['meta_sub2_pattern'])
+# profile pkg
+PROFILE_PATTERN = re.compile(configmgr.regularexp['profile_pattern'])
class RepodataParser(object):
pkg_info['selfChecked'] = False # for web-ui tree
# Parsing meta-pkg using meta naming rule
- meta_match = meta_pattern.search(pkg_info['name'])
+ meta_match = META_PATTERN.search(pkg_info['name'])
if meta_match is not None:
#print(meta_match.group(0), ', ', meta_match.group('meta'), ', ', meta_match.group('pkgname'))
if meta_match.group('meta') == 'root':
meta_info['root'].append([pkg_info['name']])
pkg_info['meta'] = 'root'
elif meta_match.group('meta') == 'sub1':
- sub1_match = meta_sub1_pattern.search(meta_match.group('pkgname'))
+ sub1_match = META_SUB1_PATTERN.search(meta_match.group('pkgname'))
meta_info['sub1'].append([pkg_info['name'],
- ''.join([meta_prefix_root, sub1_match.group('root')])])
+ ''.join([META_PREFIX_ROOT, sub1_match.group('root')])])
pkg_info['meta'] = 'sub1'
elif meta_match.group('meta') == 'sub2':
- sub2_match = meta_sub2_pattern.search(meta_match.group('pkgname'))
+ sub2_match = META_SUB2_PATTERN.search(meta_match.group('pkgname'))
meta_info['sub2'].append([pkg_info['name'],
- ''.join([meta_prefix_root, sub2_match.group('root')]),
- ''.join([meta_prefix_sub1, sub2_match.group('root'),'-', sub2_match.group('sub1')])])
+ ''.join([META_PREFIX_ROOT, sub2_match.group('root')]),
+ ''.join([META_PREFIX_SUB1, sub2_match.group('root'),'-', sub2_match.group('sub1')])])
pkg_info['meta'] = 'sub2'
-
+
+ # check profile pkg
+ profile_match = PROFILE_PATTERN.search(pkg_info['name']);
+ if profile_match and profile_match.group('profile'):
+ pkg_info['profile'] = profile_match.group('profile')
+ else:
+ pkg_info['profile'] = None
ver_tag = pkg.find(tag_dic['version'])
pkg_info['version'] = {'epoch':ver_tag.attrib['epoch'],
return ret_list
def parse(self):
+ logger = logging.getLogger(__name__)
if not self.repodata_list:
return None
tree = etree.parse(repodata['primary'])
xml_list.append(tree.getroot())
except etree.XMLSyntaxError as e:
- raise TICError('primary.xml syntax error. %s', e)
+ logger.info(e)
+ raise TICError(configmgr.message['xml_parse_error'] % ('primary', repodata['baseurl']))
tag_dic = self._get_tagname(xml_list[0])