<commit_before>from __future__ import print_function

import os
import shutil
import string
import math

from SCons.Script import *
from SCons.Action import CommandAction


def get_total_file_size(path):
    total = 0
    for root, dirs, files in os.walk(path):
        for name in files:
            total += os.path.getsize(os.path.join(root, name))
    return total


def replace_underscore(s):
    return s.replace('_', '-')


def write_control(path, env, installed_size):
    f = None
    try:
        f = open(path, 'w')

        write_var = env.WriteVariable
        write_var(env, f, 'Package', 'package_name_lower', None,
                  replace_underscore)
        write_var(env, f, 'Version', 'version', None, replace_underscore)
        write_var(env, f, 'Standards-Version', 'deb_standards_version')
        write_var(env, f, 'Maintainer', 'maintainer')
        write_var(env, f, 'Priority', 'deb_priority')
        write_var(env, f, 'Section', 'deb_section')
        write_var(env, f, 'Bugs', 'bug_url')
        write_var(env, f, 'Homepage', 'url')
        write_var(env, f, 'Essential', 'deb_essential')
        write_var(env, f, 'Distribution', 'deb_distribution')
        write_var(env, f, 'Depends', 'deb_depends')
        write_var(env, f, 'Pre-Depends', 'deb_pre_depends')
        write_var(env, f, 'Recommends', 'deb_recommends')
        write_var(env, f, 'Suggests', 'deb_suggests')
        write_var(env, f, 'Breaks', 'deb_breaks')
        write_var(env, f, 'Conflicts', 'deb_conflicts')
        write_var(env, f, 'Provides', 'deb_provides')
        write_var(env, f, 'Replaces', 'deb_replaces')
        write_var(env, f, 'Enhances', 'deb_enhances')
        write_var(env, f, 'Architecture', 'package_arch', env.GetPackageArch())

        f.write('Installed-Size: %d\n' % math.ceil(installed_size / 1024))

        write_var(env, f, 'Description', 'summary')
        for line in env.get('description').split('\n'):
            if line.strip() == '': line = '.'
            f.write(' %s\n' % line)


    finally:
        if f is not None: f.close()


def install_files(env, key, target, perms = 0o644, dperms = 0o755):
    if key in env: env.CopyToPackage(env.get(key), target, perms, dperms)


def get_files(env, key, target):
    if key in env: return env.ResolvePackageFileMap(env.get(key), target)


def build_function(target, source, env):
    target = str(target[0])
    name = env.get('package_name_lower')

    # Create package build dir
    build_dir = 'build/%s-deb' % name
    if os.path.exists(build_dir): shutil.rmtree(build_dir)
    os.makedirs(build_dir, 0o755)

    # Copy user control files
    shutil.copytree(env.get('deb_directory'), build_dir + '/DEBIAN',
                    ignore = shutil.ignore_patterns('.svn', '*~'))

    # Copy files into package
    install_files(env, 'documents', build_dir + '/usr/share/doc/' + name)
    install_files(env, 'programs', build_dir + '/usr/bin', 0o755)
    install_files(env, 'scripts', build_dir + '/usr/bin', 0o755)
    install_files(env, 'desktop_menu', build_dir + '/usr/share/applications')
    install_files(env, 'init_d', build_dir + '/etc/init.d', 0o755)
    install_files(env, 'config', build_dir + '/etc/' + name)
    install_files(env, 'icons', build_dir + '/usr/share/pixmaps')
    install_files(env, 'mime', build_dir + '/usr/share/mime/packages')
    install_files(env, 'platform_independent', build_dir + '/usr/share/' + name)

    # Dirs
    docs_dir =  build_dir + '/usr/share/doc/' + name

    # Create conffiles
    filename = build_dir + '/DEBIAN/conffiles'
    f = None
    try:
        conffiles = get_files(env, 'init_d', '/etc/init.d')
        if conffiles is not None:
            for src, dst, mode in conffiles:
                if f is None: f = open(filename, 'w')
                f.write(dst + '\n')
    finally:
        if f is not None:
            f.close()
            os.chmod(filename, 0o644)

    # Debian changelog
    changelog = build_dir + '/DEBIAN/changelog'
    if os.path.exists(changelog):
        dest = docs_dir + '/changelog.Debian'

        shutil.move(changelog, dest)
        cmd = 'gzip -9 ' + dest
        CommandAction(cmd).execute(dest + '.gz', [dest], env)

    # ChangeLog<commit_msg>Install misc files with Debian package<commit_after>from __future__ import print_function

import os
import shutil
import string
import math

from SCons.Script import *
from SCons.Action import CommandAction


