1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 import os
17 from rhn.i18n import bstr
18 from spacewalk.common import checksum
21
22 if filename is not None:
23 stream = open(filename, mode='rb')
24 need_close = True
25 elif file_obj is not None:
26 stream = file_obj
27 else:
28 stream = os.fdopen(os.dup(fd), "r")
29 need_close = True
30
31 if stream.name.endswith('.deb'):
32 packaging = 'deb'
33 elif stream.name.endswith('.rpm'):
34 packaging = 'rpm'
35 else:
36 packaging = 'mpm'
37
38 a_pkg = package_from_stream(stream, packaging)
39 a_pkg.read_header()
40 if need_close:
41 stream.close()
42 return a_pkg.header
43
58
61 if filename.endswith('.deb'):
62 packaging = 'deb'
63 elif filename.endswith('.rpm') or filename.endswith('.hdr'):
64 packaging = 'rpm'
65 else:
66 packaging = 'mpm'
67 stream = open(filename, mode='rb')
68 return package_from_stream(stream, packaging)
69
70 BUFFER_SIZE = 16384
71 DEFAULT_CHECKSUM_TYPE = 'md5'
75
76 """virtual class that implements shared methods for RPM/MPM/DEB package object"""
77
78
88
90 """reads header from self.input_file"""
91 pass
92
94 """saves payload to output_stream"""
95 c_hash = checksum.getHashlibInstance(self.checksum_type, False)
96 if output_stream:
97 output_start = output_stream.tell()
98 self._stream_copy(self.input_stream, output_stream, c_hash)
99 self.checksum = c_hash.hexdigest()
100 if output_stream:
101 self.payload_stream = output_stream
102 self.payload_size = output_stream.tell() - output_start
103
105
106 start = self.input_stream.tell()
107 self.save_payload(None)
108 self.payload_size = self.input_stream.tell() - start + self.header_end
109 self.payload_stream = self.input_stream
110
111 @staticmethod
113 """copies data from the source stream to the destination stream"""
114 while True:
115 buf = source.read(BUFFER_SIZE)
116 if not buf:
117 break
118 if dest:
119 dest.write(buf)
120 if c_hash:
121 c_hash.update(buf)
122
123 @staticmethod
125 ret = bstr('')
126 while amt:
127 buf = stream.read(min(amt, BUFFER_SIZE))
128 if not buf:
129 return ret
130 ret = ret + buf
131 amt = amt - len(buf)
132 return ret
133
137