summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorfenn <fennetic.net>2009-08-11 13:33:35 -0500
committerfenn <fennetic.net>2009-08-11 13:33:35 -0500
commit201f4a28a9a48e37513edd6f7bf38f9463912f28 (patch)
tree18acff654119f5028267700e87d9d5298ff4df68 /packages
parent1f997a34b8d8a48fa105b1f3a4aa191b34eddde7 (diff)
downloadskdb-201f4a28a9a48e37513edd6f7bf38f9463912f28.tar.gz
skdb-201f4a28a9a48e37513edd6f7bf38f9463912f28.zip
clean up some bit rot
Diffstat (limited to 'packages')
-rw-r--r--packages/lego/interfaces.py32
-rw-r--r--packages/lego/lego.py12
-rw-r--r--packages/lego/test_legos.py5
3 files changed, 26 insertions, 23 deletions
diff --git a/packages/lego/interfaces.py b/packages/lego/interfaces.py
index 30da902..66c3753 100644
--- a/packages/lego/interfaces.py
+++ b/packages/lego/interfaces.py
@@ -26,21 +26,8 @@ class Discrete:
'''allows only a certain set of values'''
pass
-#class Grammar(skdb.FennObject, dict):
-# yaml_tag='!lego_grammar'
+grammar = {}
-fh = skdb.package_file('lego', 'grammar.yaml')
-grammar = skdb.load(fh)['features']
-
-#stuff values
-for key in grammar.keys():
- grammar[key]['name'] = key
-
-def dump_grammar_file():
- '''you probably should pipe through 'grep -v name'''''
- import yaml
- return yaml.dump(grammar)
-
class Feature(skdb.Interface):
yaml_tag='!lego_feature'
yaml_flow_style=False
@@ -52,7 +39,7 @@ class Feature(skdb.Interface):
try:
type = self.type
self.overlay(grammar[type])
- except AttributeError: self.type = None
+ except KeyError: self.type = None
try: name = self.name
except AttributeError: name = None
@@ -90,5 +77,20 @@ class SnapFit(Feature):
class Hinge(RevoluteJoint, SnapFit): pass
+#class Grammar(skdb.FennObject, dict):
+# yaml_tag='!lego_grammar'
+
+fh = skdb.package_file('lego', 'grammar.yaml')
+grammar = skdb.load(fh)['features']
+
+#stuff values
+for key in grammar.keys():
+ grammar[key].name = key
+
+def dump_grammar_file():
+ '''you probably should pipe through 'grep -v name'''''
+ import yaml
+ return yaml.dump(grammar)
+
if __name__ == '__main__':
print dump_grammar_file()
diff --git a/packages/lego/lego.py b/packages/lego/lego.py
index ea585ff..e795783 100644
--- a/packages/lego/lego.py
+++ b/packages/lego/lego.py
@@ -13,12 +13,14 @@ __status__ = "Development"
class Lego(Part):
'''standard lego part'''
yaml_tag = "!lego"
- def setup(self, name, num_pegs=0, num_holes=0):
- '''sets up a lego part'''
+ def __init__(self, name=None, num_pegs=0, num_holes=0):
self.name = name
self.interfaces = []
for each in range(num_holes):
new_hole = grammar['anti stud']
+ import yaml
+ print yaml.dump(new_hole)
+ print new_hole
new_hole.identifier = len(self.interfaces)
self.interfaces.append(new_hole)
for each in range(num_pegs):
@@ -29,16 +31,16 @@ class Lego(Part):
'''returns a list of peg interfaces that this Lego has'''
results = []
for each in self.interfaces:
- if each.__class__.__name__ == "Peg":
+ if each.type == "stud":
results.append(each)
return results
def holes(self):
'''returns a list of hole interfaces that this Lego has'''
results = []
for each in self.interfaces:
- if each.__class__.__name__ == "Hole":
+ if each.type == "antistud":
results.append(each)
return results
def __repr__(self):
- return "Lego(name=%s, num_pegs=%d, num_holes=%d)" % (self.name, len(self.pegs()), len(self.holes()))
+ return "%s(name=%s, num_pegs=%d, num_holes=%d)" % (self.__class__.__name__, self.name, len(self.pegs()), len(self.holes()))
diff --git a/packages/lego/test_legos.py b/packages/lego/test_legos.py
index 4877877..5f943fd 100644
--- a/packages/lego/test_legos.py
+++ b/packages/lego/test_legos.py
@@ -1,6 +1,5 @@
#!/usr/bin/python
-from lego import Lego, Peg, Hole
-from skdb import Part
+from lego import *
import unittest
def init_legos(): #why can't i do this in test_lego?
@@ -45,7 +44,7 @@ class TestLegos(unittest.TestCase):
for interface in brick.interfaces:
for opt in interface.options(bricklist):
if1, if2 = opt.interface1, opt.interface2
- self.assertFalse(if1.__class__ == Peg and if1.connected.__class__ == Peg)
+ self.assertFalse(if1.type == 'stud' and if1.connected.type == 'antistud')
self.assertFalse(if1.__class__ == Hole and if2.connected.__class__ == Hole)
def test_all_filled_up(self):
'''there should be no more options involving brick1's interface0'''