d53b28d277481553c1e9eb209370ed1d09ebb114
[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 class Dependency(object):
25     REQUIRES='requires'
26     RECOMMENDS='recommends'
27     SUGGESTS='suggests'
28     PROVIDES='provides'
29     CONFILCTS='conflicts'
30
31
32 default_arch = ('noarch', 'src')
33
34 archPolicies = {
35     "x86_64":       ("x86_64", "i686", "i586", "i486", "i386"),
36     "i686":         ("i686", "i586", "i486", "i386"),
37     "i586":         ("i586", "i486", "i386"),
38     "ia64":         ("ia64", "i686", "i586", "i486", "i386"),
39     "aarch64":      ("aarch64"),
40     "armv7tnhl":    ("armv7tnhl", "armv7thl", "armv7nhl", "armv7hl"),
41     "armv7thl":     ("armv7thl", "armv7hl"),
42     "armv7nhl":     ("armv7nhl", "armv7hl"),
43     "armv7hl":      ("armv7hl"),
44     "armv7l":       ("armv7l", "armv6l", "armv5tejl", "armv5tel", "armv5l", "armv4tl", "armv4l", "armv3l"),
45     "armv6l":       ("armv6l", "armv5tejl", "armv5tel", "armv5l", "armv4tl", "armv4l", "armv3l"),
46     "armv5tejl":    ("armv5tejl", "armv5tel", "armv5l", "armv4tl", "armv4l", "armv3l"),
47     "armv5tel":     ("armv5tel", "armv5l", "armv4tl", "armv4l", "armv3l"),
48     "armv5l":       ("armv5l", "armv4tl", "armv4l", "armv3l"),
49 }
50
51 def compare_ver(ver1, ver2):
52     return rpm.labelCompare((ver1.get('epoch'), ver1.get('ver'), ver1.get('rel')), (ver2.get('epoch'), ver2.get('ver'), ver2.get('rel')))
53     
54 def compare_req_cap_ver(req, cap):
55     epoch = cap.get('epoch')
56     ver = cap.get('ver')
57     rel = cap.get('rel')
58     if not req.get('epoch'): epoch = None
59     if not req.get('rel'): rel = None
60     return rpm.labelCompare((req.get('epoch'), req.get('ver'), req.get('rel')), (epoch, ver, rel))
61
62 def meetRequireVersion(req_ver, cmp_ver):
63     cmp_ret = compare_req_cap_ver(req_ver, cmp_ver)
64     if cmp_ret == 0 and (req_ver['flags'] in ['EQ', 'GE', 'LE']):
65         return True
66     elif cmp_ret == 1 and (req_ver['flags'] in ['LT', 'LE']):
67         return True
68     elif cmp_ret == -1 and (req_ver['flags'] in ['GT', 'GE']):
69         return True
70     return False