Blame plugins/migrate.py

Packit Service 27f74b
#
Packit Service 27f74b
# Copyright (C) 2015  Red Hat, Inc.
Packit Service 27f74b
#
Packit Service 27f74b
# This copyrighted material is made available to anyone wishing to use,
Packit Service 27f74b
# modify, copy, or redistribute it subject to the terms and conditions of
Packit Service 27f74b
# the GNU General Public License v.2, or (at your option) any later version.
Packit Service 27f74b
# This program is distributed in the hope that it will be useful, but WITHOUT
Packit Service 27f74b
# ANY WARRANTY expressed or implied, including the implied warranties of
Packit Service 27f74b
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
Packit Service 27f74b
# Public License for more details.  You should have received a copy of the
Packit Service 27f74b
# GNU General Public License along with this program; if not, write to the
Packit Service 27f74b
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
Packit Service 27f74b
# 02110-1301, USA.  Any Red Hat trademarks that are incorporated in the
Packit Service 27f74b
# source code or documentation are not subject to the GNU General Public
Packit Service 27f74b
# License and may only be used or replicated with the express permission of
Packit Service 27f74b
# Red Hat, Inc.
Packit Service 27f74b
#
Packit Service 27f74b
Packit Service 27f74b
from __future__ import absolute_import
Packit Service 27f74b
from __future__ import unicode_literals
Packit Service 27f74b
Packit Service 27f74b
from dnf.db.history import SwdbInterface
Packit Service 27f74b
from dnfpluginscore import _, logger
Packit Service 27f74b
Packit Service 27f74b
import dnf
Packit Service 27f74b
import dnf.cli
Packit Service 27f74b
import os
Packit Service 27f74b
Packit Service 27f74b
Packit Service 27f74b
class Migrate(dnf.Plugin):
Packit Service 27f74b
Packit Service 27f74b
    name = "migrate"
Packit Service 27f74b
Packit Service 27f74b
    def __init__(self, base, cli):
Packit Service 27f74b
        super(Migrate, self).__init__(base, cli)
Packit Service 27f74b
        self.base = base
Packit Service 27f74b
        self.cli = cli
Packit Service 27f74b
        if self.cli is not None:
Packit Service 27f74b
            self.cli.register_command(MigrateCommand)
Packit Service 27f74b
Packit Service 27f74b
Packit Service 27f74b
class MigrateCommand(dnf.cli.Command):
Packit Service 27f74b
Packit Service 27f74b
    aliases = ("migrate",)
Packit Service 27f74b
    summary = _("migrate yum's history, group and yumdb data to dnf")
Packit Service 27f74b
Packit Service 27f74b
    def configure(self):
Packit Service 27f74b
        demands = self.cli.demands
Packit Service 27f74b
        demands.available_repos = True
Packit Service 27f74b
        demands.sack_activation = True
Packit Service 27f74b
        demands.root_user = True
Packit Service 27f74b
Packit Service 27f74b
    def run(self):
Packit Service 27f74b
        logger.info(_("Migrating history data..."))
Packit Service 27f74b
        input_dir = os.path.join(self.base.conf.installroot, '/var/lib/yum/')
Packit Service 27f74b
        persist_dir = os.path.join(self.base.conf.installroot, self.base.conf.persistdir)
Packit Service 27f74b
        swdb = SwdbInterface(persist_dir)
Packit Service 27f74b
        swdb.transform(input_dir)