def apply(self, builder, instr, role, target_base, hierarchy): # Find or create the relevant file cpio_file = cpiofile.File() (clrb, setb) = utils.parse_mode(instr.mode) cpio_file.mode = setb cpio_file.uid = utils.parse_uid(builder, instr.uid) cpio_file.gid = utils.parse_gid(builder, instr.gid) if (instr.type == "char"): cpio_file.mode = cpio_file.mode | cpiofile.File.S_CHAR else: cpio_file.mode = cpio_file.mode | cpiofile.File.S_BLK cpio_file.rdev = os.makedev(int(instr.major), int(instr.minor)) # Zero-length file - it's a device node. cpio_file.name = None cpio_file.data = None #print "target_base = %s for role %s"%(target_base, role) real_path = utils.rel_join(target_base, instr.file_name) cpio_file.key_name = real_path #print "put_target_file %s"%real_path print 'Adding device node %s'%real_path hierarchy.put_target_file(real_path, cpio_file)
def list_files_under(self, dir, recursively=False, vroot=None): """ Return a list of the files under dir. """ if (dir[0] == '/'): dir = dir[1:] #print "l_f_u = %s (vroot = %s)"%(dir,vroot) obj = None for r in self.hierarchy.roots.keys(): to_find = utils.rel_join(vroot, dir) abs_path = os.path.join(r, to_find) # Trim any trailing '/'s for normalisation reasons. if (len(abs_path) > 1 and abs_path[-1] == '/'): abs_path = abs_path[:-1] # Find the File representing this directory obj = self.hierarchy.map.get(abs_path) if (obj is not None): break if (obj is None): print "> Warning: No files in %s [vroot = %s] in this cpio archive.. " % ( dir, vroot) return [] # Read everything in this directory. result = [] for elem in obj.children: last_elem = os.path.basename(elem.name) # We want the last element only .. result.append(last_elem) if (recursively): # .. and recurse .. #print "> l_f_u recurse dir = %s, elem.name = %s last = %s"%(dir, elem.name, last_elem) inner = self.list_files_under(os.path.join(dir, last_elem), True, vroot=vroot) for thing in inner: result.append(os.path.join(last_elem, thing)) return result
def list_files_under(self, dir, recursively = False, vroot = None): """ Return a list of the files under dir. """ if (dir[0] == '/'): dir = dir[1:] #print "l_f_u = %s (vroot = %s)"%(dir,vroot) obj = None for r in self.hierarchy.roots.keys(): to_find = utils.rel_join(vroot, dir) abs_path = os.path.join(r, to_find) # Trim any trailing '/'s for normalisation reasons. if (len(abs_path) > 1 and abs_path[-1] == '/'): abs_path = abs_path[:-1] # Find the File representing this directory obj = self.hierarchy.map.get(abs_path) if (obj is not None): break if (obj is None): print "> Warning: No files in %s [vroot = %s] in this cpio archive.. "%(dir,vroot) return [ ] # Read everything in this directory. result = [ ] for elem in obj.children: last_elem = os.path.basename(elem.name) # We want the last element only .. result.append(last_elem) if (recursively): # .. and recurse .. #print "> l_f_u recurse dir = %s, elem.name = %s last = %s"%(dir, elem.name, last_elem) inner = self.list_files_under(os.path.join(dir, last_elem), True, vroot = vroot) for thing in inner: result.append(os.path.join(last_elem, thing)) return result
def file_name(self, builder): tmp = depend.Label(utils.LabelType.Package, self.name, self.role) inst_path = builder.package_install_path(tmp) ret = utils.rel_join(inst_path, self.filename) return ret
def build_label(self, builder, label): our_dir = builder.package_obj_path(label) dirlist = [] tag = label.tag if (tag == utils.LabelTag.Built or tag == utils.LabelTag.Installed): for (l, s) in self.components: tmp = Label(utils.LabelType.Package, l.name, l.role, domain=label.domain) root_dir = builder.package_install_path(tmp) dirlist.append((root_dir, s)) print "dirlist:" for (x, y) in dirlist: print "%s=%s \n" % (x, y) if (tag == utils.LabelTag.PreConfig): pass elif (tag == utils.LabelTag.Configured): pass elif (tag == utils.LabelTag.Built): # OK. Building. This is ghastly .. utils.recursively_remove(our_dir) utils.ensure_dir(our_dir) # Now we need to copy all the subdirs in .. for (root, sub) in dirlist: utils.ensure_dir(utils.rel_join(our_dir, sub)) # Only bother to copy kernel modules. names = utils.find_by_predicate(utils.rel_join(root, sub), predicate_is_kernel_module) utils.copy_name_list_with_dirs(names, utils.rel_join(root, sub), utils.rel_join(our_dir, sub)) # .. and run depmod. depmod = "depmod" if (self.custom_depmod is not None): depmod = self.custom_depmod # Because depmod is brain-dead, we need to give it explicit versions. names = os.listdir(utils.rel_join(our_dir, "lib/modules")) our_re = re.compile(r'\d+\.\d+\..*') for n in names: if (our_re.match(n) is not None): print "Found kernel version %s in %s .. " % (n, our_dir) utils.run0("%s -b %s %s" % (depmod, our_dir, n)) elif (tag == utils.LabelTag.Installed): # Now we find all the modules.* files in our_dir and copy them over # to our install directory names = utils.find_by_predicate(our_dir, predicate_is_module_db) tgt_dir = builder.package_install_path(label) utils.copy_name_list_with_dirs(names, our_dir, tgt_dir) for n in names: new_n = utils.replace_root_name(our_dir, tgt_dir, n) print "Installed: %s" % (new_n) elif (tag == utils.LabelTag.Clean): utils.recursively_remove(our_dir) elif (tag == utils.LabelTag.DistClean): utils.recursively_remove(our_dir)
def build_label(self, builder, label): our_dir = builder.package_obj_path(label) dirlist = [ ] tag = label.tag if (tag == utils.LabelTag.Built or tag == utils.LabelTag.Installed): for (l,s) in self.components: tmp = Label(utils.LabelType.Package, l.name, l.role, domain=label.domain) root_dir = builder.package_install_path(tmp) dirlist.append( (root_dir, s) ) print "dirlist:" for (x,y) in dirlist: print "%s=%s \n"%(x,y) if (tag == utils.LabelTag.PreConfig): pass elif (tag == utils.LabelTag.Configured): pass elif (tag == utils.LabelTag.Built): # OK. Building. This is ghastly .. utils.recursively_remove(our_dir) utils.ensure_dir(our_dir) # Now we need to copy all the subdirs in .. for (root, sub) in dirlist: utils.ensure_dir(utils.rel_join(our_dir, sub)) # Only bother to copy kernel modules. names = utils.find_by_predicate(utils.rel_join(root, sub), predicate_is_kernel_module) utils.copy_name_list_with_dirs(names, utils.rel_join(root,sub), utils.rel_join(our_dir, sub)) # .. and run depmod. depmod = "depmod" if (self.custom_depmod is not None): depmod = self.custom_depmod # Because depmod is brain-dead, we need to give it explicit versions. names = os.listdir(utils.rel_join(our_dir, "lib/modules")) our_re = re.compile(r'\d+\.\d+\..*') for n in names: if (our_re.match(n) is not None): print "Found kernel version %s in %s .. "%(n, our_dir) utils.run0("%s -b %s %s"%(depmod, our_dir, n)) elif (tag == utils.LabelTag.Installed): # Now we find all the modules.* files in our_dir and copy them over # to our install directory names = utils.find_by_predicate(our_dir, predicate_is_module_db) tgt_dir = builder.package_install_path(label) utils.copy_name_list_with_dirs(names, our_dir, tgt_dir) for n in names: new_n = utils.replace_root_name(our_dir, tgt_dir, n) print "Installed: %s"%(new_n) elif (tag == utils.LabelTag.Clean): utils.recursively_remove(our_dir) elif (tag == utils.LabelTag.DistClean): utils.recursively_remove(our_dir)