Upgrade version to 4.14
[tools/librpm-tizen.git] / python / rpm / __init__.py.in
1 r"""RPM Module
2
3 This module enables you to manipulate rpms and the rpm database.
4
5 The rpm base module provides the main starting point for
6 accessing RPM from Python. For most usage, call
7 the TransactionSet method to get a transaction set (rpmts).
8
9 For example:
10         import rpm
11         ts = rpm.TransactionSet()
12
13 The transaction set will open the RPM database as needed, so
14 in most cases, you do not need to explicitly open the
15 database. The transaction set is the workhorse of RPM.
16
17 You can open another RPM database, such as one that holds
18 all packages for a given Linux distribution, to provide
19 packages used to solve dependencies. To do this, use
20 the following code:
21
22 rpm.addMacro('_dbpath', '/path/to/alternate/database')
23 solvets = rpm.TransactionSet()
24 solvets.openDB()
25 rpm.delMacro('_dbpath')
26
27 # Open default database
28 ts = rpm.TransactionSet()
29
30 This code gives you access to two RPM databases through
31 two transaction sets (rpmts): ts is a transaction set
32 associated with the default RPM database and solvets
33 is a transaction set tied to an alternate database, which
34 is very useful for resolving dependencies.
35 """
36
37 import warnings
38 from @PYTHON_MODULENAME@._rpm import *
39 from @PYTHON_MODULENAME@.transaction import *
40 import @PYTHON_MODULENAME@._rpm as _rpm
41 _RPMVSF_NODIGESTS = _rpm._RPMVSF_NODIGESTS
42 _RPMVSF_NOHEADER = _rpm._RPMVSF_NOHEADER
43 _RPMVSF_NOPAYLOAD = _rpm._RPMVSF_NOPAYLOAD
44 _RPMVSF_NOSIGNATURES = _rpm._RPMVSF_NOSIGNATURES
45
46 __version__ = _rpm.__version__
47 __version_info__ = tuple(__version__.split('.'))
48
49 # backwards compatibility + give the same class both ways
50 ts = TransactionSet
51
52
53 def headerLoad(*args, **kwds):
54     """DEPRECATED! Use rpm.hdr() instead."""
55     warnings.warn("Use rpm.hdr() instead.", DeprecationWarning, stacklevel=2)
56     return hdr(*args, **kwds)
57
58
59 def _doHeaderListFromFD(rpm_fd, retrofit):
60     hlist = []
61     while 1:
62         try:
63             h = hdr(rpm_fd)
64             if retrofit:
65                 h.convert(HEADERCONV_RETROFIT_V3)
66             hlist.append(h)
67         except _rpm.error:
68             break
69
70     return hlist
71
72
73 def readHeaderListFromFD(file_desc, retrofit=True):
74     if not isinstance(file_desc, fd):
75         file_desc = fd(file_desc)
76     return _doHeaderListFromFD(file_desc, retrofit)
77
78
79 def readHeaderListFromFile(path, retrofit=True):
80     f = fd(path)
81     hlist = _doHeaderListFromFD(f, retrofit)
82     f.close()
83     return hlist
84
85
86 def readHeaderFromFD(file_desc):
87     """Return (header, pos_before_hdr)"""
88     if not isinstance(file_desc, fd):
89         file_desc = fd(file_desc)
90     try:
91         offset = file_desc.tell()
92         h = hdr(file_desc)
93     except (_rpm.error, IOError):
94         offset = None
95         h = None
96
97     return (h, offset)
98
99
100 def signalsCaught(siglist):
101     """Returns list of signals that were caught."""
102     caught = []
103     for sig in siglist:
104         if signalCaught(sig):
105             caught.append(sig)
106
107     return caught
108
109
110 def dsSingle(TagN, N, EVR="", Flags=RPMSENSE_ANY):
111     """
112     Creates a single entry dependency set (ds)
113
114     dsSingle(RPMTAG_CONFLICTNAME, "rpm") corresponds to "Conflicts: rpm"
115     """
116     return ds((N, Flags, EVR), TagN)