Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/setup.py
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@activitycentral.org>2011-06-28 09:23:54 (GMT)
committer Aleksey Lim <alsroot@activitycentral.org>2011-06-28 09:24:48 (GMT)
commit11003147ac4ea947ec5017921019d668cb4953d1 (patch)
treeeaab12347c33cb62326f9eb53121eff594301638 /setup.py
parent35278d261ace09d5ed20bdae0983730d88dd8037 (diff)
Switch to the singular sources tree and releasing scheme
Diffstat (limited to 'setup.py')
-rwxr-xr-xsetup.py149
1 files changed, 149 insertions, 0 deletions
diff --git a/setup.py b/setup.py
new file mode 100755
index 0000000..92102db
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,149 @@
+#!/usr/bin/env python
+
+# 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, see <http://www.gnu.org/licenses/>.
+
+import os
+import sys
+import shutil
+import subprocess
+from glob import glob
+from ConfigParser import ConfigParser
+from os.path import join, dirname, abspath, lexists, islink, isdir, exists
+from os.path import basename
+
+
+COMPONENTS = ['Edit', 'Jam', 'Mini', 'SynthLab']
+
+
+def link_activities(dst_root, cp_cmd):
+ for component in COMPONENTS:
+ activity_dir = join(dst_root, 'TamTam%s.activity' % component)
+
+ if lexists(activity_dir):
+ if islink(activity_dir):
+ os.unlink(activity_dir)
+ else:
+ shutil.rmtree(activity_dir)
+ os.makedirs(join(activity_dir, 'activity'))
+
+ for i in [component, 'icons', 'common', 'locale',
+ 'TamTam%s.py' % component,
+ join('activity', 'TamTam%s.svg' % component),
+ 'AUTHORS', 'COPYING', 'HACKING', 'NEWS', 'README']:
+ if exists(join(src_root, i)):
+ cp_cmd(join(src_root, i), join(activity_dir, i))
+
+ info = ConfigParser()
+ info.read(join(src_root, 'activity', 'activity.info'))
+ info.set('DEFAULT', 'component_id', component.lower())
+ info.set('DEFAULT', 'component_name', 'TamTam%s' % component)
+ for key, value in info.items('Activity'):
+ # Replace % expansions since ASLO doesn't understand them
+ info.set('Activity', key, value)
+ info_file = file(join(activity_dir, 'activity', 'activity.info'), 'w')
+ info.write(info_file)
+ info_file.close()
+ info.read(join(src_root, 'activity', 'activity.info'))
+
+ setup_file = file(join(activity_dir, 'setup.py'), 'w')
+ setup_file.write('#!/usr/bin/env python\n')
+ setup_file.write('from sugar.activity import bundlebuilder\n')
+ setup_file.write('bundlebuilder.start()\n')
+ setup_file.close()
+ os.chmod(setup_file.name, 0755)
+
+
+def walk_activities(*commands):
+ dst_root = join(src_root, '.dist')
+ link_activities(dst_root, link_tree)
+ if not exists(join(src_root, 'dist')):
+ os.makedirs(join(src_root, 'dist'))
+
+ for component in COMPONENTS:
+ for cmd in commands:
+ print '-- %s %s activity' % (' '.join(cmd), component)
+
+ activity_dir = join(dst_root, 'TamTam%s.activity' % component)
+ subprocess.check_call(['python', 'setup.py'] + cmd,
+ cwd=activity_dir)
+
+ for i in glob(join(activity_dir, 'dist', '*.xo')) + \
+ glob(join(activity_dir, 'dist', '*.tar.*')):
+ os.rename(i, join(src_root, 'dist', basename(i)))
+
+ shutil.rmtree(dst_root)
+
+
+def link_tree(src, dst):
+ if abspath(src) == abspath(dst):
+ return
+
+ do_copy = []
+
+ def link(src, dst):
+ if not exists(dirname(dst)):
+ os.makedirs(dirname(dst))
+ if do_copy:
+ shutil.copy(src, dst)
+ else:
+ try:
+ os.link(src, dst)
+ except OSError:
+ do_copy.append(True)
+ shutil.copy(src, dst)
+
+ if isdir(src):
+ for root, __, files in os.walk(src):
+ dst_root = join(dst, root[len(src):].lstrip(os.sep))
+ if not exists(dst_root):
+ os.makedirs(dst_root)
+ for i in files:
+ link(join(root, i), join(dst_root, i))
+ else:
+ link(src, dst)
+
+
+if len(sys.argv) == 1:
+ print """\
+Available commands:
+
+dev [PATH] Create symlinked activity directories in PATH
+ (default is "..") to run TamTam activities in development
+ environment from ~/Activities directory
+dist_xo Create xo bundles for all TamTam activities
+dist_source Create a tar source bundles for all TamTam activities
+install Install activities in the system; export DESTDIR
+ environment variable to set destination directory
+"""
+ exit(0)
+
+src_root = abspath(dirname(__file__))
+
+if sys.argv[1] == 'dev':
+ if len(sys.argv) > 2:
+ dst_root = sys.argv[2]
+ else:
+ dst_root = join(src_root, '..')
+ link_activities(dst_root, os.symlink)
+elif sys.argv[1] == 'dist_source':
+ from sugar.activity import bundlebuilder
+ bundlebuilder.start()
+elif sys.argv[1] == 'dist_xo':
+ walk_activities(['dist_xo'])
+elif sys.argv[1] == 'install':
+ destdir = os.environ.get('DESTDIR', '')
+ walk_activities(['build'], ['install', '--prefix=%s/usr' % destdir])
+else:
+ print 'Unknown command %s' % sys.argv[1]
+ exit(1)