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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
"""
A Cobbler repesentation of a yum repo.
Copyright 2006, Red Hat, Inc
Michael DeHaan <mdehaan@redhat.com>
This software may be freely redistributed under the terms of the GNU
general public license.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
"""
import utils
import item
from cexceptions import *
from rhpl.translate import _, N_, textdomain, utf8
class Repo(item.Item):
TYPE_NAME = _("repo")
COLLECTION_TYPE = "repo"
def make_clone(self):
ds = self.to_datastruct()
cloned = Repo(self.config)
cloned.from_datastruct(ds)
return cloned
def clear(self,is_subobject=False):
self.parent = None
self.name = None
self.mirror = (None, '<<inherit>>')[is_subobject]
self.keep_updated = ('y', '<<inherit>>')[is_subobject]
self.priority = (99, '<<inherit>>')[is_subobject]
self.rpm_list = ("", '<<inherit>>')[is_subobject]
self.createrepo_flags = ("-c cache", '<<inherit>>')[is_subobject]
self.depth = 2 # arbitrary, as not really apart of the graph
self.arch = "" # use default arch
def from_datastruct(self,seed_data):
self.parent = self.load_item(seed_data, 'parent')
self.name = self.load_item(seed_data, 'name')
self.mirror = self.load_item(seed_data, 'mirror')
self.keep_updated = self.load_item(seed_data, 'keep_updated','y')
self.priority = self.load_item(seed_data, 'priority',99)
self.rpm_list = self.load_item(seed_data, 'rpm_list')
self.createrepo_flags = self.load_item(seed_data, 'createrepo_flags', '-c cache')
self.arch = self.load_item(seed_data, 'arch')
self.depth = self.load_item(seed_data, 'depth', 2)
# force this to be saved as a boolean
self.set_keep_updated(self.keep_updated)
return self
def set_name(self,name):
"""
A name can be anything. It's a string, though best values are something like "fc6extras"
or "myrhel4stuff"
"""
self.name = name # we check it add time, but store the original value.
return True
def set_mirror(self,mirror):
"""
A repo is (initially, as in right now) is something that can be rsynced.
reposync/repotrack integration over HTTP might come later.
"""
self.mirror = mirror
return True
def set_keep_updated(self,keep_updated):
"""
This allows the user to disable updates to a particular repo for whatever reason.
"""
if type(keep_updated) == bool:
self.keep_updated = keep_updated
elif str(keep_updated).lower() in ["yes","y","on","1","true"]:
self.keep_updated = True
else:
self.keep_updated = False
return True
def set_priority(self,priority):
"""
Set the priority of the repository. 1= highest, 99=default
Only works if host is using priorities plugin for yum.
"""
try:
priority = int(str(priority))
except:
raise CX(_("invalid priority level: %s") % priority)
self.priority = priority
return True
def set_rpm_list(self,rpms):
"""
Rather than mirroring the entire contents of a repository (Fedora Extras, for instance,
contains games, and we probably don't want those), make it possible to list the packages
one wants out of those repos, so only those packages + deps can be mirrored.
"""
if type(rpms) != list:
rpmlist = rpms.split(None)
else:
rpmlist = rpms
try:
rpmlist.remove('')
except:
pass
self.rpm_list = rpmlist
return True
def set_createrepo_flags(self,createrepo_flags):
"""
Flags passed to createrepo when it is called. Common flags to use would be
-c cache or -g comps.xml to generate group information.
"""
self.createrepo_flags = createrepo_flags
return True
def set_arch(self,arch):
"""
Override the arch used for reposync
"""
self.arch = arch
return True
def is_valid(self):
"""
A repo is valid if it has a name and a mirror URL
"""
if self.name is None:
raise CX(_("name is required"))
if self.mirror is None:
raise CX(_("mirror is required"))
if self.mirror.startswith("rhn://"):
# reposync creates directories based on the channel name so this
# prevents a lot of ugly special case handling if we make the
# requirement that repo names match the channels. It makes sense too.
if self.mirror != "rhn://%s" % self.name:
args = { "m1" : self.mirror, "m2" : self.mirror.replace("rhn://","") }
raise CX(_("Since mirror is RHN %(m1)s, the repo must also be named %(m2)s") % args)
return True
def to_datastruct(self):
return {
'name' : self.name,
'mirror' : self.mirror,
'keep_updated' : self.keep_updated,
'priority' : self.priority,
'rpm_list' : self.rpm_list,
'createrepo_flags' : self.createrepo_flags,
'arch' : self.arch,
'parent' : self.parent,
'depth' : self.depth
}
def printable(self):
buf = _("repo : %s\n") % self.name
buf = buf + _("mirror : %s\n") % self.mirror
buf = buf + _("keep updated : %s\n") % self.keep_updated
buf = buf + _("priority : %s\n") % self.priority
buf = buf + _("rpm list : %s\n") % self.rpm_list
buf = buf + _("createrepo_flags : %s\n") % self.createrepo_flags
buf = buf + _("arch : %s\n") % self.arch
return buf
def get_parent(self):
"""
currently the Cobbler object space does not support subobjects of this object
as it is conceptually not useful.
"""
return None
def is_rsync_mirror(self):
"""
Returns True if this mirror is synchronized using rsync, False otherwise
"""
lower = self.mirror.lower()
if lower.startswith("http://") or lower.startswith("ftp://") or lower.startswith("rhn://"):
return False
else:
return True
def remote_methods(self):
return {
'name' : self.set_name,
'arch' : self.set_arch,
'mirror-name' : self.set_name,
'mirror' : self.set_mirror,
'keep-updated' : self.set_keep_updated,
'priority' : self.set_priority,
'rpm-list' : self.set_rpm_list,
'createrepo-flags' : self.set_createrepo_flags
}
|