Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/develop-activity/new_activity.py
blob: e9390051c94644aa5458ab37c3f8d36bd43f01d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Copyright 2008 Paul Swartz
#
# 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 shutil
import logging

from sugar.activity import activity


def class_template(name):
    name = name.replace(' ', '')
    return '%s_app' % name.lower(), '%sActivity' % name


def activity_info_template(name, web_activity=False):
    bundle_id = 'org.sugarlabs.%s' % name.replace(' ', '')
    if web_activity:
        exec_line = 'sugar-activity-web'
    else:
        exec_line = 'sugar-activity activity.HelloWorldActivity'

    return """[Activity]
name = %s
bundle_id = %s
icon = activity-helloworld
exec = %s
activity_version = 1
show_launcher = yes
""" % (name, bundle_id, exec_line)


def create_activity(name, base_path, skeleton):
    path = os.path.expanduser(os.path.join(base_path,
                              '%s.activity' % name.replace(' ', '')))
    os.makedirs(path)
    activity_path = os.path.join(path, 'activity')
    os.mkdir(activity_path)

    # copy all the files in the skeleton directory
    skeleton_path = os.path.join(activity.get_bundle_path(), 'skeletons',
                                 skeleton)
    for cur, dirs, files in os.walk(skeleton_path):
        destination_path = os.path.join(path, cur[len(skeleton_path) + 1:])
        for directory in dirs:
            directory_path = os.path.join(destination_path, directory)
            try:
                os.mkdir(directory_path)
            except:
                logging.error('Error trying to create %s', directory_path)

        for file_name in files:
            shutil.copyfile(os.path.join(cur, file_name),
                            os.path.join(destination_path, file_name))

    # create activity.info file
    activity_info_path = os.path.join(activity_path, 'activity.info')
    with open(activity_info_path, 'w') as activity_info_file:
        activity_info_file.write(activity_info_template(name,
                                                        (skeleton == 'Web')))

    return path