2006-07-28 01:25:08 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2006-08-12 23:47:14 +02:00
|
|
|
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()
|
|
|
|
|
2006-08-04 15:54:28 +02:00
|
|
|
def setup_activity(source, dest_path, bin):
|
|
|
|
"""Copy an activity to the destination path and setup it"""
|
|
|
|
filename = os.path.basename(source)
|
2006-07-28 01:25:08 +02:00
|
|
|
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
|
|
|
|
|
2006-08-12 23:47:14 +02:00
|
|
|
write_service(activity_id + '.Factory', activity_exec, dest_path)
|
2006-07-28 01:25:08 +02:00
|
|
|
|
2006-08-04 15:54:28 +02:00
|
|
|
def setup_activities(source_path, dest_path, bin):
|
2006-08-12 23:35:52 +02:00
|
|
|
"""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
|
|
|
|
|
2006-07-28 01:25:08 +02:00
|
|
|
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"):
|
2006-08-04 15:54:28 +02:00
|
|
|
source = os.path.join(activity_dir, filename)
|
|
|
|
setup_activity(source, dest_path, bin)
|
2006-07-28 01:25:08 +02:00
|
|
|
|
|
|
|
if __name__=='__main__':
|
2006-08-04 15:54:28 +02:00
|
|
|
setup_activities(sys.argv[1], sys.argv[2], sys.argv[3])
|