<commit_before># Copyright (C) 2006-2008, Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

import os
import sys
import six
import logging

# Change the default encoding to avoid UnicodeDecodeError
# http://lists.sugarlabs.org/archive/sugar-devel/2012-August/038928.html
if six.PY2:
    reload(sys)
    sys.setdefaultencoding('utf-8')

import gettext
from optparse import OptionParser

import dbus
import dbus.service
from dbus.mainloop.glib import DBusGMainLoop
DBusGMainLoop(set_as_default=True)

from sugar3.activity import activityhandle
from sugar3 import config
from sugar3.bundle.activitybundle import ActivityBundle
from sugar3 import logger

from sugar3.bundle.bundle import MalformedBundleException

from errno import EEXIST

import time
import hashlib
import random


def _makedirs(path):
    try:
        os.makedirs(path)
    except OSError as e:
        if e.errno != EEXIST:
            raise e


def create_activity_instance(constructor, handle):
    activity = constructor(handle)
    activity.show()
    return activity


def get_single_process_name(bundle_id):
    return bundle_id


def get_single_process_path(bundle_id):
    return '/' + bundle_id.replace('.', '/')


class SingleProcess(dbus.service.Object):

    def __init__(self, name_service, constructor):
        self.constructor = constructor

        bus = dbus.SessionBus()
        bus_name = dbus.service.BusName(name_service, bus=bus)
        object_path = get_single_process_path(name_service)
        dbus.service.Object.__init__(self, bus_name, object_path)

    @dbus.service.method('org.laptop.SingleProcess', in_signature='a{sv}')
    def create(self, handle_dict):
        handle = activityhandle.create_from_dict(handle_dict)
        create_activity_instance(self.constructor, handle)


def main():
    usage = 'usage: %prog [options] [activity dir] [python class]'
    epilog = 'If you are running from a directory containing an Activity, ' \
             'the argument may be omitted.  Otherwise please provide either '\
             'a directory containing a Sugar Activity [activity dir], a '\
             '[python_class], or both.'

    parser = OptionParser(usage=usage, epilog=epilog)
    parser.add_option('-b', '--bundle-id', dest='bundle_id',
                      help='identifier of the activity bundle')
    parser.add_option('-a', '--activity-id', dest='activity_id',
                      help='identifier of the activity instance')
    parser.add_option('-o', '--object-id', dest='object_id',
                      help='identifier of the associated datastore object')
    parser.add_option('-u', '--uri', dest='uri',
                      help='URI to load')
    parser.add_option('-s', '--single-process', dest='single_process',
                      action='store_true',
                      help='start all the instances in the same process')
    parser.add_option('-i', '--invited', dest='invited',
                      action='store_true', default=False,
                      help='the activity is being launched for handling an '
                           'invite from the network')
    (options, args) = parser.parse_args()

    logger.start()

    activity_class = None
    if len(args) == 2:
        activity_class = args[1]
        os.chdir(args[0])
    elif len(args) == 1:
        if os.path.isdir(args[0]):
            os.chdir(args[0])
        else:
            activity_class = args[0]

    bundle_path = os.path.abspath(os.curdir)
    sys.path.insert(0, bundle_path)

    try:
        bundle = ActivityBundle(bundle_path)
    except MalformedBundleException:
        parser.print_help()
        exit(0)

    if not activity_class:
        command = bundle.get_command()
        if command.startswith('sugar-activity'):
            if not command.startswith('sugar-activity3'):
                logging.warning("Activity written for Python 2,\
                                consider porting to Python 3.")
            activity_class = command.split(" ")[1]

    # when an activity is started outside sugar,
    # activityfactory.get_environment has not executed in parent
    # process, so parts of get_environment must happen here.
    if 'SUGAR_BUNDLE_PATH' not in os.environ:
        profile_id = os.environ.get('SUGAR_PROFILE', 'default')
        home_dir = os.environ.get('SUGAR_HOME', os.path.expanduser('~/.sugar'))
        base = os.path.join(home_dir, profile_id)
        activity_root = os.path.join(base, bundle.get_bundle_id())

        instance_dir = os.path.join(activity_root, 'instance')
        _makedirs(instance_dir)

        data_dir = os.path.join(activity_root, 'data')
        _makedirs(data_dir)<commit_msg>Fix unnecessary whitespace in warning<commit_after># Copyright (C) 2006-2008, Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

import os
import sys
import six
import logging

