Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/sugar/setup.py
blob: e4d8ae7a2aaceb21cc67ecd729c122e706c21bb2 (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/python

# Copyright (C) 2006, Red Hat, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.

import os
import sys
import shutil
import logging
from ConfigParser import ConfigParser
from ConfigParser import NoOptionError

class ServiceParser(ConfigParser):
	def optionxform(self, option):
		return option

def write_service(name, bin, path):
	service_cp = ServiceParser()
	section = 'D-BUS Service'	
	service_cp.add_section(section)
	service_cp.set(section, 'Name', name)
	service_cp.set(section, 'Exec', bin)

	dest_filename = os.path.join(path, name + '.service')
	fileobject = open(dest_filename, 'w')
	service_cp.write(fileobject)
	fileobject.close()

def setup_activity(source, dest_path, bin):
	"""Copy an activity to the destination path and setup it"""
	filename = os.path.basename(source)
	dest = os.path.join(dest_path, filename)
	print 'Install ' + filename + ' ...'
	shutil.copyfile(source, dest)

	cp = ConfigParser()
	cp.read([source])

	try:
		activity_id = cp.get('Activity', 'id')
	except NoOptionError:
		logging.error('%s miss the required id option' % (path))
		return False
	
	if cp.has_option('Activity', 'exec'):
		activity_exec = cp.get('Activity', 'exec')
	elif cp.has_option('Activity', 'python_module'):
		python_module = cp.get('Activity', 'python_module')
		python_module = cp.get('Activity', 'python_module')
		activity_exec = '%s %s %s' % (bin, activity_id, python_module)
	else:
		logging.error('%s must specifiy exec or python_module' % (source))
		return False

	write_service(activity_id + '.Factory', activity_exec, dest_path)

def setup_activities(source_path, dest_path, bin):
	"""Scan a directory for activities and install them."""
	if not os.path.isdir(dest_path):
		os.mkdir(dest_path)
	else:
		# FIXME delete the whole directory
		pass

	if os.path.isdir(source_path):
		for filename in os.listdir(source_path):
			activity_dir = os.path.join(source_path, filename)
			if os.path.isdir(activity_dir):
				for filename in os.listdir(activity_dir):
					if filename.endswith(".activity"):
						source = os.path.join(activity_dir, filename)
						setup_activity(source, dest_path, bin)

if __name__=='__main__':
	setup_activities(sys.argv[1], sys.argv[2], sys.argv[3])