<commit_before>
import glob
import os

from moulinette import m18n
from yunohost.utils.error import YunohostError
from moulinette.utils.log import getActionLogger
from moulinette.utils.process import check_output, call_async_output
from moulinette.utils.filesystem import read_file

from yunohost.tools import Migration, tools_update, tools_upgrade
from yunohost.app import unstable_apps
from yunohost.regenconf import manually_modified_files
from yunohost.utils.filesystem import free_space_in_directory
from yunohost.utils.packages import get_ynh_package_version, _list_upgradable_apt_packages

logger = getActionLogger('yunohost.migration')

class MyMigration(Migration):

    "Upgrade the system to Debian Buster and Yunohost 4.x"

    mode = "manual"

    def run(self):

        self.check_assertions()

        logger.info(m18n.n("migration_0015_start"))

        #
        # Patch sources.list
        #
        logger.info(m18n.n("migration_0015_patching_sources_list"))
        self.patch_apt_sources_list()
        tools_update(system=True)

        # Tell libc6 it's okay to restart system stuff during the upgrade
        os.system("echo 'libc6 libraries/restart-without-asking boolean true' | debconf-set-selections")

        # Don't send an email to root about the postgresql migration. It should be handled automatically after.
        os.system("echo 'postgresql-common postgresql-common/obsolete-major seen true' | debconf-set-selections")

        #
        # Specific packages upgrades
        #
        logger.info(m18n.n("migration_0015_specific_upgrade"))

        # Update unscd independently, was 0.53-1+yunohost on stretch (custom build of ours) but now it's 0.53-1+b1 on vanilla buster,
        # which for apt appears as a lower version (hence the --allow-downgrades and the hardcoded version number)
        unscd_version = check_output('dpkg -s unscd | grep "^Version: " | cut -d " " -f 2')
        if "yunohost" in unscd_version:
            self.apt_install('unscd=0.53-1+b1 --allow-downgrades')

        # Upgrade libpam-modules independently, small issue related to willing to overwrite a file previously provided by Yunohost
        libpammodules_version = check_output('dpkg -s libpam-modules | grep "^Version: " | cut -d " " -f 2')
        if not libpammodules_version.startswith("1.3"):
            self.apt_install('libpam-modules -o Dpkg::Options::="--force-overwrite"')<commit_msg>Fix small issue with unscd upgrade/downgrade ... new version ain't always 0.53.1, so find it using dirty scrapping<commit_after>
import glob
import os

from moulinette import m18n
from yunohost.utils.error import YunohostError
from moulinette.utils.log import getActionLogger
from moulinette.utils.process import check_output, call_async_output
from moulinette.utils.filesystem import read_file

from yunohost.tools import Migration, tools_update, tools_upgrade
from yunohost.app import unstable_apps
from yunohost.regenconf import manually_modified_files
from yunohost.utils.filesystem import free_space_in_directory
from yunohost.utils.packages import get_ynh_package_version, _list_upgradable_apt_packages

logger = getActionLogger('yunohost.migration')

class MyMigration(Migration):

    "Upgrade the system to Debian Buster and Yunohost 4.x"

    mode = "manual"

    def run(self):

        self.check_assertions()

        logger.info(m18n.n("migration_0015_start"))

        #
        # Patch sources.list
        #
        logger.info(m18n.n("migration_0015_patching_sources_list"))
        self.patch_apt_sources_list()
        tools_update(system=True)

        # Tell libc6 it's okay to restart system stuff during the upgrade
        os.system("echo 'libc6 libraries/restart-without-asking boolean true' | debconf-set-selections")

        # Don't send an email to root about the postgresql migration. It should be handled automatically after.
        os.system("echo 'postgresql-common postgresql-common/obsolete-major seen true' | debconf-set-selections")

        #
        # Specific packages upgrades
        #
        logger.info(m18n.n("migration_0015_specific_upgrade"))

        # Update unscd independently, was 0.53-1+yunohost on stretch (custom build of ours) but now it's 0.53-1+b1 on vanilla buster,
        # which for apt appears as a lower version (hence the --allow-downgrades and the hardcoded version number)
        unscd_version = check_output('dpkg -s unscd | grep "^Version: " | cut -d " " -f 2')
        if "yunohost" in unscd_version:
            new_version = check_output("apt policy unscd 2>/dev/null | grep -v '\\*\\*\\*' | grep -A100 'Version table' | grep debian -B1 | head -n 1 | awk '{print $1}'")
            if new_version:
                self.apt_install('unscd=%s --allow-downgrades' % new_version)
            else:
                logger.warning("Could not identify which version of unscd to install")

        # Upgrade libpam-modules independently, small issue related to willing to overwrite a file previously provided by Yunohost
        libpammodules_version = check_output('dpkg -s libpam-modules | grep "^Version: " | cut -d " " -f 2')
        if not libpammodules_version.startswith("1.3"):
            self.apt_install('libpam-modules -o Dpkg::Options::="--force-overwrite"')
{'fraction_non_alphanumeric': 0.08760927404028887, 'fraction_numerical': 0.016723679209426075, 'mean_word_length': 3.422689075630252, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7483459', 'n_tokens_mistral': 1689, 'n_tokens_neox': 1584, 'n_words': 444}