Author: waldi Date: Sat Mar 8 21:16:36 2008 New Revision: 10745 Log: * lib/dkt/hooks/modules/backward_config_boot.py: Remove symlink handling. * lib/dkt/hooks/modules/backward_symlinks.py: Add symlink handling.
Modified: people/waldi/dkt/lib/dkt/hooks/modules/backward_config_boot.py people/waldi/dkt/lib/dkt/hooks/modules/backward_symlinks.py Modified: people/waldi/dkt/lib/dkt/hooks/modules/backward_config_boot.py ============================================================================== --- people/waldi/dkt/lib/dkt/hooks/modules/backward_config_boot.py (original) +++ people/waldi/dkt/lib/dkt/hooks/modules/backward_config_boot.py Sat Mar 8 21:16:36 2008 @@ -6,7 +6,7 @@ from dkt.imageconfig.interfaces import IImageBaseConfig class Hook(object): - def _add_config(self, configs, version, image_file, initramfs_file, symlinks_file): + def _add_config(self, configs, version, image_file, initramfs_file): c = { 'image': { @@ -21,11 +21,6 @@ if initramfs_file is not None: c['initramfs'] = {'file': initramfs_file} - if symlinks_file is not None: - c['backward-compatibility'] = { - 'symlink-file': symlinks_file, - } - configs.add('boot-backward-' + version, MutableConfig(c)) def _check_config(self, configs, version, data): @@ -37,46 +32,35 @@ return self._add_config(configs, version, *data) - def _update_config(self, config, image_file, initramfs_file, symlinks_file): + def _update_config(self, config, image_file, initramfs_file): config = IMutableConfig(config) - if symlinks_file is not None: - config.add_section('backward-compatibility') - config.set('backward-compatibility', 'symlink-file', symlinks_file) + if initramfs_file is not None: config.add_section('initramfs') config.set('initramfs', 'file', initramfs_file) def _get_files(self): - ret = ([], [], [], []) + ret = ([], []) for root, dirs, files in os.walk('/boot'): del dirs[:] for file in files: real_file = os.path.join(root, file) file_parts = file.split('-', 1) + + if file.endswith('.bak'): + continue + if os.path.islink(real_file): + continue + + version = "unknown" + if len(file_parts) > 1: + version = file_parts[1] + if file_parts[0] in ("vmlinuz", "vmlinux"): - if len(file_parts) > 1: - ret[0].append((real_file, file_parts[1])) - else: - ret[2].append((real_file, file)) - elif file in ("vmlinuz.old", "vmlinux.old"): - ret[2].append((real_file, file)) + ret[0].append((real_file, version)) elif file_parts[0] in ("initrd.img",): - if len(file_parts) > 1: - ret[1].append((real_file, file_parts[1])) - else: - ret[3].append((real_file, file)) - elif file in ("initrd.img.old"): - ret[3].append((real_file, file)) - - for root, dirs, files in os.walk('/'): - del dirs[:] - for file in files: - real_file = os.path.join(root, file) - if file in ("vmlinuz", "vmlinux"): - ret[2].append((real_file, file)) - elif file in ("initrd.img"): - ret[3].append((real_file, file)) + ret[1].append((real_file, version)) return ret @@ -85,35 +69,15 @@ versions = {} for file in iter(files[0]): - if file[0].endswith('.bak'): - continue version = file[1] - e = versions.setdefault(version, [None, None, None]) + e = versions.setdefault(version, [None, None]) e[0] = file[0] for file in iter(files[1]): - if file[0].endswith('.bak'): - continue version = file[1] - e = versions.setdefault(version, [None, None, None]) + e = versions.setdefault(version, [None, None]) e[1] = file[0] - for file in iter(files[2]): - if not os.path.islink(file[0]): - e = versions.setdefault("unknown", [None, None, None]) - e[0] = file[0] - else: - link = os.readlink(file[0]) - link_parts = os.path.basename(link).split('-', 1) - e = versions.get(link_parts[1], None) - if e is not None: - e[2] = file[0] - - for file in iter(files[3]): - if not os.path.islink(file[0]): - e = versions.setdefault("unknown", [None, None, None]) - e[1] = file[0] - return versions def image_config(self, configs, systemconfig): Modified: people/waldi/dkt/lib/dkt/hooks/modules/backward_symlinks.py ============================================================================== --- people/waldi/dkt/lib/dkt/hooks/modules/backward_symlinks.py (original) +++ people/waldi/dkt/lib/dkt/hooks/modules/backward_symlinks.py Sat Mar 8 21:16:36 2008 @@ -1,7 +1,9 @@ from itertools import chain +import os from dkt.config.interfaces import IMutableConfig from dkt.hooks import default_registry, interfaces, register +from dkt.imageconfig.interfaces import IImageBaseConfig class Hook(object): def _check_active(self, systemconfig): @@ -12,6 +14,64 @@ config.add_section('backward-compatibility') config.set('backward-compatibility', name, value) + def _check_file_config(self, configs, type, target, dir, file): + for l in configs.itervalues(): + if IImageBaseConfig(l).file == target: + self._set_config(l, 'symlink-dir', dir) + self._set_config(l, 'symlink-image-file', file) + self._set_config(l, 'symlink-type', type) + return + + def _get_files_dir(self, act, old, dir): + for root, dirs, files in os.walk(dir): + del dirs[:] + for file in files: + real_file = os.path.join(root, file) + + if not os.path.islink(real_file): + continue + + link = os.path.join(root, os.readlink(real_file)) + if os.path.dirname(link) != '/boot': + continue + + if file in ("vmlinuz", "vmlinux"): + act.append((dir, file, link)) + elif file in ("vmlinuz.old", "vmlinux.old"): + old.append((dir, file[:-4], link)) + + def _get_files(self): + actl = [] + oldl = [] + act_dir = act_file = act_target = None + old_dir = old_file = old_target = None + + self._get_files_dir(actl, oldl, '/boot') + self._get_files_dir(actl, oldl, '/') + + assert len(actl) <= 1 + assert len(oldl) <= 1 + + if len(actl): + act_dir, act_file, act_target = actl[0] + if len(oldl): + old_dir, old_file, old_target = oldl[0] + + if act_dir and old_dir: + assert act_dir == old_dir + assert act_file == old_file + + return act_dir, act_file, act_target, old_target + + def image_config(self, configs, systemconfig): + if not self._check_active(systemconfig): + return + + dir, file, act, old = self._get_files() + + self._check_file_config(configs, 0, act, dir, file) + self._check_file_config(configs, 1, old, dir, file) + def image_preinst(*args): pass @@ -30,30 +90,53 @@ def image_postrm(*args): pass + def _set_config_partition(self, config, dir, image_file, type): + suffix = '' + if type == 1: + suffix = '.old' + + link_file = os.path.join(dir, image_file + suffix) + link_target = config.get('image', 'file') + if dir == '/boot': + link_target = os.path.basename(link_target) + + config.set('backward-compatibility', 'symlink-image-data', (link_file, link_target)) + + link_file = os.path.join(dir, 'initrd.img' + suffix) + link_target = None + + initramfs_file = config.get('initramfs', 'file', None) + if initramfs_file: + link_target = initramfs_file + if dir == '/boot': + link_target = os.path.basename(link_target) + + config.set('backward-compatibility', 'symlink-initramfs-data', (link_file, link_target)) + def boot_config_partition(self, bootconfigs, systemconfig): if not self._check_active(systemconfig): return - symlink_act = symlink_act_file = symlink_old = symlink_old_file = None + symlink_act = symlink_old = None symlink_create = symlink_remove = None for i in chain(*bootconfigs): config = i.config if 'backward-compatibility' in config: - symlink_file = config.get('backward-compatibility', 'symlink-file', None) - if symlink_file: - if symlink_file.endswith('.old'): - symlink_old = i - symlink_old_file = symlink_file - else: - symlink_act = i - symlink_act_file = symlink_file + symlink_type = config.get('backward-compatibility', 'symlink-type', None) + if symlink_type == 0: + symlink_act = i + if symlink_type == 1: + symlink_old = i if config.get('backward-compatibility', 'symlink-create', None): symlink_create = i if config.get('backward-compatibility', 'symlink-remove', None): symlink_remove = i + symlink_dir = symlink_act.config.get('backward-compatibility', 'symlink-dir') + symlink_image_file = symlink_act.config.get('backward-compatibility', 'symlink-image-file') + if symlink_create is not None and symlink_create is not symlink_act and symlink_create is not symlink_old: symlink_old = symlink_act symlink_act = symlink_create @@ -66,10 +149,10 @@ ret = [] if symlink_old is not None: - symlink_old.config.set('backward-compatibility', 'symlink-file', symlink_old_file) + self._set_config_partition(symlink_old.config, symlink_dir, symlink_image_file, 1) ret.append(symlink_old) if symlink_act is not None: - symlink_act.config.set('backward-compatibility', 'symlink-file', symlink_act_file) + self._set_config_partition(symlink_act.config, symlink_dir, symlink_image_file, 0) ret.append(symlink_act) return [ret] @@ -79,8 +162,19 @@ assert len(bootconfigs) <= 2 + for bootconfig in bootconfigs: + file, target = bootconfig.config.get('backward-compatibility', 'symlink-image-data') + os.unlink(file) + os.symlink(target, file) + + file, target = bootconfig.config.get('backward-compatibility', 'symlink-image-data') + os.unlink(file) + if target: + os.symlink(target, file) + return True +register('backward-symlinks', interfaces.IImageConfig, Hook(), default_registry.PRIORITY_LAST, (), ('backward-config-boot',)) register('backward-symlinks', interfaces.IBootConfigPartition, Hook(), default_registry.PRIORITY_FIRST) register('backward-symlinks', interfaces.IBootConfigDeploy, Hook(), default_registry.PRIORITY_FIRST) register('backward-symlinks', interfaces.IImageTask, Hook()) _______________________________________________ Kernel-svn-changes mailing list Kernel-svn-changes@lists.alioth.debian.org http://lists.alioth.debian.org/mailman/listinfo/kernel-svn-changes