[TIC-Core] UI element HF and QT implemented. GBS support of category
[archive/20170607/tools/tic-core.git] / tic / utils / rpmmisc.py
1 #!/usr/bin/python
2 # Copyright (c) 2016 Samsung Electronics Co., Ltd
3 #
4 # Licensed under the Flora License, Version 1.1 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #     http://floralicense.org/license/
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16 # Contributors:
17 # - S-Core Co., Ltd
18
19 import rpm
20
21 class Dependency(object):
22     REQUIRES='requires'
23     RECOMMENDS='recommends'
24     SUGGESTS='suggests'
25     PROVIDES='provides'
26     CONFILCTS='conflicts'
27
28
29 default_arch = ('noarch', 'src')
30
31 archPolicies = {
32     "x86_64":       ("x86_64", "i686", "i586", "i486", "i386"),
33     "i686":         ("i686", "i586", "i486", "i386"),
34     "i586":         ("i586", "i486", "i386"),
35     "ia64":         ("ia64", "i686", "i586", "i486", "i386"),
36     "aarch64":      ("aarch64"),
37     "armv7tnhl":    ("armv7tnhl", "armv7thl", "armv7nhl", "armv7hl"),
38     "armv7thl":     ("armv7thl", "armv7hl"),
39     "armv7nhl":     ("armv7nhl", "armv7hl"),
40     "armv7hl":      ("armv7hl"),
41     "armv7l":       ("armv7l", "armv6l", "armv5tejl", "armv5tel", "armv5l", "armv4tl", "armv4l", "armv3l"),
42     "armv6l":       ("armv6l", "armv5tejl", "armv5tel", "armv5l", "armv4tl", "armv4l", "armv3l"),
43     "armv5tejl":    ("armv5tejl", "armv5tel", "armv5l", "armv4tl", "armv4l", "armv3l"),
44     "armv5tel":     ("armv5tel", "armv5l", "armv4tl", "armv4l", "armv3l"),
45     "armv5l":       ("armv5l", "armv4tl", "armv4l", "armv3l"),
46 }
47
48 def compare_ver(ver1, ver2):
49     return rpm.labelCompare((ver1.get('epoch'), ver1.get('ver'), ver1.get('rel')), (ver2.get('epoch'), ver2.get('ver'), ver2.get('rel')))
50     
51 def compare_req_cap_ver(req, cap):
52     epoch = cap.get('epoch')
53     ver = cap.get('ver')
54     rel = cap.get('rel')
55     if not req.get('epoch'): epoch = None
56     if not req.get('rel'): rel = None
57     return rpm.labelCompare((req.get('epoch'), req.get('ver'), req.get('rel')), (epoch, ver, rel))
58
59 def meetRequireVersion(req_ver, cmp_ver):
60     cmp_ret = compare_req_cap_ver(req_ver, cmp_ver)
61     if cmp_ret == 0 and (req_ver['flags'] in ['EQ', 'GE', 'LE']):
62         return True
63     elif cmp_ret == 1 and (req_ver['flags'] in ['LT', 'LE']):
64         return True
65     elif cmp_ret == -1 and (req_ver['flags'] in ['GT', 'GE']):
66         return True
67     return False