def get_total_file_size(path):
    total = 0
    for root, dirs, files in os.walk(path):
        for name in files:
            total += os.path.getsize(os.path.join(root, name))
    return total


def replace_underscore(s):
    return s.replace('_', '-')


def write_control(path, env, installed_size):
    f = None
    try:
        f = open(path, 'w')

        write_var = env.WriteVariable
        write_var(env, f, 'Package', 'package_name_lower', None,
                  replace_underscore)
        write_var(env, f, 'Version', 'version', None, replace_underscore)
        write_var(env, f, 'Standards-Version', 'deb_standards_version')
        write_var(env, f, 'Maintainer', 'maintainer')
        write_var(env, f, 'Priority', 'deb_priority')
        write_var(env, f, 'Section', 'deb_section')
        write_var(env, f, 'Bugs', 'bug_url')
        write_var(env, f, 'Homepage', 'url')
        write_var(env, f, 'Essential', 'deb_essential')
        write_var(env, f, 'Distribution', 'deb_distribution')
        write_var(env, f, 'Depends', 'deb_depends')
        write_var(env, f, 'Pre-Depends', 'deb_pre_depends')
        write_var(env, f, 'Recommends', 'deb_recommends')
        write_var(env, f, 'Suggests', 'deb_suggests')
        write_var(env, f, 'Breaks', 'deb_breaks')
        write_var(env, f, 'Conflicts', 'deb_conflicts')
        write_var(env, f, 'Provides', 'deb_provides')
        write_var(env, f, 'Replaces', 'deb_replaces')
        write_var(env, f, 'Enhances', 'deb_enhances')
        write_var(env, f, 'Architecture', 'package_arch', env.GetPackageArch())

        f.write('Installed-Size: %d\n' % math.ceil(installed_size / 1024))

        write_var(env, f, 'Description', 'summary')
        for line in env.get('description').split('\n'):
            if line.strip() == '': line = '.'
            f.write(' %s\n' % line)


    finally:
        if f is not None: f.close()


def install_files(env, key, target, perms = 0o644, dperms = 0o755):
    if key in env: env.CopyToPackage(env.get(key), target, perms, dperms)


def get_files(env, key, target):
    if key in env: return env.ResolvePackageFileMap(env.get(key), target)


def build_function(target, source, env):
    target = str(target[0])
    name = env.get('package_name_lower')

    # Create package build dir
    build_dir = 'build/%s-deb' % name
    if os.path.exists(build_dir): shutil.rmtree(build_dir)
    os.makedirs(build_dir, 0o755)

    # Copy user control files
    shutil.copytree(env.get('deb_directory'), build_dir + '/DEBIAN',
                    ignore = shutil.ignore_patterns('.svn', '*~'))

    # Copy files into package
    install_files(env, 'documents', build_dir + '/usr/share/doc/' + name)
    install_files(env, 'programs', build_dir + '/usr/bin', 0o755)
    install_files(env, 'scripts', build_dir + '/usr/bin', 0o755)
    install_files(env, 'desktop_menu', build_dir + '/usr/share/applications')
    install_files(env, 'init_d', build_dir + '/etc/init.d', 0o755)
    install_files(env, 'config', build_dir + '/etc/' + name)
    install_files(env, 'icons', build_dir + '/usr/share/pixmaps')
    install_files(env, 'mime', build_dir + '/usr/share/mime/packages')
    install_files(env, 'platform_independent', build_dir + '/usr/share/' + name)
    install_files(env, 'misc', build_dir)

    # Dirs
    docs_dir =  build_dir + '/usr/share/doc/' + name

    # Create conffiles
    filename = build_dir + '/DEBIAN/conffiles'
    f = None
    try:
        conffiles = get_files(env, 'init_d', '/etc/init.d')
        if conffiles is not None:
            for src, dst, mode in conffiles:
                if f is None: f = open(filename, 'w')
                f.write(dst + '\n')
    finally:
        if f is not None:
            f.close()
            os.chmod(filename, 0o644)

    # Debian changelog
    changelog = build_dir + '/DEBIAN/changelog'
    if os.path.exists(changelog):
        dest = docs_dir + '/changelog.Debian'

        shutil.move(changelog, dest)
        cmd = 'gzip -9 ' + dest
        CommandAction(cmd).execute(dest + '.gz', [dest], env)

    # ChangeLog
{'fraction_non_alphanumeric': 0.14461791290057519, 'fraction_numerical': 0.008216926869350863, 'mean_word_length': 2.935334872979215, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2721027', 'n_tokens_mistral': 3070, 'n_tokens_neox': 2894, 'n_words': 673}