本文整理汇总了Python中utils.loh_to_hoh函数的典型用法代码示例。如果您正苦于以下问题:Python loh_to_hoh函数的具体用法?Python loh_to_hoh怎么用?Python loh_to_hoh使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了loh_to_hoh函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: replace_objects_newer_on_remote
def replace_objects_newer_on_remote(self, obj_type):
locals = utils.loh_to_hoh(self.local_data[obj_type],"uid")
remotes = utils.loh_to_hoh(self.remote_data[obj_type],"uid")
for (ruid, rdata) in remotes.iteritems():
# do not add the system if it is not on the transfer list
if not self.must_include[obj_type].has_key(rdata["name"]):
continue
if locals.has_key(ruid):
ldata = locals[ruid]
if ldata["mtime"] < rdata["mtime"]:
if ldata["name"] != rdata["name"]:
self.logger.info("removing %s %s" % (obj_type, ldata["name"]))
self.api.remove_item(obj_type, ldata["name"], recursive=True, logger=self.logger)
creator = getattr(self.api, "new_%s" % obj_type)
newobj = creator()
newobj.from_datastruct(rdata)
try:
self.logger.info("updating %s %s" % (obj_type, rdata["name"]))
self.api.add_item(obj_type, newobj)
except Exception, e:
utils.log_exc(self.logger)
示例2: remove_objects_not_on_master
def remove_objects_not_on_master(self, obj_type):
locals = utils.loh_to_hoh(self.local_data[obj_type],"uid")
remotes = utils.loh_to_hoh(self.remote_data[obj_type],"uid")
for (luid, ldata) in locals.iteritems():
if not remotes.has_key(luid):
try:
self.logger.info("removing %s %s" % (obj_type, ldata["name"]))
self.api.remove_item(obj_type, ldata["name"], recursive=True, logger=self.logger)
except Exception, e:
utils.log_exc(self.logger)
示例3: add_objects_not_on_local
def add_objects_not_on_local(self, obj_type):
locals = utils.loh_to_hoh(self.local_data[obj_type], "uid")
remotes = utils.loh_sort_by_key(self.remote_data[obj_type],"depth")
remotes2 = utils.loh_to_hoh(self.remote_data[obj_type],"depth")
for rdata in remotes:
# do not add the system if it is not on the transfer list
if not self.must_include[obj_type].has_key(rdata["name"]):
continue
if not locals.has_key(rdata["uid"]):
creator = getattr(self.api, "new_%s" % obj_type)
newobj = creator()
newobj.from_datastruct(rdata)
try:
self.logger.info("adding %s %s" % (obj_type, rdata["name"]))
self.api.add_item(obj_type, newobj)
except Exception, e:
utils.log_exc(self.logger)
示例4: remove_objects_not_on_master
def remove_objects_not_on_master(self, obj_type):
locals = utils.lod_to_dod(self.local_data[obj_type], "uid")
remotes = utils.lod_to_dod(self.remote_data[obj_type], "uid")
obj_pattern = getattr(self, "%s_patterns" % obj_type)
if obj_pattern and self.prune:
self.logger.info("Found pattern for %s. Pruning non-matching items" % obj_type)
keep_obj = {}
remote_names = utils.loh_to_hoh(self.remote_data[obj_type], "name")
for name in remote_names.keys():
if name in self.must_include[obj_type] and remote_names[name]["uid"] in remotes:
self.logger.info("Adding %s:%s to keep list" % (name, remote_names[name]["uid"]))
keep_obj[remote_names[name]["uid"]] = remotes[remote_names[name]["uid"]]
remotes = keep_obj
for (luid, ldata) in locals.iteritems():
if luid not in remotes:
try:
self.logger.info("removing %s %s" % (obj_type, ldata["name"]))
self.api.remove_item(obj_type, ldata["name"], recursive=True, logger=self.logger)
except Exception:
utils.log_exc(self.logger)
示例5: generate_include_map
def generate_include_map(self):
self.remote_names = {}
self.remote_dict = {}
self.must_include = {
"distro" : {},
"profile" : {},
"system" : {},
"image" : {},
"repo" : {},
"mgmtclass" : {},
"package" : {},
"file" : {}
}
for ot in OBJ_TYPES:
self.remote_names[ot] = utils.loh_to_hoh(self.remote_data[ot],"name").keys()
self.remote_dict[ot] = utils.loh_to_hoh(self.remote_data[ot],"name")
if self.sync_all:
for names in self.remote_dict[ot]:
self.must_include[ot][names] = 1
self.logger.debug("remote names struct is %s" % self.remote_names)
if not self.sync_all:
# include all profiles that are matched by a pattern
for obj_type in OBJ_TYPES:
patvar = getattr(self, "%s_patterns" % obj_type)
self.logger.debug("* Finding Explicit %s Matches" % obj_type)
for pat in patvar:
for remote in self.remote_names[obj_type]:
self.logger.debug("?: seeing if %s looks like %s" % (remote,pat))
if fnmatch.fnmatch(remote, pat):
self.must_include[obj_type][remote] = 1
# include all profiles that systems require
# whether they are explicitly included or not
self.logger.debug("* Adding Profiles Required By Systems")
for sys in self.must_include["system"].keys():
pro = self.remote_dict["system"][sys].get("profile","")
self.logger.debug("?: requires profile: %s" % pro)
if pro != "":
self.must_include["profile"][pro] = 1
# include all profiles that subprofiles require
# whether they are explicitly included or not
# very deep nesting is possible
self.logger.debug("* Adding Profiles Required By SubProfiles")
while True:
loop_exit = True
for pro in self.must_include["profile"].keys():
parent = self.remote_dict["profile"][pro].get("parent","")
if parent != "":
if not self.must_include["profile"].has_key(parent):
self.must_include["profile"][parent] = 1
loop_exit = False
if loop_exit:
break
# require all distros that any profiles in the generated list requires
# whether they are explicitly included or not
self.logger.debug("* Adding Distros Required By Profiles")
for p in self.must_include["profile"].keys():
distro = self.remote_dict["profile"][p].get("distro","")
if not distro == "<<inherit>>" and not distro == "~":
self.logger.info("Adding repo %s for profile %s."%(p, distro))
self.must_include["distro"][distro] = 1
# require any repos that any profiles in the generated list requires
# whether they are explicitly included or not
self.logger.debug("* Adding Repos Required By Profiles")
for p in self.must_include["profile"].keys():
repos = self.remote_dict["profile"][p].get("repos",[])
for r in repos:
self.must_include["repo"][r] = 1
# include all images that systems require
# whether they are explicitly included or not
self.logger.debug("* Adding Images Required By Systems")
for sys in self.must_include["system"].keys():
img = self.remote_dict["system"][sys].get("image","")
self.logger.debug("?: requires profile: %s" % pro)
if img != "":
self.must_include["image"][img] = 1
# FIXME: remove debug
for ot in OBJ_TYPES:
self.logger.debug("transfer list for %s is %s" % (ot, self.must_include[ot].keys()))