<commit_before># Copyright 2016 Canonical Ltd.
#
# This file is part of the Snap layer for Juju.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#  http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
'''
charms.reactive helpers for dealing with Snap packages.
'''
import os.path
import shutil
import subprocess
from textwrap import dedent
import time

from charmhelpers.core import hookenv, host
from charms import layer
from charms import reactive
from charms.layer import snap
from charms.reactive import hook
from charms.reactive.helpers import data_changed


def install():
    opts = layer.options('snap')
    for snapname, snap_opts in opts.items():
        installed_state = 'snap.installed.{}'.format(snapname)
        if not reactive.is_state(installed_state):
            snap.install(snapname, **snap_opts)
    if data_changed('snap.install.opts', opts):
        snap.connect_all()


def refresh():
    opts = layer.options('snap')
    for snapname, snap_opts in opts.items():
        snap.refresh(snapname, **snap_opts)
    snap.connect_all()


@hook('upgrade-charm')
def upgrade_charm():
    refresh()


def get_series():
    return subprocess.check_output(['lsb_release', '-sc'],
                                   universal_newlines=True).strip()


def snapd_supported():
    # snaps are not supported in trusty lxc containers.
    if get_series() == 'trusty' and host.is_container():
        return False
    return True  # For all other cases, assume true.


def ensure_snapd():
    if not snapd_supported():
        hookenv.log('Snaps do not work in this environment', hookenv.ERROR)
        return

    # I don't use the apt layer, because that would tie this layer
    # too closely to apt packaging. Perhaps this is a snap-only system.
    if not shutil.which('snap'):
        cmd = ['apt', 'install', '-y', 'snapd']
        subprocess.check_call(cmd, universal_newlines=True)
<commit_msg>Work around LP:1699986 and install systemd package as well on Trusty.<commit_after># Copyright 2016 Canonical Ltd.
#
# This file is part of the Snap layer for Juju.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#  http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
'''
charms.reactive helpers for dealing with Snap packages.
'''
import os.path
import shutil
import subprocess
from textwrap import dedent
import time

from charmhelpers.core import hookenv, host
from charms import layer
from charms import reactive
from charms.layer import snap
from charms.reactive import hook
from charms.reactive.helpers import data_changed


def install():
    opts = layer.options('snap')
    for snapname, snap_opts in opts.items():
        installed_state = 'snap.installed.{}'.format(snapname)
        if not reactive.is_state(installed_state):
            snap.install(snapname, **snap_opts)
    if data_changed('snap.install.opts', opts):
        snap.connect_all()


def refresh():
    opts = layer.options('snap')
    for snapname, snap_opts in opts.items():
        snap.refresh(snapname, **snap_opts)
    snap.connect_all()


@hook('upgrade-charm')
def upgrade_charm():
    refresh()


def get_series():
    return subprocess.check_output(['lsb_release', '-sc'],
                                   universal_newlines=True).strip()


def snapd_supported():
    # snaps are not supported in trusty lxc containers.
    if get_series() == 'trusty' and host.is_container():
        return False
    return True  # For all other cases, assume true.


def ensure_snapd():
    if not snapd_supported():
        hookenv.log('Snaps do not work in this environment', hookenv.ERROR)
        return

    # I don't use the apt layer, because that would tie this layer
    # too closely to apt packaging. Perhaps this is a snap-only system.
    if not shutil.which('snap'):
        cmd = ['apt', 'install', '-y', 'snapd']
        # LP:1699986: Force install of systemd on Trusty.
        if get_series() == 'trusty':
            cmd.append('systemd')
        subprocess.check_call(cmd, universal_newlines=True)

{'fraction_non_alphanumeric': 0.09416581371545547, 'fraction_numerical': 0.006141248720573183, 'mean_word_length': 3.445859872611465, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '300543', 'n_tokens_mistral': 1405, 'n_tokens_neox': 1345, 'n_words': 523}