Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/sugar
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@localhost.localdomain>2008-05-25 20:47:34 (GMT)
committer Marco Pesenti Gritti <marco@localhost.localdomain>2008-05-25 20:47:34 (GMT)
commit95b7098120cabd5d59bfae2a3e863009d4de6d5d (patch)
tree726d922e48ed98dceb5d8a3bf69c5688cd2da760 /src/sugar
parentd06bf0528781727b821dd4d3fe0deaad76151191 (diff)
Split the packaging code out to XOPackager
Diffstat (limited to 'src/sugar')
-rw-r--r--src/sugar/activity/bundlebuilder.py160
1 files changed, 85 insertions, 75 deletions
diff --git a/src/sugar/activity/bundlebuilder.py b/src/sugar/activity/bundlebuilder.py
index 53bd0ed..092e68d 100644
--- a/src/sugar/activity/bundlebuilder.py
+++ b/src/sugar/activity/bundlebuilder.py
@@ -26,6 +26,66 @@ from optparse import OptionParser
from sugar import env
from sugar.bundle.activitybundle import ActivityBundle
+class _DefaultFileList(list):
+ def __init__(self):
+ for name in os.listdir('activity'):
+ if name.endswith('.svg'):
+ self.append(os.path.join('activity', name))
+
+ self.append('activity/activity.info')
+
+class _ManifestFileList(_DefaultFileList):
+ def __init__(self, manifest):
+ _DefaultFileList.__init__(self)
+ self.append(manifest)
+
+ f = open(manifest,'r')
+ for line in f.readlines():
+ stripped_line = line.strip()
+ if stripped_line and not stripped_line in self:
+ self.append(stripped_line)
+ f.close()
+
+class _AllFileList(list):
+ def __init__(self):
+ for root, dirs, files in os.walk('.'):
+ if not root.startswith('./locale'):
+ for f in files:
+ if not f.endswith('.xo') and \
+ f != '.gitignore':
+ self.append(os.path.join(root, f))
+
+def _get_file_list(manifest):
+ if os.path.isfile(manifest):
+ return _ManifestFileList(manifest)
+ elif os.path.isdir('.git'):
+ return _GitFileList()
+ elif os.path.isdir('.svn'):
+ return _SvnFileList()
+ else:
+ return _AllFileList()
+
+def _get_po_list(manifest):
+ file_list = {}
+
+ po_regex = re.compile("po/(.*)\.po$")
+ for file_name in _get_file_list(manifest):
+ match = po_regex.match(file_name)
+ if match:
+ file_list[match.group(1)] = file_name
+
+ return file_list
+
+def _get_l10n_list(config):
+ l10n_list = []
+
+ for lang in _get_po_list(config.manifest).keys():
+ filename = config.bundle_id + '.mo'
+ l10n_list.append(os.path.join('locale', lang, 'LC_MESSAGES', filename))
+ l10n_list.append(os.path.join('locale', lang, 'activity.linfo'))
+
+ return l10n_list
+
class Config(object):
def __init__(self, bundle_name, manifest):
self.bundle_name = bundle_name
@@ -75,6 +135,25 @@ class Builder(object):
f.write('[Activity]\nname = %s\n' % translated_name)
f.close()
+class XOPackager(object):
+ def __init__(self, config):
+ self.config = config
+
+ def package(self):
+ file_list = _get_file_list(self.config.manifest)
+
+ zipname = self.config.xo_name
+ bundle_zip = zipfile.ZipFile(zipname, 'w', zipfile.ZIP_DEFLATED)
+ base_dir = self.config.bundle_root_dir
+
+ for filename in file_list:
+ bundle_zip.write(filename, os.path.join(base_dir, filename))
+
+ for filename in _get_l10n_list(self.config):
+ bundle_zip.write(filename, os.path.join(base_dir, filename))
+
+ bundle_zip.close()
+
class _SvnFileList(list):
def __init__(self):
f = os.popen('svn list -R')
@@ -93,66 +172,6 @@ class _GitFileList(list):
self.append(filename)
f.close()
-class _DefaultFileList(list):
- def __init__(self):
- for name in os.listdir('activity'):
- if name.endswith('.svg'):
- self.append(os.path.join('activity', name))
-
- self.append('activity/activity.info')
-
-class _ManifestFileList(_DefaultFileList):
- def __init__(self, manifest):
- _DefaultFileList.__init__(self)
- self.append(manifest)
-
- f = open(manifest,'r')
- for line in f.readlines():
- stripped_line = line.strip()
- if stripped_line and not stripped_line in self:
- self.append(stripped_line)
- f.close()
-
-class _AllFileList(list):
- def __init__(self):
- for root, dirs, files in os.walk('.'):
- if not root.startswith('./locale'):
- for f in files:
- if not f.endswith('.xo') and \
- f != '.gitignore':
- self.append(os.path.join(root, f))
-
-def _get_file_list(manifest):
- if os.path.isfile(manifest):
- return _ManifestFileList(manifest)
- elif os.path.isdir('.git'):
- return _GitFileList()
- elif os.path.isdir('.svn'):
- return _SvnFileList()
- else:
- return _AllFileList()
-
-def _get_po_list(manifest):
- file_list = {}
-
- po_regex = re.compile("po/(.*)\.po$")
- for file_name in _get_file_list(manifest):
- match = po_regex.match(file_name)
- if match:
- file_list[match.group(1)] = file_name
-
- return file_list
-
-def _get_l10n_list(config):
- l10n_list = []
-
- for lang in _get_po_list(config.manifest).keys():
- filename = config.bundle_id + '.mo'
- l10n_list.append(os.path.join('locale', lang, 'LC_MESSAGES', filename))
- l10n_list.append(os.path.join('locale', lang, 'activity.linfo'))
-
- return l10n_list
-
def cmd_help(config, options, args):
print 'Usage: \n\
setup.py build - build generated files \n\
@@ -182,24 +201,14 @@ def cmd_dist(config, options, args):
builder = Builder(config)
builder.build()
- file_list = _get_file_list(config.manifest)
-
- zipname = config.xo_name
- bundle_zip = zipfile.ZipFile(zipname, 'w', zipfile.ZIP_DEFLATED)
- base_dir = config.bundle_root_dir
-
- for filename in file_list:
- bundle_zip.write(filename, os.path.join(base_dir, filename))
-
- for filename in _get_l10n_list(config):
- bundle_zip.write(filename, os.path.join(base_dir, filename))
-
- bundle_zip.close()
+ packager = XOPackager(config)
+ packager.package()
def cmd_install(config, options, args):
path = args[0]
- cmd_dist(config, options, args)
+ packager = XOPackager(config)
+ packager.package()
root_path = os.path.join(args[0], config.bundle_root_dir)
if os.path.isdir(root_path):
@@ -329,7 +338,8 @@ def cmd_release(config, options, args):
print 'ERROR - cannot push to git'
print 'Creating the bundle...'
- cmd_dist(config, options, args)
+ packager = XOPackager(config)
+ packager.package()
print 'Done.'