[TIC-CORE] support caching for analysis data
[archive/20170607/tools/tic-core.git] / tic / utils / rpmmisc.py
1 #!/usr/bin/python
2 # Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
3 #
4 # Contact: 
5 # @author Chulwoo Shin <cw1.shin@samsung.com>
6
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
10 #
11 # http://www.apache.org/licenses/LICENSE-2.0
12 #
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.
18 #
19 # Contributors:
20 # - S-Core Co., Ltd
21
22 import rpm
23
24 default_arch = ('noarch', 'src')
25
26 archPolicies = {
27     "x86_64":       ("x86_64", "i686", "i586", "i486", "i386"),
28     "i686":         ("i686", "i586", "i486", "i386"),
29     "i586":         ("i586", "i486", "i386"),
30     "ia64":         ("ia64", "i686", "i586", "i486", "i386"),
31     "aarch64":      ("aarch64"),
32     "armv7tnhl":    ("armv7tnhl", "armv7thl", "armv7nhl", "armv7hl"),
33     "armv7thl":     ("armv7thl", "armv7hl"),
34     "armv7nhl":     ("armv7nhl", "armv7hl"),
35     "armv7hl":      ("armv7hl"),
36     "armv7l":       ("armv7l", "armv6l", "armv5tejl", "armv5tel", "armv5l", "armv4tl", "armv4l", "armv3l"),
37     "armv6l":       ("armv6l", "armv5tejl", "armv5tel", "armv5l", "armv4tl", "armv4l", "armv3l"),
38     "armv5tejl":    ("armv5tejl", "armv5tel", "armv5l", "armv4tl", "armv4l", "armv3l"),
39     "armv5tel":     ("armv5tel", "armv5l", "armv4tl", "armv4l", "armv3l"),
40     "armv5l":       ("armv5l", "armv4tl", "armv4l", "armv3l"),
41 }
42
43 def compare_ver(ver1, ver2):
44     return rpm.labelCompare((ver1.get('epoch'), ver1.get('ver'), ver1.get('rel')), (ver2.get('epoch'), ver2.get('ver'), ver2.get('rel')))
45     
46 def compare_req_cap_ver(req, cap):
47     epoch = cap.get('epoch')
48     ver = cap.get('ver')
49     rel = cap.get('rel')
50     if not req.get('epoch'): epoch = None
51     if not req.get('rel'): rel = None
52     return rpm.labelCompare((req.get('epoch'), req.get('ver'), req.get('rel')), (epoch, ver, rel))
53
54 def meetRequireVersion(req_ver, cmp_ver):
55     cmp_ret = compare_req_cap_ver(req_ver, cmp_ver)
56     if cmp_ret == 0 and (req_ver['flags'] in ['EQ', 'GE', 'LE']):
57         return True
58     elif cmp_ret == 1 and (req_ver['flags'] in ['LT', 'LE']):
59         return True
60     elif cmp_ret == -1 and (req_ver['flags'] in ['GT', 'GE']):
61         return True
62     return False