2 # Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
5 # @author Chulwoo Shin <cw1.shin@samsung.com>
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
24 def analyze_dependency(pkg_group):
27 logger = logging.getLogger(__name__)
28 if pkg_list[pkg_id].get('dependency') is not None:
29 return pkg_list[pkg_id].get('dependency')
32 visited[pkg_id] = number[0]
33 min_num[pkg_id] = number[0]
36 dep_set = set([pkg_list[pkg_id]['name']])
38 if pkg_list[pkg_id].get('requires'):
39 for req in pkg_list[pkg_id].get('requires'):
40 req_id = req.get('id')
41 if req_id is not None:
42 if scc_list[req_id] > 0:
43 dep_set.update(pkg_list[req_id].get('dependency'))
46 if visited[req_id] == 0:
47 dep_set.update(dep_dfs(req_id))
49 min_num[pkg_id] = min(min_num[pkg_id], min_num[req_id])
51 #TODO: package does not exist
52 #logger.warning('%s does not exist in repo', req['name'])
55 if min_num[pkg_id] == visited[pkg_id]:
56 # scc (string connected components)
57 make_scc(pkg_id, list(dep_set))
61 def make_scc(pkg_id, dep_list):
67 scc_list[p_id] = scc_num[0]
68 pkg_list[p_id]['dependency'] = dep_list
73 for pkg_id in range(len(pkg_list)):
74 if visited[pkg_id] == 0:
77 #TODO: Exception handling
81 # package install-dependency analysis
82 pkg_list = pkg_group.get('pkg_list')
85 visited = [0]*len(pkg_list)
86 min_num = [0]*len(pkg_list)
87 scc_list = [0]*len(pkg_list)