Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/sugar_network
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@sugarlabs.org>2014-03-11 12:25:59 (GMT)
committer Aleksey Lim <alsroot@sugarlabs.org>2014-03-11 12:25:59 (GMT)
commit47be127e9955013ddc5563013ded534cc3952ef1 (patch)
treeb3fba40ab90963e2ca6e5cdcc92ff14b4d0f33fa /sugar_network
parent41cb9e831db3d66973292fbdb4c13fb658ac9f59 (diff)
Revert multiple application commands
This time for the reason to run different commands in different environments like regular desktop, sugar shell.
Diffstat (limited to 'sugar_network')
-rw-r--r--sugar_network/db/blobs.py4
-rw-r--r--sugar_network/model/__init__.py2
-rw-r--r--sugar_network/node/model.py39
-rw-r--r--sugar_network/toolkit/spec.py18
4 files changed, 42 insertions, 21 deletions
diff --git a/sugar_network/db/blobs.py b/sugar_network/db/blobs.py
index 52bc324..084ffde 100644
--- a/sugar_network/db/blobs.py
+++ b/sugar_network/db/blobs.py
@@ -36,6 +36,10 @@ class Blobs(object):
self._root = abspath(root)
self._seqno = seqno
+ @property
+ def root(self):
+ return self._root
+
def path(self, *args):
if len(args) == 1 and len(args[0]) == 40 and '.' not in args[0]:
return self._blob_path(args[0])
diff --git a/sugar_network/model/__init__.py b/sugar_network/model/__init__.py
index bd7405d..5068a63 100644
--- a/sugar_network/model/__init__.py
+++ b/sugar_network/model/__init__.py
@@ -179,7 +179,7 @@ def load_bundle(blob, context=None, initial=False, extra_deps=None):
release['stability'] = spec['stability']
if spec['license'] is not EMPTY_LICENSE:
release['license'] = spec['license']
- release['command'] = spec.command
+ release['commands'] = spec.commands
release['requires'] = spec.requires
release['bundles'] = {
'*-*': {
diff --git a/sugar_network/node/model.py b/sugar_network/node/model.py
index 90e50c2..559f6b4 100644
--- a/sugar_network/node/model.py
+++ b/sugar_network/node/model.py
@@ -105,12 +105,13 @@ class Context(base_context.Context):
return value
-def solve(volume, top_context, lsb_id=None, lsb_release=None,
+def solve(volume, top_context, command=None, lsb_id=None, lsb_release=None,
stability=None, requires=None):
top_context = volume['context'][top_context]
- top_stability = stability or ['stable']
- if isinstance(top_stability, basestring):
- top_stability = [top_stability]
+ if stability is None:
+ stability = ['stable']
+ if isinstance(stability, basestring):
+ stability = [stability]
top_cond = []
top_requires = {}
if isinstance(requires, basestring):
@@ -129,17 +130,16 @@ def solve(volume, top_context, lsb_id=None, lsb_release=None,
clauses = []
_logger.debug('Solve %r lsb_id=%r lsb_release=%r stability=%r requires=%r',
- top_context.guid, lsb_id, lsb_release, top_stability, top_requires)
+ top_context.guid, lsb_id, lsb_release, stability, top_requires)
def rate_release(digest, release):
- return [_STABILITY_RATES.get(release['stability']) or 0,
+ return [command in release['commands'],
+ _STABILITY_RATES.get(release['stability']) or 0,
release['version'],
digest,
]
- def add_deps(context, v_usage, deps):
- if top_requires and context.guid == top_context.guid:
- deps.update(top_requires)
+ def add_deps(v_usage, deps):
for dep, cond in deps.items():
dep_clause = [-v_usage]
for v_release in add_context(dep):
@@ -178,7 +178,7 @@ def solve(volume, top_context, lsb_id=None, lsb_release=None,
if 'value' not in release:
continue
release = release['value']
- if release['stability'] not in top_stability or \
+ if release['stability'] not in stability or \
context.guid == top_context.guid and \
not spec.ensure(release['version'], top_cond):
continue
@@ -187,12 +187,27 @@ def solve(volume, top_context, lsb_id=None, lsb_release=None,
digest = release[-1]
release = releases[digest]['value']
release_info = {'version': release['version'], 'blob': digest}
+ blob = volume.blobs.get(digest)
+ if blob is not None:
+ release_info['size'] = blob.size
+ unpack_size = release['bundles']['*-*'].get('unpack_size')
+ if unpack_size is not None:
+ release_info['unpack_size'] = unpack_size
+ requires = release.get('requires') or {}
+ if top_requires and context.guid == top_context.guid:
+ requires.update(top_requires)
if context.guid == top_context.guid:
- release_info['command'] = release['command']
+ cmd = release['commands'].get(command)
+ if cmd is None:
+ cmd_name, cmd = release['commands'].items()[0]
+ else:
+ cmd_name = command
+ release_info['command'] = (cmd_name, cmd['exec'])
+ requires.update(cmd.get('requires') or {})
v_release = len(varset)
varset.append((context.guid, release_info))
clause.append(v_release)
- add_deps(context, v_release, release.get('requires') or {})
+ add_deps(v_release, requires)
if clause:
context_clauses[context.guid] = clause
diff --git a/sugar_network/toolkit/spec.py b/sugar_network/toolkit/spec.py
index a8489ce..bd852d4 100644
--- a/sugar_network/toolkit/spec.py
+++ b/sugar_network/toolkit/spec.py
@@ -193,7 +193,7 @@ class Spec(object):
def __init__(self, spec=None, root=None):
self.path = None
- self.command = None
+ self.commands = {}
self.bindings = set()
self.requires = {}
self.build_requires = []
@@ -276,8 +276,7 @@ class Spec(object):
if section_type == 'Activity':
self._new_activity(section, requires)
elif section_type == 'Application':
- cmd_name = section.split(':')[-1] if ':' in section else 'run'
- self._new_command(section, requires, cmd_name)
+ self._new_command(section, requires)
self.applications.append(_Application(self._config, section))
elif section_type == 'Library':
enforce(':' not in section, '[Library] should be singular')
@@ -347,13 +346,16 @@ class Spec(object):
for i in self.applications:
i.name = '-'.join(i.section.split(':')[1:])
- def _new_command(self, section, requires, name):
- enforce(self.command is None, 'Only one command is allowed')
+ def _new_command(self, section, requires):
cmdline = self._get(section, 'exec')
enforce(cmdline,
'Option "exec" should exist for [%s] section', section)
- self.command = cmdline
- self.requires.update(requires)
+ name = section.split(':')[-1] if ':' in section else section.lower()
+ command = self.commands[name] = {'exec': cmdline}
+ if ':' in section:
+ command['requires'] = requires
+ else:
+ self.requires.update(requires)
def _new_activity(self, section, requires):
enforce(':' not in section, '[Activity] should be singular')
@@ -372,7 +374,7 @@ class Spec(object):
enforce(self._get(section, key),
'Option "%s" should exist for activities', key)
- self._new_command(section, requires, 'activity')
+ self._new_command(section, requires)
self.activity = _Activity(self._config, section)
def _new_archive(self, section):