Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@sugarlabs.org>2012-09-28 19:14:14 (GMT)
committer Aleksey Lim <alsroot@sugarlabs.org>2012-09-28 19:14:14 (GMT)
commited116a71e3b3ad78a2f36a9c81075e70eeb24ddd (patch)
treeca2452770ca42d0f94c2e4a2578a18952a524d23
parent7f1bdbda6000e96901ad01badbb58c6cbdf8a73c (diff)
Remove needless slots to speed up xapian index; index Implementation.version with preserving order
-rw-r--r--doc/objects.dia137
-rw-r--r--sugar_network/node/router.py2
-rw-r--r--sugar_network/resources/artifact.py3
-rw-r--r--sugar_network/resources/context.py15
-rw-r--r--sugar_network/resources/feedback.py2
-rw-r--r--sugar_network/resources/implementation.py19
-rw-r--r--sugar_network/resources/notification.py8
-rw-r--r--sugar_network/resources/user.py8
-rw-r--r--sugar_network/resources/volume.py35
-rw-r--r--tests/units/__main__.py1
-rwxr-xr-xtests/units/datastore.py6
-rwxr-xr-xtests/units/implementation.py51
-rwxr-xr-xtests/units/volume.py6
13 files changed, 174 insertions, 119 deletions
diff --git a/doc/objects.dia b/doc/objects.dia
index 2ec73f6..4da4476 100644
--- a/doc/objects.dia
+++ b/doc/objects.dia
@@ -90,7 +90,7 @@
<dia:point val="30,11"/>
</dia:attribute>
<dia:attribute name="obj_bb">
- <dia:rectangle val="29.985,10.985;49.2275,45.415"/>
+ <dia:rectangle val="29.985,10.985;49.2275,43.415"/>
</dia:attribute>
<dia:attribute name="elem_corner">
<dia:point val="30,11"/>
@@ -99,7 +99,7 @@
<dia:real val="19.212499999999999"/>
</dia:attribute>
<dia:attribute name="elem_height">
- <dia:real val="34.400000000000006"/>
+ <dia:real val="32.400000000000006"/>
</dia:attribute>
<dia:attribute name="name">
<dia:string>#Context#</dia:string>
@@ -197,7 +197,7 @@
<dia:string>#type#</dia:string>
</dia:attribute>
<dia:attribute name="type">
- <dia:string>#[enum] [R WN S F]#</dia:string>
+ <dia:string>#[enum] [R WN]#</dia:string>
</dia:attribute>
<dia:attribute name="value">
<dia:string>##</dia:string>
@@ -217,33 +217,10 @@
</dia:composite>
<dia:composite type="umlattribute">
<dia:attribute name="name">
- <dia:string>#name#</dia:string>
- </dia:attribute>
- <dia:attribute name="type">
- <dia:string>#str [R WE S F]#</dia:string>
- </dia:attribute>
- <dia:attribute name="value">
- <dia:string>#""#</dia:string>
- </dia:attribute>
- <dia:attribute name="comment">
- <dia:string>#Sugar Network name associated with the Context#</dia:string>
- </dia:attribute>
- <dia:attribute name="visibility">
- <dia:enum val="0"/>
- </dia:attribute>
- <dia:attribute name="abstract">
- <dia:boolean val="false"/>
- </dia:attribute>
- <dia:attribute name="class_scope">
- <dia:boolean val="false"/>
- </dia:attribute>
- </dia:composite>
- <dia:composite type="umlattribute">
- <dia:attribute name="name">
<dia:string>#implement#</dia:string>
</dia:attribute>
<dia:attribute name="type">
- <dia:string>#[str] [R WA F]#</dia:string>
+ <dia:string>#[str] [R WA]#</dia:string>
</dia:attribute>
<dia:attribute name="value">
<dia:string>#[]#</dia:string>
@@ -473,7 +450,7 @@
<dia:string>#keep#</dia:string>
</dia:attribute>
<dia:attribute name="type">
- <dia:string>#bool [R W S L]#</dia:string>
+ <dia:string>#bool [R W L]#</dia:string>
</dia:attribute>
<dia:attribute name="value">
<dia:string>#False#</dia:string>
@@ -496,7 +473,7 @@
<dia:string>#keep_impl#</dia:string>
</dia:attribute>
<dia:attribute name="type">
- <dia:string>#int [R W S L]#</dia:string>
+ <dia:string>#int [R W L]#</dia:string>
</dia:attribute>
<dia:attribute name="value">
<dia:string>#0#</dia:string>
@@ -526,13 +503,13 @@
<dia:point val="-2,10"/>
</dia:attribute>
<dia:attribute name="obj_bb">
- <dia:rectangle val="-2.015,9.985;10.065,37.615"/>
+ <dia:rectangle val="-2.015,9.985;9.5475,37.615"/>
</dia:attribute>
<dia:attribute name="elem_corner">
<dia:point val="-2,10"/>
</dia:attribute>
<dia:attribute name="elem_width">
- <dia:real val="12.050000000000001"/>
+ <dia:real val="11.532500000000001"/>
</dia:attribute>
<dia:attribute name="elem_height">
<dia:real val="27.600000000000001"/>
@@ -633,7 +610,7 @@
<dia:string>#guid#</dia:string>
</dia:attribute>
<dia:attribute name="type">
- <dia:string>#str [R S]#</dia:string>
+ <dia:string>#str [R]#</dia:string>
</dia:attribute>
<dia:attribute name="value">
<dia:string>##</dia:string>
@@ -702,7 +679,7 @@
<dia:string>#tags#</dia:string>
</dia:attribute>
<dia:attribute name="type">
- <dia:string>#[str] [R WA S F]#</dia:string>
+ <dia:string>#[str] [R WA F]#</dia:string>
</dia:attribute>
<dia:attribute name="value">
<dia:string>#[]#</dia:string>
@@ -794,7 +771,7 @@
<dia:string>#location#</dia:string>
</dia:attribute>
<dia:attribute name="type">
- <dia:string>#str [R WA F S]#</dia:string>
+ <dia:string>#str [R WA F]#</dia:string>
</dia:attribute>
<dia:attribute name="value">
<dia:string>#""#</dia:string>
@@ -847,13 +824,13 @@
<dia:point val="12,10"/>
</dia:attribute>
<dia:attribute name="obj_bb">
- <dia:rectangle val="11.985,9.985;24.065,36.015"/>
+ <dia:rectangle val="11.985,9.985;23.785,36.015"/>
</dia:attribute>
<dia:attribute name="elem_corner">
<dia:point val="12,10"/>
</dia:attribute>
<dia:attribute name="elem_width">
- <dia:real val="12.050000000000001"/>
+ <dia:real val="11.77"/>
</dia:attribute>
<dia:attribute name="elem_height">
<dia:real val="26"/>
@@ -954,7 +931,7 @@
<dia:string>#guid#</dia:string>
</dia:attribute>
<dia:attribute name="type">
- <dia:string>#str [R S]#</dia:string>
+ <dia:string>#str [R]#</dia:string>
</dia:attribute>
<dia:attribute name="value">
<dia:string>##</dia:string>
@@ -1023,7 +1000,7 @@
<dia:string>#user#</dia:string>
</dia:attribute>
<dia:attribute name="type">
- <dia:string>#[User] [R WA S]#</dia:string>
+ <dia:string>#[User] [R WA]#</dia:string>
</dia:attribute>
<dia:attribute name="value">
<dia:string>##</dia:string>
@@ -1069,7 +1046,7 @@
<dia:string>#layer#</dia:string>
</dia:attribute>
<dia:attribute name="type">
- <dia:string>#[enum] [R WA S F]#</dia:string>
+ <dia:string>#[enum] [R WA]#</dia:string>
</dia:attribute>
<dia:attribute name="value">
<dia:string>#[]#</dia:string>
@@ -1092,7 +1069,7 @@
<dia:string>#tags#</dia:string>
</dia:attribute>
<dia:attribute name="type">
- <dia:string>#[str] [R WA S F]#</dia:string>
+ <dia:string>#[str] [R WA F]#</dia:string>
</dia:attribute>
<dia:attribute name="value">
<dia:string>#[]#</dia:string>
@@ -1119,17 +1096,17 @@
</dia:object>
<dia:object type="UML - Association" version="2" id="O3">
<dia:attribute name="obj_pos">
- <dia:point val="49.2267,28.2"/>
+ <dia:point val="49.2267,27.2"/>
</dia:attribute>
<dia:attribute name="obj_bb">
- <dia:rectangle val="49.209,27.44;53.0176,54.84"/>
+ <dia:rectangle val="49.209,26.44;53.0176,54.84"/>
</dia:attribute>
<dia:attribute name="meta">
<dia:composite type="dict"/>
</dia:attribute>
<dia:attribute name="orth_points">
- <dia:point val="49.2267,28.2"/>
- <dia:point val="51,28.2"/>
+ <dia:point val="49.2267,27.2"/>
+ <dia:point val="51,27.2"/>
<dia:point val="51,54"/>
<dia:point val="53,54"/>
</dia:attribute>
@@ -1193,7 +1170,7 @@
<dia:color val="#000000ff"/>
</dia:attribute>
<dia:connections>
- <dia:connection handle="0" to="O0" connection="36"/>
+ <dia:connection handle="0" to="O0" connection="34"/>
</dia:connections>
</dia:object>
<dia:object type="UML - Association" version="2" id="O4">
@@ -1278,17 +1255,17 @@
</dia:object>
<dia:object type="UML - Association" version="2" id="O5">
<dia:attribute name="obj_pos">
- <dia:point val="39.6063,45.4"/>
+ <dia:point val="39.6063,43.4"/>
</dia:attribute>
<dia:attribute name="obj_bb">
- <dia:rectangle val="39.4824,44.64;40.1,49.84"/>
+ <dia:rectangle val="39.4824,42.64;40.1,49.84"/>
</dia:attribute>
<dia:attribute name="meta">
<dia:composite type="dict"/>
</dia:attribute>
<dia:attribute name="orth_points">
- <dia:point val="39.6063,45.4"/>
- <dia:point val="40,45.4"/>
+ <dia:point val="39.6063,43.4"/>
+ <dia:point val="40,43.4"/>
<dia:point val="40,49"/>
<dia:point val="39.5,49"/>
</dia:attribute>
@@ -1358,17 +1335,17 @@
</dia:object>
<dia:object type="UML - Association" version="2" id="O6">
<dia:attribute name="obj_pos">
- <dia:point val="29.9847,28.2"/>
+ <dia:point val="29.9847,27.2"/>
</dia:attribute>
<dia:attribute name="obj_bb">
- <dia:rectangle val="26.9824,27.44;30.0023,54.84"/>
+ <dia:rectangle val="26.9824,26.44;30.0023,54.84"/>
</dia:attribute>
<dia:attribute name="meta">
<dia:composite type="dict"/>
</dia:attribute>
<dia:attribute name="orth_points">
- <dia:point val="29.9847,28.2"/>
- <dia:point val="28.4924,28.2"/>
+ <dia:point val="29.9847,27.2"/>
+ <dia:point val="28.4924,27.2"/>
<dia:point val="28.4924,54"/>
<dia:point val="27,54"/>
</dia:attribute>
@@ -1432,7 +1409,7 @@
<dia:color val="#000000ff"/>
</dia:attribute>
<dia:connections>
- <dia:connection handle="0" to="O0" connection="36"/>
+ <dia:connection handle="0" to="O0" connection="34"/>
</dia:connections>
</dia:object>
<dia:object type="UML - Association" version="2" id="O7">
@@ -1563,13 +1540,13 @@
<dia:point val="11,45"/>
</dia:attribute>
<dia:attribute name="obj_bb">
- <dia:rectangle val="10.985,44.985;24.22,59.815"/>
+ <dia:rectangle val="10.985,44.985;23.45,59.815"/>
</dia:attribute>
<dia:attribute name="elem_corner">
<dia:point val="11,45"/>
</dia:attribute>
<dia:attribute name="elem_width">
- <dia:real val="13.205"/>
+ <dia:real val="12.434999999999999"/>
</dia:attribute>
<dia:attribute name="elem_height">
<dia:real val="14.800000000000001"/>
@@ -1762,7 +1739,7 @@
<dia:string>#solution#</dia:string>
</dia:attribute>
<dia:attribute name="type">
- <dia:string>#Solution [R WA S]#</dia:string>
+ <dia:string>#Solution [R WA]#</dia:string>
</dia:attribute>
<dia:attribute name="value">
<dia:string>#""#</dia:string>
@@ -1899,7 +1876,7 @@
<dia:string>#feedback#</dia:string>
</dia:attribute>
<dia:attribute name="type">
- <dia:string>#Feedback [R WN S]#</dia:string>
+ <dia:string>#Feedback [R WN]#</dia:string>
</dia:attribute>
<dia:attribute name="value">
<dia:string>##</dia:string>
@@ -1949,17 +1926,17 @@
</dia:object>
<dia:object type="UML - Association" version="2" id="O11">
<dia:attribute name="obj_pos">
- <dia:point val="17.6025,59.8"/>
+ <dia:point val="17.2175,59.8"/>
</dia:attribute>
<dia:attribute name="obj_bb">
- <dia:rectangle val="17.5849,59.7824;20.4412,64.7856"/>
+ <dia:rectangle val="17.1999,59.7824;20.4413,64.7856"/>
</dia:attribute>
<dia:attribute name="meta">
<dia:composite type="dict"/>
</dia:attribute>
<dia:attribute name="orth_points">
- <dia:point val="17.6025,59.8"/>
- <dia:point val="17.6025,62"/>
+ <dia:point val="17.2175,59.8"/>
+ <dia:point val="17.2175,62"/>
<dia:point val="19.8562,62"/>
<dia:point val="19.8562,63.9856"/>
</dia:attribute>
@@ -2076,13 +2053,13 @@
<dia:point val="33,69"/>
</dia:attribute>
<dia:attribute name="obj_bb">
- <dia:rectangle val="32.985,68.985;45.45,79.815"/>
+ <dia:rectangle val="32.985,68.985;44.68,79.815"/>
</dia:attribute>
<dia:attribute name="elem_corner">
<dia:point val="33,69"/>
</dia:attribute>
<dia:attribute name="elem_width">
- <dia:real val="12.434999999999999"/>
+ <dia:real val="11.665000000000001"/>
</dia:attribute>
<dia:attribute name="elem_height">
<dia:real val="10.800000000000001"/>
@@ -2183,7 +2160,7 @@
<dia:string>#parent_resource#</dia:string>
</dia:attribute>
<dia:attribute name="type">
- <dia:string>#enum [R WN S]#</dia:string>
+ <dia:string>#enum [R WN]#</dia:string>
</dia:attribute>
<dia:attribute name="value">
<dia:string>##</dia:string>
@@ -2206,7 +2183,7 @@
<dia:string>#parent#</dia:string>
</dia:attribute>
<dia:attribute name="type">
- <dia:string>#guid [R WN S]#</dia:string>
+ <dia:string>#guid [R WN]#</dia:string>
</dia:attribute>
<dia:attribute name="value">
<dia:string>##</dia:string>
@@ -2366,7 +2343,7 @@
<dia:string>#type#</dia:string>
</dia:attribute>
<dia:attribute name="type">
- <dia:string>#enum [R WN S]#</dia:string>
+ <dia:string>#enum [R WN]#</dia:string>
</dia:attribute>
<dia:attribute name="value">
<dia:string>##</dia:string>
@@ -2389,7 +2366,7 @@
<dia:string>#resource#</dia:string>
</dia:attribute>
<dia:attribute name="type">
- <dia:string>#enum [R WN S]#</dia:string>
+ <dia:string>#enum [R WN]#</dia:string>
</dia:attribute>
<dia:attribute name="value">
<dia:string>#""#</dia:string>
@@ -2412,7 +2389,7 @@
<dia:string>#object#</dia:string>
</dia:attribute>
<dia:attribute name="type">
- <dia:string>#str [R WN S]#</dia:string>
+ <dia:string>#str [R WN]#</dia:string>
</dia:attribute>
<dia:attribute name="value">
<dia:string>#""#</dia:string>
@@ -2435,7 +2412,7 @@
<dia:string>#to#</dia:string>
</dia:attribute>
<dia:attribute name="type">
- <dia:string>#User [R WN S]#</dia:string>
+ <dia:string>#User [R WN]#</dia:string>
</dia:attribute>
<dia:attribute name="value">
<dia:string>#""#</dia:string>
@@ -2662,7 +2639,7 @@
<dia:string>#keep#</dia:string>
</dia:attribute>
<dia:attribute name="type">
- <dia:string>#bool [R W S L]#</dia:string>
+ <dia:string>#bool [R W L]#</dia:string>
</dia:attribute>
<dia:attribute name="value">
<dia:string>#false#</dia:string>
@@ -2708,7 +2685,7 @@
<dia:string>#title#</dia:string>
</dia:attribute>
<dia:attribute name="type">
- <dia:string>#str [R WA F I]#</dia:string>
+ <dia:string>#str [R WA S F I]#</dia:string>
</dia:attribute>
<dia:attribute name="value">
<dia:string>#""#</dia:string>
@@ -2754,7 +2731,7 @@
<dia:string>#activity_id#</dia:string>
</dia:attribute>
<dia:attribute name="type">
- <dia:string>#str [R WA S]#</dia:string>
+ <dia:string>#str [R WA]#</dia:string>
</dia:attribute>
<dia:attribute name="value">
<dia:string>#""#</dia:string>
@@ -3075,7 +3052,7 @@
<dia:string>#stability#</dia:string>
</dia:attribute>
<dia:attribute name="type">
- <dia:string>#enum [R WN S F]#</dia:string>
+ <dia:string>#enum [R WN F]#</dia:string>
</dia:attribute>
<dia:attribute name="value">
<dia:string>##</dia:string>
@@ -3151,13 +3128,13 @@
<dia:point val="65,64"/>
</dia:attribute>
<dia:attribute name="obj_bb">
- <dia:rectangle val="64.985,63.985;82.84,80.015"/>
+ <dia:rectangle val="64.985,63.985;82.07,80.015"/>
</dia:attribute>
<dia:attribute name="elem_corner">
<dia:point val="65,64"/>
</dia:attribute>
<dia:attribute name="elem_width">
- <dia:real val="17.824999999999999"/>
+ <dia:real val="17.055"/>
</dia:attribute>
<dia:attribute name="elem_height">
<dia:real val="16.000000000000004"/>
@@ -3258,7 +3235,7 @@
<dia:string>#context#</dia:string>
</dia:attribute>
<dia:attribute name="type">
- <dia:string>#guid [R WN S]#</dia:string>
+ <dia:string>#guid [R WN]#</dia:string>
</dia:attribute>
<dia:attribute name="value">
<dia:string>##</dia:string>
@@ -3281,7 +3258,7 @@
<dia:string>#implementation#</dia:string>
</dia:attribute>
<dia:attribute name="type">
- <dia:string>#Implementation [R WN S]#</dia:string>
+ <dia:string>#Implementation [R WN]#</dia:string>
</dia:attribute>
<dia:attribute name="value">
<dia:string>#""#</dia:string>
@@ -3730,12 +3707,12 @@
<dia:point val="63,20.3"/>
</dia:attribute>
<dia:attribute name="obj_bb">
- <dia:rectangle val="63,19.705;80.6425,20.45"/>
+ <dia:rectangle val="63,19.6864;82.6911,20.4873"/>
</dia:attribute>
<dia:attribute name="text">
<dia:composite type="text">
<dia:attribute name="string">
- <dia:string>#[S] Property can be used in exact search and sorting#</dia:string>
+ <dia:string>#[S] Property can be sorted, grouped or searched by ranges#</dia:string>
</dia:attribute>
<dia:attribute name="font">
<dia:font family="sans" style="0" name="Helvetica"/>
diff --git a/sugar_network/node/router.py b/sugar_network/node/router.py
index 44aaf25..d51713e 100644
--- a/sugar_network/node/router.py
+++ b/sugar_network/node/router.py
@@ -55,7 +55,7 @@ class Router(router.Router):
directory = self.commands.volume['context']
documents, total = directory.find(type='package',
offset=request.get('offset'), limit=request.get('limit'))
- return {'total': total.value, 'result': [i.guid for i in documents]}
+ return {'total': total, 'result': [i.guid for i in documents]}
def _get_package(self, repo, package):
directory = self.commands.volume['context']
diff --git a/sugar_network/resources/artifact.py b/sugar_network/resources/artifact.py
index 8fd35b6..1adaa32 100644
--- a/sugar_network/resources/artifact.py
+++ b/sugar_network/resources/artifact.py
@@ -22,6 +22,9 @@ from sugar_network.resources.volume import Resource
class Artifact(Resource):
+ # All properties are sloted to not fail on `get_uniquevaluesfor()` call
+ # while emulating sugar-datastore interface
+
@ad.active_property(slot=1, prefix='C', default='')
def context(self, value):
return value
diff --git a/sugar_network/resources/context.py b/sugar_network/resources/context.py
index 1745a82..5683664 100644
--- a/sugar_network/resources/context.py
+++ b/sugar_network/resources/context.py
@@ -31,11 +31,6 @@ class Context(Resource):
def type(self, value):
return value
- @ad.active_property(slot=1, prefix='N', full_text=True,
- permissions=ad.ACCESS_READ, default='')
- def name(self, value):
- return value
-
@ad.active_property(prefix='M',
full_text=True, default=[], typecast=[])
def implement(self, value):
@@ -136,6 +131,16 @@ class Context(Resource):
return versions
+ @ad.active_property(ad.StoredProperty, typecast=[], default=[])
+ def dependencies(self, value):
+ """Software dependencies.
+
+ This is a transition method how to improve dependencies handling.
+ The regular way should be setting up them in activity.info instead.
+
+ """
+ return value
+
@ad.active_property(ad.StoredProperty, typecast=dict, default={})
def aliases(self, value):
return value
diff --git a/sugar_network/resources/feedback.py b/sugar_network/resources/feedback.py
index 87f6b8a..e7309c0 100644
--- a/sugar_network/resources/feedback.py
+++ b/sugar_network/resources/feedback.py
@@ -39,6 +39,6 @@ class Feedback(Resource):
def content(self, value):
return value
- @ad.active_property(slot=3, prefix='A', default='')
+ @ad.active_property(prefix='A', default='')
def solution(self, value):
return value
diff --git a/sugar_network/resources/implementation.py b/sugar_network/resources/implementation.py
index 1a6c3f1..b5dc774 100644
--- a/sugar_network/resources/implementation.py
+++ b/sugar_network/resources/implementation.py
@@ -19,9 +19,22 @@ import active_document as ad
from sugar_network.zerosugar import GOOD_LICENSES
from sugar_network import resources
+from sugar_network.zerosugar import parse_version
from sugar_network.resources.volume import Resource
+def _encode_version(version):
+ result = ''
+ version = parse_version(version)
+ while version:
+ unit, modificator = version[:2]
+ del version[:2]
+ unit = ([0, 0] + unit)[-3:]
+ result += ''.join(['%05d' % i for i in unit])
+ result += '%02d' % (10 + modificator)
+ return result
+
+
class Implementation(Resource):
@ad.active_property(prefix='C',
@@ -34,17 +47,17 @@ class Implementation(Resource):
def license(self, value):
return value
- @ad.active_property(slot=2, prefix='V',
+ @ad.active_property(slot=1, prefix='V', reprcast=_encode_version,
permissions=ad.ACCESS_CREATE | ad.ACCESS_READ)
def version(self, value):
return value
- @ad.active_property(slot=3, prefix='D',
+ @ad.active_property(slot=2, prefix='D',
permissions=ad.ACCESS_CREATE | ad.ACCESS_READ, typecast=int)
def date(self, value):
return value
- @ad.active_property(slot=4, prefix='S', full_text=True,
+ @ad.active_property(prefix='S',
permissions=ad.ACCESS_CREATE | ad.ACCESS_READ,
typecast=resources.STABILITIES)
def stability(self, value):
diff --git a/sugar_network/resources/notification.py b/sugar_network/resources/notification.py
index f357b9c..4b78d75 100644
--- a/sugar_network/resources/notification.py
+++ b/sugar_network/resources/notification.py
@@ -21,24 +21,24 @@ from sugar_network.resources.volume import Resource
class Notification(Resource):
- @ad.active_property(slot=1, prefix='T',
+ @ad.active_property(prefix='T',
permissions=ad.ACCESS_CREATE | ad.ACCESS_READ,
typecast=resources.NOTIFICATION_TYPES)
def type(self, value):
return value
- @ad.active_property(slot=2, prefix='K',
+ @ad.active_property(prefix='K',
permissions=ad.ACCESS_CREATE | ad.ACCESS_READ,
default='', typecast=resources.NOTIFICATION_OBJECT_TYPES)
def resource(self, value):
return value
- @ad.active_property(slot=3, prefix='O',
+ @ad.active_property(prefix='O',
permissions=ad.ACCESS_CREATE | ad.ACCESS_READ, default='')
def object(self, value):
return value
- @ad.active_property(slot=4, prefix='D',
+ @ad.active_property(prefix='D',
permissions=ad.ACCESS_CREATE | ad.ACCESS_READ, default='')
def to(self, value):
return value
diff --git a/sugar_network/resources/user.py b/sugar_network/resources/user.py
index 717888c..0c89c3a 100644
--- a/sugar_network/resources/user.py
+++ b/sugar_network/resources/user.py
@@ -32,11 +32,11 @@ class User(ad.Document):
def color(self, value):
return value
- @ad.active_property(slot=3, prefix='S', permissions=ad.ACCESS_CREATE)
+ @ad.active_property(prefix='S', permissions=ad.ACCESS_CREATE)
def machine_sn(self, value):
return value
- @ad.active_property(slot=4, prefix='U', permissions=ad.ACCESS_CREATE)
+ @ad.active_property(prefix='U', permissions=ad.ACCESS_CREATE)
def machine_uuid(self, value):
return value
@@ -48,11 +48,11 @@ class User(ad.Document):
def tags(self, value):
return value
- @ad.active_property(slot=5, prefix='P', full_text=True, default='')
+ @ad.active_property(prefix='P', full_text=True, default='')
def location(self, value):
return value
- @ad.active_property(slot=6, prefix='B', default=0, typecast=int)
+ @ad.active_property(slot=2, prefix='B', default=0, typecast=int)
def birthday(self, value):
return value
diff --git a/sugar_network/resources/volume.py b/sugar_network/resources/volume.py
index 20dc90e..bf4fd70 100644
--- a/sugar_network/resources/volume.py
+++ b/sugar_network/resources/volume.py
@@ -154,7 +154,7 @@ class Commands(object):
raise NotImplementedError()
@ad.volume_command(method='GET', cmd='subscribe')
- def subscribe(self, response, only_commits=False):
+ def subscribe(self, request, response, only_commits=False):
"""Subscribe to Server-Sent Events.
:param only_commits:
@@ -164,7 +164,10 @@ class Commands(object):
"""
response.content_type = 'text/event-stream'
response['Cache-Control'] = 'no-cache'
- return self._pull_events(only_commits)
+ peer = 'anonymous'
+ if hasattr(request, 'environ'):
+ peer = request.environ.get('HTTP_SUGAR_USER') or peer
+ return self._pull_events(peer, only_commits)
@ad.directory_command_post(method='GET')
def _Commands_find_post(self, request, response, result):
@@ -196,22 +199,24 @@ class Commands(object):
default='/'.join(['', document, guid, name]) + postfix,
prefix=prefix)
- def _pull_events(self, only_commits):
+ def _pull_events(self, peer, only_commits):
+ _logger.debug('Start pulling events to %s user', peer)
# Otherwise, gevent's WSGI server doesn't sent HTTP status
yield '\n'
- while True:
- event = self._notifier.get()
-
- if only_commits:
- if event['event'] != 'commit':
- continue
- else:
- if event['event'] == 'commit':
- # Subscribers already got update notifications enough
- continue
-
- yield 'data: %s\n\n' % json.dumps(event)
+ try:
+ while True:
+ event = self._notifier.get()
+ if only_commits:
+ if event['event'] != 'commit':
+ continue
+ else:
+ if event['event'] == 'commit':
+ # Subscribers already got update notifications enough
+ continue
+ yield 'data: %s\n\n' % json.dumps(event)
+ finally:
+ _logger.debug('Stop pulling events to %s user', peer)
def _notify(self, event):
self._notifier.set(event)
diff --git a/tests/units/__main__.py b/tests/units/__main__.py
index 19c72b7..da752b3 100644
--- a/tests/units/__main__.py
+++ b/tests/units/__main__.py
@@ -23,6 +23,7 @@ from node_mount import *
from injector import *
from mountset import *
from context import *
+from implementation import *
from obs import *
tests.main()
diff --git a/tests/units/datastore.py b/tests/units/datastore.py
index de1e67d..39e99da 100755
--- a/tests/units/datastore.py
+++ b/tests/units/datastore.py
@@ -23,12 +23,12 @@ class DatastoreTest(tests.Test):
datastore.populate(artifacts)
assert not exists(sn_stamp())
- self.assertEqual(0, artifacts.find()[1].value)
+ self.assertEqual(0, artifacts.find()[1])
self.touch(sn_stamp())
datastore.populate(artifacts)
assert not exists(sn_stamp())
- self.assertEqual(0, artifacts.find()[1].value)
+ self.assertEqual(0, artifacts.find()[1])
self.touch(sn_stamp())
os.utime(sn_stamp(), (0, 0))
@@ -37,7 +37,7 @@ class DatastoreTest(tests.Test):
datastore.populate(artifacts)
assert exists(sn_stamp())
assert exists(ds_stamp())
- self.assertEqual(0, artifacts.find()[1].value)
+ self.assertEqual(0, artifacts.find()[1])
def test_populate(self):
self.create_mountset([Artifact])
diff --git a/tests/units/implementation.py b/tests/units/implementation.py
new file mode 100755
index 0000000..27b1397
--- /dev/null
+++ b/tests/units/implementation.py
@@ -0,0 +1,51 @@
+#!/usr/bin/env python
+# sugar-lint: disable
+
+from __init__ import tests
+
+from sugar_network.resources.implementation import _encode_version
+
+
+class ImplementationTest(tests.Test):
+
+ def test_encode_version(self):
+ self.assertEqual(
+ '00000''00000''00001' '10',
+ _encode_version('1'))
+ self.assertEqual(
+ '00000''00001''00002' '10',
+ _encode_version('1.2'))
+ self.assertEqual(
+ '00001''00020''00300' '10',
+ _encode_version('1.20.300'))
+ self.assertEqual(
+ '00020''00300''04000' '10',
+ _encode_version('1.20.300.4000'))
+
+ self.assertEqual(
+ '00000''00000''00001' '10' '00002''00003''00004' '10',
+ _encode_version('1-2.3.4'))
+ self.assertEqual(
+ '00000''00000''00001' '10' '00002''00003''00004' '10' '00006''00007''00008' '10',
+ _encode_version('1-2.3.4-5.6.7.8'))
+
+ self.assertEqual(
+ '00000''00000''00001' '08',
+ _encode_version('1-pre'))
+ self.assertEqual(
+ '00000''00000''00001' '09',
+ _encode_version('1-rc'))
+ self.assertEqual(
+ '00000''00000''00001' '10',
+ _encode_version('1-'))
+ self.assertEqual(
+ '00000''00000''00001' '11',
+ _encode_version('1-post'))
+
+ self.assertEqual(
+ '00000''00000''00001' '08' '00003''00004''00005' '10',
+ _encode_version('1-pre2.3.4.5'))
+
+
+if __name__ == '__main__':
+ tests.main()
diff --git a/tests/units/volume.py b/tests/units/volume.py
index 0c43b67..23e3733 100755
--- a/tests/units/volume.py
+++ b/tests/units/volume.py
@@ -8,7 +8,7 @@ from __init__ import tests
import active_document as ad
from sugar_network.toolkit.collection import Sequence
from sugar_network.toolkit.sneakernet import InPacket, OutBufferPacket, DiskFull
-from sugar_network.resources.volume import Volume, Resource, Commands
+from sugar_network.resources.volume import Volume, Resource, Commands, Request
from active_toolkit import coroutine
@@ -176,7 +176,7 @@ class VolumeTest(tests.Test):
events = []
def read_events():
- for event in cp.subscribe(ad.Response()):
+ for event in cp.subscribe(Request(), ad.Response()):
if not event.strip():
continue
assert event.startswith('data: ')
@@ -218,7 +218,7 @@ class VolumeTest(tests.Test):
events = []
def read_events():
- for event in cp.subscribe(ad.Response(), only_commits=True):
+ for event in cp.subscribe(Request(), ad.Response(), only_commits=True):
if not event.strip():
continue
assert event.startswith('data: ')