1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# Install method for disk image installs (CD & NFS)
from comps import ComponentSet, HeaderList
from installmethod import InstallMethod
import os
import rpm
import time
import urllib
import string
import struct
import socket
from log import log
# we import these explicitly because urllib loads them dynamically, which stinks
import ftplib
import httplib
import StringIO
import todo
FILENAME = 1000000
class UrlInstallMethod(InstallMethod):
def readComps(self, hdlist):
return ComponentSet(self.baseUrl + '/RedHat/base/comps',
hdlist)
def getFilename(self, h, timer):
root = "/mnt/sysimage"
pathlist = [ "/var/tmp", "/tmp",
"/." ]
for p in pathlist:
if (os.access(root + p, os.X_OK)):
tmppath = root + p
break
# h doubles as a filename -- gross
if type("/") == type(h):
fullPath = self.baseUrl + "/" + h
else:
fullPath = self.baseUrl + "/RedHat/RPMS/" + h[FILENAME],
file = tmppath + os.path.basename(fullPath)
connected = 0
while not connected:
try:
urllib.urlretrieve(fullPath, file)
except IOError, (errnum, msg):
log("IOError %s occured getting %s: %s",
errnum, fullPath, str(msg))
time.sleep(5)
else:
connected = 1
return file
def unlinkFilename(self, fullName):
os.remove(fullName)
def readHeaders(self):
connected = 0
while not connected:
try:
url = urllib.urlopen(self.baseUrl + "/RedHat/base/hdlist")
except IOError, (errnum, msg):
log("IOError %s occured getting %s: %s",
errnum, self.baseUrl + "/RedHat/base/hdlist", msg)
time.sleep(5)
else:
connected = 1
raw = url.read(16)
hl = []
while (raw):
info = struct.unpack("iiii", raw)
magic1 = socket.ntohl(info[0]) & 0xffffffff
if (magic1 != 0x8eade801 or info[1]):
raise TypeError, "bad magic in header"
il = socket.ntohl(info[2])
dl = socket.ntohl(info[3])
totalSize = il * 16 + dl;
hdrString = raw[8:] + url.read(totalSize)
hdr = rpm.headerLoad(hdrString)
hl.append(hdr)
raw = url.read(16)
return HeaderList(hl)
def mergeFullHeaders(self, hdlist):
fn = self.getFilename("RedHat/base/hdlist2", None)
hdlist.mergeFullHeaders(fn)
os.unlink(fn)
def __init__(self, url):
InstallMethod.__init__(self)
i = string.index(url, '://') + 2
self.baseUrl = url[0:i]
rem = url[i:]
new = string.replace(rem, "//", "/")
while (new != rem):
rem = new
new = string.replace(rem, "//", "/")
rem = new
if rem and rem[-1] == "/":
rem = rem[:-1]
self.baseUrl = self.baseUrl + rem
|