# Change the default encoding to avoid UnicodeDecodeError
# http://lists.sugarlabs.org/archive/sugar-devel/2012-August/038928.html
if six.PY2:
    reload(sys)
    sys.setdefaultencoding('utf-8')

import gettext
from optparse import OptionParser

import dbus
import dbus.service
from dbus.mainloop.glib import DBusGMainLoop
DBusGMainLoop(set_as_default=True)

from sugar3.activity import activityhandle
from sugar3 import config
from sugar3.bundle.activitybundle import ActivityBundle
from sugar3 import logger

from sugar3.bundle.bundle import MalformedBundleException

from errno import EEXIST

import time
import hashlib
import random


def _makedirs(path):
    try:
        os.makedirs(path)
    except OSError as e:
        if e.errno != EEXIST:
            raise e


def create_activity_instance(constructor, handle):
    activity = constructor(handle)
    activity.show()
    return activity


def get_single_process_name(bundle_id):
    return bundle_id


def get_single_process_path(bundle_id):
    return '/' + bundle_id.replace('.', '/')


class SingleProcess(dbus.service.Object):

    def __init__(self, name_service, constructor):
        self.constructor = constructor

        bus = dbus.SessionBus()
        bus_name = dbus.service.BusName(name_service, bus=bus)
        object_path = get_single_process_path(name_service)
        dbus.service.Object.__init__(self, bus_name, object_path)

    @dbus.service.method('org.laptop.SingleProcess', in_signature='a{sv}')
    def create(self, handle_dict):
        handle = activityhandle.create_from_dict(handle_dict)
        create_activity_instance(self.constructor, handle)


def main():
    usage = 'usage: %prog [options] [activity dir] [python class]'
    epilog = 'If you are running from a directory containing an Activity, ' \
             'the argument may be omitted.  Otherwise please provide either '\
             'a directory containing a Sugar Activity [activity dir], a '\
             '[python_class], or both.'

    parser = OptionParser(usage=usage, epilog=epilog)
    parser.add_option('-b', '--bundle-id', dest='bundle_id',
                      help='identifier of the activity bundle')
    parser.add_option('-a', '--activity-id', dest='activity_id',
                      help='identifier of the activity instance')
    parser.add_option('-o', '--object-id', dest='object_id',
                      help='identifier of the associated datastore object')
    parser.add_option('-u', '--uri', dest='uri',
                      help='URI to load')
    parser.add_option('-s', '--single-process', dest='single_process',
                      action='store_true',
                      help='start all the instances in the same process')
    parser.add_option('-i', '--invited', dest='invited',
                      action='store_true', default=False,
                      help='the activity is being launched for handling an '
                           'invite from the network')
    (options, args) = parser.parse_args()

    logger.start()

    activity_class = None
    if len(args) == 2:
        activity_class = args[1]
        os.chdir(args[0])
    elif len(args) == 1:
        if os.path.isdir(args[0]):
            os.chdir(args[0])
        else:
            activity_class = args[0]

    bundle_path = os.path.abspath(os.curdir)
    sys.path.insert(0, bundle_path)

    try:
        bundle = ActivityBundle(bundle_path)
    except MalformedBundleException:
        parser.print_help()
        exit(0)

    if not activity_class:
        command = bundle.get_command()
        if command.startswith('sugar-activity'):
            if not command.startswith('sugar-activity3'):
                logging.warning("Activity written for Python 2,"
                                " consider porting to Python 3.")
            activity_class = command.split(" ")[1]

    # when an activity is started outside sugar,
    # activityfactory.get_environment has not executed in parent
    # process, so parts of get_environment must happen here.
    if 'SUGAR_BUNDLE_PATH' not in os.environ:
        profile_id = os.environ.get('SUGAR_PROFILE', 'default')
        home_dir = os.environ.get('SUGAR_HOME', os.path.expanduser('~/.sugar'))
        base = os.path.join(home_dir, profile_id)
        activity_root = os.path.join(base, bundle.get_bundle_id())

        instance_dir = os.path.join(activity_root, 'instance')
        _makedirs(instance_dir)

        data_dir = os.path.join(activity_root, 'data')
        _makedirs(data_dir)
{'fraction_non_alphanumeric': 0.09855859228753276, 'fraction_numerical': 0.009359790340696368, 'mean_word_length': 2.9239809034153508, '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': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4540996', 'n_tokens_mistral': 3133, 'n_tokens_neox': 3011, 'n_words': 897}