Project plugin works again
This commit is contained in:
parent
cc60bdd4b9
commit
00ca8d604a
@ -27,7 +27,7 @@ AC_DEFINE(MOO_BUILD_PYTHON_MODULE, 1, MOO_BUILD_PYTHON_MODULE)
|
|||||||
else
|
else
|
||||||
AM_CONDITIONAL(MOO_INSTALL_LIB, true)
|
AM_CONDITIONAL(MOO_INSTALL_LIB, true)
|
||||||
AM_CONDITIONAL(MOO_BUILD_PYTHON_MODULE, false)
|
AM_CONDITIONAL(MOO_BUILD_PYTHON_MODULE, false)
|
||||||
AM_CONDITIONAL(MOO_INSTALL_HEADERS, true)
|
AM_CONDITIONAL(MOO_INSTALL_HEADERS, false)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
AC_PROG_CC
|
AC_PROG_CC
|
||||||
|
@ -293,16 +293,16 @@
|
|||||||
</kdevdoctreeview>
|
</kdevdoctreeview>
|
||||||
<kdevfilecreate>
|
<kdevfilecreate>
|
||||||
<filetypes>
|
<filetypes>
|
||||||
<type icon="source" ext="g" create="template" name="GAP source" >
|
<type icon="source" ext="g" name="GAP source" create="template" >
|
||||||
<descr>A new empty GAP source file</descr>
|
<descr>A new empty GAP source file</descr>
|
||||||
</type>
|
</type>
|
||||||
<type icon="source_cpp" ext="cpp" create="template" name="C++ Source" >
|
<type icon="source_cpp" ext="cpp" name="C++ Source" create="template" >
|
||||||
<descr>A new empty C++ file.</descr>
|
<descr>A new empty C++ file.</descr>
|
||||||
</type>
|
</type>
|
||||||
<type icon="source_h" ext="h" create="template" name="C/C++ Header" >
|
<type icon="source_h" ext="h" name="C/C++ Header" create="template" >
|
||||||
<descr>A new empty header file for C/C++.</descr>
|
<descr>A new empty header file for C/C++.</descr>
|
||||||
</type>
|
</type>
|
||||||
<type icon="source_c" ext="c" create="template" name="C Source" >
|
<type icon="source_c" ext="c" name="C Source" create="template" >
|
||||||
<descr>A new empty C file.</descr>
|
<descr>A new empty C file.</descr>
|
||||||
</type>
|
</type>
|
||||||
</filetypes>
|
</filetypes>
|
||||||
|
3
moo.mprj
3
moo.mprj
@ -1,8 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
<medit-project name="moo" type="C" version="1.0">
|
<medit-project name="moo" type="C" version="1.0">
|
||||||
<make>
|
|
||||||
<n_jobs>3</n_jobs>
|
|
||||||
</make>
|
|
||||||
<configurations>
|
<configurations>
|
||||||
<debug>
|
<debug>
|
||||||
<run>
|
<run>
|
||||||
|
@ -2,6 +2,5 @@ from mprj.config._config import *
|
|||||||
from mprj.config._item import *
|
from mprj.config._item import *
|
||||||
from mprj.config._setting import *
|
from mprj.config._setting import *
|
||||||
from mprj.config._group import *
|
from mprj.config._group import *
|
||||||
from mprj.config._list import *
|
|
||||||
from mprj.config._dict import *
|
from mprj.config._dict import *
|
||||||
from mprj.config._xml import *
|
from mprj.config._xml import *
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
__all__ = ['Config']
|
__all__ = ['Config']
|
||||||
|
|
||||||
from mprj.config._group import Group, _GroupMeta
|
from mprj.config._group import Group, _GroupMeta
|
||||||
|
from mprj.config._xml import XMLGroup
|
||||||
|
|
||||||
|
|
||||||
class Config(Group):
|
class Config(Group):
|
||||||
@ -20,10 +21,17 @@ class Config(Group):
|
|||||||
self.name = file.name
|
self.name = file.name
|
||||||
self.type = file.project_type
|
self.type = file.project_type
|
||||||
self.version = file.version
|
self.version = file.version
|
||||||
|
self.load_xml()
|
||||||
|
|
||||||
|
def load_xml(self):
|
||||||
Group.load(self, self.file.root)
|
Group.load(self, self.file.root)
|
||||||
|
|
||||||
def get_xml(self):
|
def get_xml(self):
|
||||||
xml = self.save()[0]
|
xml = Group.save(self)
|
||||||
|
if xml:
|
||||||
|
xml = xml[0]
|
||||||
|
else:
|
||||||
|
xml = XMLGroup('medit-project')
|
||||||
xml.set_attr('name', self.name)
|
xml.set_attr('name', self.name)
|
||||||
xml.set_attr('type', self.type)
|
xml.set_attr('type', self.type)
|
||||||
xml.set_attr('version', self.version)
|
xml.set_attr('version', self.version)
|
||||||
|
@ -1,22 +1,25 @@
|
|||||||
__all__ = ['Dict']
|
__all__ = ['Dict']
|
||||||
|
|
||||||
from mprj.config._item import Item
|
from mprj.config._item import Item, create_instance
|
||||||
|
from mprj.config._xml import XMLGroup, XMLItem
|
||||||
|
|
||||||
|
|
||||||
def _load_instance(typ, info, node):
|
def _load_instance(typ, info, node):
|
||||||
if issubclass(typ, Item):
|
if issubclass(typ, Item):
|
||||||
obj = mprj._item.create_instance(info, node.name)
|
obj = create_instance(info, node.name)
|
||||||
obj.load(node)
|
obj.load(node)
|
||||||
else:
|
else:
|
||||||
return typ(node.get())
|
obj = typ(node.get())
|
||||||
|
# print "_load_instance: ", obj
|
||||||
|
return obj
|
||||||
|
|
||||||
def _save_instance(name, obj):
|
def _save_instance(name, obj):
|
||||||
if isinstance(obj, Item):
|
if isinstance(obj, Item):
|
||||||
return obj.save()
|
return obj.save()
|
||||||
elif obj is None:
|
elif obj is None:
|
||||||
return XMLItem(name, None)
|
return [XMLItem(name, None)]
|
||||||
else:
|
else:
|
||||||
return XMLItem(name, str(obj))
|
return [XMLItem(name, str(obj))]
|
||||||
|
|
||||||
def _copy_instance(obj):
|
def _copy_instance(obj):
|
||||||
if isinstance(obj, Item):
|
if isinstance(obj, Item):
|
||||||
@ -25,13 +28,10 @@ def _copy_instance(obj):
|
|||||||
return type(obj)(obj)
|
return type(obj)(obj)
|
||||||
|
|
||||||
|
|
||||||
def Dict(info = str):
|
def Dict(info = str, **kwargs):
|
||||||
if isinstance(info, type):
|
if isinstance(info, type):
|
||||||
typ = info
|
typ = info
|
||||||
if issubclass(info, Item):
|
info = [typ, kwargs]
|
||||||
pass
|
|
||||||
else:
|
|
||||||
pass
|
|
||||||
else:
|
else:
|
||||||
typ = info[0]
|
typ = info[0]
|
||||||
|
|
||||||
@ -54,6 +54,10 @@ def Dict(info = str):
|
|||||||
return item
|
return item
|
||||||
|
|
||||||
def __setitem__(self, key, value):
|
def __setitem__(self, key, value):
|
||||||
|
if not isinstance(value, Dict.__elm_type__):
|
||||||
|
raise TypeError('value %s is invalid for %s' % (value, self))
|
||||||
|
if self.__items.has_key(key):
|
||||||
|
raise RuntimeError('key %s already exists in %s' % (key, self))
|
||||||
self.__items[key] = value
|
self.__items[key] = value
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
@ -66,16 +70,35 @@ def Dict(info = str):
|
|||||||
def get_value(self):
|
def get_value(self):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def get_items(self):
|
def items(self): return self.__items.items()
|
||||||
return self.__items.items()
|
def keys(self): return self.__items.keys()
|
||||||
|
|
||||||
def copy_from(self, other):
|
def copy_from(self, other):
|
||||||
self.__items = {}
|
changed = Dict.copy_from(self, other)
|
||||||
for key in other:
|
first, common, second = dict_diff(self.__items, other.__items)
|
||||||
self[key] = _copy_instance(other[key])
|
|
||||||
|
if first or second:
|
||||||
|
changed = True
|
||||||
|
for key in first:
|
||||||
|
self.remove_item(key)
|
||||||
|
for key in second:
|
||||||
|
self.add_item(_copy_instance(other.__items[key]))
|
||||||
|
|
||||||
|
if issubclass(Dict.__elm_type__, Item):
|
||||||
|
for key in common:
|
||||||
|
changed = self.__items[key].copy_from(other.__items[key]) or changed
|
||||||
|
else:
|
||||||
|
for key in common:
|
||||||
|
old = self.__items[key]
|
||||||
|
new = other.__items[key]
|
||||||
|
if old != new:
|
||||||
|
self.__items[key] = new
|
||||||
|
changed = True
|
||||||
|
|
||||||
|
return changed
|
||||||
|
|
||||||
def load(self, node):
|
def load(self, node):
|
||||||
print 'load'
|
# print "Dict.load: %s, %s, %s" % (Dict.__elm_type__, Dict.__elm_info__, node)
|
||||||
for c in node.children():
|
for c in node.children():
|
||||||
self[c.name] = _load_instance(Dict.__elm_type__, Dict.__elm_info__, c)
|
self[c.name] = _load_instance(Dict.__elm_type__, Dict.__elm_info__, c)
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ __all__ = ['Group']
|
|||||||
|
|
||||||
from mprj.config._item import Item, _ItemMeta, create_instance
|
from mprj.config._item import Item, _ItemMeta, create_instance
|
||||||
from mprj.config._xml import XMLGroup
|
from mprj.config._xml import XMLGroup
|
||||||
|
from mprj.config._utils import dict_diff
|
||||||
|
|
||||||
|
|
||||||
class _GroupMeta(_ItemMeta):
|
class _GroupMeta(_ItemMeta):
|
||||||
@ -43,12 +44,12 @@ class Group(Item):
|
|||||||
|
|
||||||
if items:
|
if items:
|
||||||
for id in items:
|
for id in items:
|
||||||
self.add_item(id, items[id])
|
self.add_item(items[id], id)
|
||||||
|
|
||||||
if hasattr(type(self), '__items__'):
|
if hasattr(type(self), '__items__'):
|
||||||
items = getattr(type(self), '__items__')
|
items = getattr(type(self), '__items__')
|
||||||
for id in items:
|
for id in items:
|
||||||
self.add_item(id, items[id])
|
self.add_item(items[id], id)
|
||||||
|
|
||||||
def __getattr__(self, attr):
|
def __getattr__(self, attr):
|
||||||
if self.has_item(attr):
|
if self.has_item(attr):
|
||||||
@ -83,9 +84,17 @@ class Group(Item):
|
|||||||
return self.__items_dict.has_key(name)
|
return self.__items_dict.has_key(name)
|
||||||
|
|
||||||
def copy_from(self, other):
|
def copy_from(self, other):
|
||||||
Item.copy_from(self, other)
|
changed = Item.copy_from(self, other)
|
||||||
for item in self:
|
first, common, second = dict_diff(self.__items_dict, other.__items_dict)
|
||||||
item.copy_from(other[item.get_id()])
|
if first or second:
|
||||||
|
changed = True
|
||||||
|
for id in first:
|
||||||
|
self.remove_item(id)
|
||||||
|
for id in common:
|
||||||
|
changed = self[id].copy_from(other[id]) or changed
|
||||||
|
for id in second:
|
||||||
|
self.add_item(other[id].copy())
|
||||||
|
return changed
|
||||||
|
|
||||||
def get_value(self):
|
def get_value(self):
|
||||||
return self
|
return self
|
||||||
@ -93,9 +102,12 @@ class Group(Item):
|
|||||||
def get_items(self):
|
def get_items(self):
|
||||||
return self.__items
|
return self.__items
|
||||||
|
|
||||||
def add_item(self, id, info):
|
def add_item(self, info, id=None):
|
||||||
|
if id is None:
|
||||||
|
id = info.get_id()
|
||||||
if self.has_item(id):
|
if self.has_item(id):
|
||||||
raise RuntimeError("item '%s' already exist in '%s'" % (id, self))
|
raise RuntimeError("item '%s' already exist in '%s'" % (id, self))
|
||||||
|
# print info
|
||||||
item = create_instance(info, id)
|
item = create_instance(info, id)
|
||||||
self.__items.append(item)
|
self.__items.append(item)
|
||||||
self.__items_dict[id] = item
|
self.__items_dict[id] = item
|
||||||
|
@ -93,9 +93,25 @@ class Item(object):
|
|||||||
def __init__(self, id, name=None, description=None, visible=True):
|
def __init__(self, id, name=None, description=None, visible=True):
|
||||||
object.__init__(self)
|
object.__init__(self)
|
||||||
self.__id = id
|
self.__id = id
|
||||||
self.__name = name or _(id)
|
|
||||||
self.__description = description or self.__name
|
if name:
|
||||||
self.__visible = visible
|
self.__name = name or _(id)
|
||||||
|
elif hasattr(type(self), '__item_name__'):
|
||||||
|
self.__name = getattr(type(self), '__item_name__')
|
||||||
|
else:
|
||||||
|
self.__name = _(id)
|
||||||
|
|
||||||
|
if description:
|
||||||
|
self.__description = description
|
||||||
|
elif hasattr(type(self), '__item_description__'):
|
||||||
|
self.__description = getattr(type(self), '__item_description__')
|
||||||
|
else:
|
||||||
|
self.__description = self.__name
|
||||||
|
|
||||||
|
if hasattr(type(self), '__item_visible__'):
|
||||||
|
self.__visible = getattr(type(self), '__item_visible__')
|
||||||
|
else:
|
||||||
|
self.__visible = visible
|
||||||
|
|
||||||
def set_name(self, name): self.__name = name
|
def set_name(self, name): self.__name = name
|
||||||
def set_description(self, description): self.__description = description
|
def set_description(self, description): self.__description = description
|
||||||
@ -115,6 +131,7 @@ class Item(object):
|
|||||||
self.__name = other.__name
|
self.__name = other.__name
|
||||||
self.__description = other.__description
|
self.__description = other.__description
|
||||||
self.__visible = other.__visible
|
self.__visible = other.__visible
|
||||||
|
return False
|
||||||
|
|
||||||
def copy(self):
|
def copy(self):
|
||||||
copy = create_instance(type(self), self.get_id())
|
copy = create_instance(type(self), self.get_id())
|
||||||
|
@ -1,92 +0,0 @@
|
|||||||
__all__ = ['List']
|
|
||||||
|
|
||||||
from mprj.config._item import Item
|
|
||||||
|
|
||||||
|
|
||||||
def _load_instance(typ, info, node):
|
|
||||||
if issubclass(typ, Item):
|
|
||||||
obj = mprj._item.create_instance(info, node.name)
|
|
||||||
obj.load(node)
|
|
||||||
else:
|
|
||||||
return typ(node.get())
|
|
||||||
|
|
||||||
def _save_instance(obj):
|
|
||||||
if isinstance(obj, Item):
|
|
||||||
return obj.save()
|
|
||||||
elif obj is None:
|
|
||||||
return XMLItem('item', None)
|
|
||||||
else:
|
|
||||||
return XMLItem('item', str(obj))
|
|
||||||
|
|
||||||
def _copy_instance(obj):
|
|
||||||
if isinstance(obj, Item):
|
|
||||||
return obj.copy()
|
|
||||||
else:
|
|
||||||
return type(obj)(obj)
|
|
||||||
|
|
||||||
|
|
||||||
def List(info = str):
|
|
||||||
if isinstance(info, type):
|
|
||||||
typ = info
|
|
||||||
if issubclass(info, Item):
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
typ = info[0]
|
|
||||||
|
|
||||||
class List(Item):
|
|
||||||
__elm_type__ = typ
|
|
||||||
__elm_info__ = info
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
Item.__init__(self, *args, **kwargs)
|
|
||||||
self.__items = []
|
|
||||||
|
|
||||||
def __len__(self): return len(self.__items)
|
|
||||||
def __iter__(self): return self.__items.__iter__()
|
|
||||||
|
|
||||||
def __getitem__(self, ind):
|
|
||||||
item = self.__items[ind]
|
|
||||||
if issubclass(List.__elm_type__, Item):
|
|
||||||
return item.get_value()
|
|
||||||
else:
|
|
||||||
return item
|
|
||||||
|
|
||||||
def __eq__(self, other):
|
|
||||||
return type(self) == type(other) and \
|
|
||||||
self.get_id() == other.get_id() and \
|
|
||||||
self.__items == other.__items
|
|
||||||
def __ne__(self, other):
|
|
||||||
return not self.__eq__(other)
|
|
||||||
|
|
||||||
def get_items(self):
|
|
||||||
return self.__items
|
|
||||||
|
|
||||||
def get_value(self):
|
|
||||||
return self
|
|
||||||
|
|
||||||
def append(self, item):
|
|
||||||
if not isinstance(item, List.__elm_type__):
|
|
||||||
raise ValueError()
|
|
||||||
self.__items.append(item)
|
|
||||||
|
|
||||||
def copy_from(self, other):
|
|
||||||
self.__items = []
|
|
||||||
for elm in other:
|
|
||||||
self.append(_copy_instance(elm))
|
|
||||||
|
|
||||||
def load(self, node):
|
|
||||||
for c in node.children():
|
|
||||||
self.append(_load_instance(List.__elm_type__, List.__elm_info__, c))
|
|
||||||
|
|
||||||
def save(self):
|
|
||||||
nodes = []
|
|
||||||
for c in self:
|
|
||||||
nodes += _save_instance(c)
|
|
||||||
if nodes:
|
|
||||||
return [XMLGroup(self.get_id(), nodes)]
|
|
||||||
else:
|
|
||||||
return []
|
|
||||||
|
|
||||||
return List
|
|
@ -5,7 +5,7 @@ from mprj.config._xml import XMLItem
|
|||||||
|
|
||||||
|
|
||||||
class Setting(Item):
|
class Setting(Item):
|
||||||
def __init__(self, id, value=None, default=None, editable=None, data_type=None, **kwargs):
|
def __init__(self, id, value=None, default=None, editable=True, data_type=None, **kwargs):
|
||||||
Item.__init__(self, id, **kwargs)
|
Item.__init__(self, id, **kwargs)
|
||||||
|
|
||||||
self.__default = default
|
self.__default = default
|
||||||
@ -64,7 +64,8 @@ class Setting(Item):
|
|||||||
return self.equal(self.get_default())
|
return self.equal(self.get_default())
|
||||||
|
|
||||||
def copy_from(self, other):
|
def copy_from(self, other):
|
||||||
self.set_value(other.get_value())
|
changed = Item.copy_from(self, other)
|
||||||
|
return self.set_value(other.get_value()) or changed
|
||||||
|
|
||||||
def copy(self):
|
def copy(self):
|
||||||
return create_instance(type(self), self.get_id(),
|
return create_instance(type(self), self.get_id(),
|
||||||
|
11
moo/moopython/plugins/pyproject/mprj/config/_utils.py
Normal file
11
moo/moopython/plugins/pyproject/mprj/config/_utils.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
def dict_diff(dic1, dic2):
|
||||||
|
first, common, second = {}, {}, {}
|
||||||
|
for k in dic1:
|
||||||
|
if dic2.has_key(k):
|
||||||
|
common[k] = k
|
||||||
|
else:
|
||||||
|
first[k] = k
|
||||||
|
for k in dic2:
|
||||||
|
if not common.has_key(k):
|
||||||
|
second[k] = k
|
||||||
|
return first, common, second
|
@ -233,38 +233,13 @@ class TestGroup(unittest.TestCase):
|
|||||||
self.assert_(g.foo == g.bar)
|
self.assert_(g.foo == g.bar)
|
||||||
|
|
||||||
|
|
||||||
class TestList(unittest.TestCase):
|
|
||||||
def testlist(self):
|
|
||||||
typ = List(str)
|
|
||||||
l = typ.create_instance('ddd')
|
|
||||||
l.append('1')
|
|
||||||
l.append('2')
|
|
||||||
self.assert_(len(l) == 2)
|
|
||||||
l2 = typ.create_instance('ddd')
|
|
||||||
l2.append('1')
|
|
||||||
l2.append('2')
|
|
||||||
self.assert_(l == l2)
|
|
||||||
|
|
||||||
def testlist2(self):
|
|
||||||
typ = List(Setting())
|
|
||||||
l = typ.create_instance('ddd')
|
|
||||||
l.append(Setting.create_instance('a'))
|
|
||||||
l.append(Setting.create_instance('b'))
|
|
||||||
self.assert_(len(l) == 2)
|
|
||||||
l2 = typ.create_instance('ddd')
|
|
||||||
l2.append(Setting.create_instance('a'))
|
|
||||||
l2.append(Setting.create_instance('b'))
|
|
||||||
self.assert_(l == l2)
|
|
||||||
self.assert_(l == l.copy())
|
|
||||||
|
|
||||||
|
|
||||||
class TestConfig(unittest.TestCase):
|
class TestConfig(unittest.TestCase):
|
||||||
def testconfig(self):
|
def testconfig(self):
|
||||||
class C(Config):
|
class C(Config):
|
||||||
__items__ = {
|
__items__ = {
|
||||||
'variables' : Dict(str),
|
'variables' : Dict(str),
|
||||||
'project_dir' : Setting(data_type=str),
|
'project_dir' : Setting(data_type=str),
|
||||||
'stuff' : List(str)
|
'stuff' : Dict(str)
|
||||||
}
|
}
|
||||||
|
|
||||||
f = File("""<medit-project version="1.0" name="Foo" type="Simple">
|
f = File("""<medit-project version="1.0" name="Foo" type="Simple">
|
||||||
@ -280,7 +255,7 @@ class TestConfig(unittest.TestCase):
|
|||||||
self.assert_(len(c.get_items()) == 3)
|
self.assert_(len(c.get_items()) == 3)
|
||||||
self.assert_(c.project_dir == '.')
|
self.assert_(c.project_dir == '.')
|
||||||
self.assert_(len(c.stuff) == 1)
|
self.assert_(len(c.stuff) == 1)
|
||||||
self.assert_(c.stuff[0] == 'ddd')
|
self.assert_(c.stuff['kff'] == 'ddd')
|
||||||
self.assert_(c.variables['foo'] == 'bar')
|
self.assert_(c.variables['foo'] == 'bar')
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
__all__ = ['Column', 'View']
|
__all__ = ['Column', 'View', 'CellText', 'CellToggle']
|
||||||
|
|
||||||
""" configview.py: TreeView column and cell renderers for settings """
|
""" configview.py: TreeView column and cell renderers for settings """
|
||||||
|
|
||||||
@ -144,7 +144,7 @@ class CellText(gtk.CellRendererText):
|
|||||||
def do_edited(self, path, text):
|
def do_edited(self, path, text):
|
||||||
model = self.__model
|
model = self.__model
|
||||||
setting = model.get_value(model.get_iter(path), self.__column)
|
setting = model.get_value(model.get_iter(path), self.__column)
|
||||||
setting.set(text)
|
setting.set_string(text)
|
||||||
|
|
||||||
|
|
||||||
""" CellToggle: toggle renderer """
|
""" CellToggle: toggle renderer """
|
||||||
@ -158,4 +158,4 @@ class CellToggle(gtk.CellRendererToggle):
|
|||||||
def do_toggled(self, path):
|
def do_toggled(self, path):
|
||||||
model = self.__model
|
model = self.__model
|
||||||
setting = model.get_value(model.get_iter(path), self.__column)
|
setting = model.get_value(model.get_iter(path), self.__column)
|
||||||
setting.set(not setting.get_bool())
|
setting.set_value(not setting.get_bool())
|
||||||
|
@ -200,7 +200,6 @@ class Manager(object):
|
|||||||
project_type = self.project_types.get(file.project_type)
|
project_type = self.project_types.get(file.project_type)
|
||||||
config_type = getattr(project_type, '__config__')
|
config_type = getattr(project_type, '__config__')
|
||||||
config = config_type(file)
|
config = config_type(file)
|
||||||
config.load()
|
|
||||||
|
|
||||||
self.project = project_type(window, config)
|
self.project = project_type(window, config)
|
||||||
self.project.load()
|
self.project.load()
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
""" settings.py: basic Setting subclasses """
|
""" settings.py: basic Setting subclasses """
|
||||||
|
|
||||||
from mprj.config import Setting, Group, List
|
from mprj.config import Setting, Group, Dict, Item
|
||||||
from mprj.config._view import *
|
from mprj.config.view import *
|
||||||
from mprj.config._xml import XMLItem, XMLGroup
|
from mprj.config._xml import XMLItem, XMLGroup
|
||||||
|
|
||||||
def _cmp_nodes(n1, n2):
|
def _cmp_nodes(n1, n2):
|
||||||
@ -9,25 +9,25 @@ def _cmp_nodes(n1, n2):
|
|||||||
|
|
||||||
class String(Setting):
|
class String(Setting):
|
||||||
def get_cell_type(self):
|
def get_cell_type(self):
|
||||||
return mprj.configview.CellText
|
return CellText
|
||||||
def get_string(self):
|
def get_string(self):
|
||||||
return self.get()
|
return self.get_value()
|
||||||
def set_string(self, text):
|
def set_string(self, text):
|
||||||
self.set(text)
|
self.set_value(text)
|
||||||
|
|
||||||
class Bool(Setting):
|
class Bool(Setting):
|
||||||
def get_cell_type(self):
|
def get_cell_type(self):
|
||||||
return mprj.configview.CellToggle
|
return CellToggle
|
||||||
def get_bool(self):
|
def get_bool(self):
|
||||||
return self.get()
|
return self.get_value()
|
||||||
def set_string(self, text):
|
def set_string(self, text):
|
||||||
self.set(bool(text))
|
self.set_value(bool(text))
|
||||||
|
|
||||||
class Int(Setting):
|
class Int(Setting):
|
||||||
def get_cell_type(self):
|
def get_cell_type(self):
|
||||||
return mprj.configview.CellText
|
return CellText
|
||||||
def get_int(self):
|
def get_int(self):
|
||||||
return self.get()
|
return self.get_value()
|
||||||
def check_value(self, value):
|
def check_value(self, value):
|
||||||
try:
|
try:
|
||||||
value = int(value)
|
value = int(value)
|
||||||
@ -35,28 +35,7 @@ class Int(Setting):
|
|||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
def set_string(self, text):
|
def set_string(self, text):
|
||||||
self.set(int(text))
|
self.set_value(int(text))
|
||||||
|
|
||||||
class Dict(Setting, dict):
|
|
||||||
def load(self, node):
|
|
||||||
for c in node.children():
|
|
||||||
self[c.name] = c.get()
|
|
||||||
def save(self):
|
|
||||||
nodes = []
|
|
||||||
for k in self:
|
|
||||||
val = self[k]
|
|
||||||
if val is not None:
|
|
||||||
nodes.append(XmlItem(k, val))
|
|
||||||
if nodes:
|
|
||||||
nodes.sort(_cmp_nodes)
|
|
||||||
return [XMLGroup(self.get_id(), nodes)]
|
|
||||||
else:
|
|
||||||
return []
|
|
||||||
def copy(self):
|
|
||||||
copy = Dict()
|
|
||||||
for key in self:
|
|
||||||
copy[key] = self[key]
|
|
||||||
return copy
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import gtk
|
import gtk
|
||||||
@ -65,16 +44,16 @@ if __name__ == '__main__':
|
|||||||
window.set_size_request(300,200)
|
window.set_size_request(300,200)
|
||||||
window.connect('destroy', gtk.main_quit)
|
window.connect('destroy', gtk.main_quit)
|
||||||
|
|
||||||
group = mprj.config.Group('ddd')
|
group = Group.create_instance('ddd')
|
||||||
s = String('blah', value='111')
|
s = String.create_instance('blah', value='111')
|
||||||
group.add_item(s)
|
group.add_item(s)
|
||||||
group.blah = 8
|
group.blah = 8
|
||||||
print s.get()
|
print s.get_value()
|
||||||
print s is group.blah
|
print s is group.blah
|
||||||
group.add_item(String('foo', value='foofoofoofoofoofoofoofoo'))
|
group.add_item(String.create_instance('foo', value='foofoofoofoofoofoofoofoo'))
|
||||||
group.add_item(Bool('fff', value=True))
|
group.add_item(Bool.create_instance('fff', value=True))
|
||||||
|
|
||||||
view = mprj.configview.View(group)
|
view = View(group)
|
||||||
window.add(view)
|
window.add(view)
|
||||||
window.show_all()
|
window.show_all()
|
||||||
gtk.main()
|
gtk.main()
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
import moo
|
import moo
|
||||||
import os.path
|
import os.path
|
||||||
|
from moo.utils import _
|
||||||
|
|
||||||
from mprj.project import Project
|
from mprj.project import Project
|
||||||
from mprj.config import Config
|
from mprj.config import Config, Dict
|
||||||
from mprj.settings import Dict
|
|
||||||
from mprj.utils import print_error
|
from mprj.utils import print_error
|
||||||
from mprj.session import Session
|
from mprj.session import Session
|
||||||
|
|
||||||
|
|
||||||
class SimpleConfig(Config):
|
class SimpleConfig(Config):
|
||||||
__items__ = { 'vars' : Dict }
|
__items__ = { 'vars' : Dict(str, name=_('Environment variables')) }
|
||||||
|
|
||||||
|
|
||||||
class SimpleProject(Project):
|
class SimpleProject(Project):
|
||||||
@ -75,3 +75,26 @@ class SimpleProject(Project):
|
|||||||
|
|
||||||
def create_options_dialog(self):
|
def create_options_dialog(self):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
from mprj.config import File
|
||||||
|
|
||||||
|
s1 = """
|
||||||
|
<medit-project name="moo" type="Simple" version="2.0">
|
||||||
|
<vars>
|
||||||
|
<foo>bar</foo>
|
||||||
|
<blah>bom</blah>
|
||||||
|
</vars>
|
||||||
|
</medit-project>
|
||||||
|
"""
|
||||||
|
|
||||||
|
c = SimpleConfig(File(s1))
|
||||||
|
s2 = str(c.get_xml())
|
||||||
|
|
||||||
|
print s2
|
||||||
|
|
||||||
|
c = SimpleConfig(File(s2))
|
||||||
|
s3 = str(c.get_xml())
|
||||||
|
|
||||||
|
assert s2 == s3
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
from mprj.settings import *
|
|
||||||
from mprj.config import File, Config
|
|
||||||
|
|
||||||
f = File("""<medit-project version="1.0" name="Foo" type="Simple">
|
|
||||||
<variables>
|
|
||||||
<foo>bar</foo>
|
|
||||||
</variables>
|
|
||||||
<project_dir>.</project_dir>
|
|
||||||
<stuff>
|
|
||||||
<kff>ddd</kff>
|
|
||||||
</stuff>
|
|
||||||
</medit-project>""")
|
|
||||||
|
|
||||||
class D(Group):
|
|
||||||
__items__ = {'kff' : String, 'blah' : String}
|
|
||||||
D('ddd')
|
|
||||||
|
|
||||||
List(D)
|
|
||||||
|
|
||||||
class C(Config):
|
|
||||||
__items__ = {'variables' : Dict,
|
|
||||||
'project_dir' : String,
|
|
||||||
'stuff' : D,
|
|
||||||
'somestuff' : D}
|
|
||||||
|
|
||||||
c = C(f)
|
|
||||||
c.load()
|
|
||||||
# print c.variables
|
|
||||||
# print c.project_dir
|
|
||||||
# print c.stuff
|
|
||||||
# print f
|
|
||||||
# print c
|
|
||||||
print c.get_xml()
|
|
@ -1,5 +1,6 @@
|
|||||||
import os.path
|
import os.path
|
||||||
import moo
|
import moo
|
||||||
|
from moo.utils import _
|
||||||
|
|
||||||
from mprj.utils import expand_command
|
from mprj.utils import expand_command
|
||||||
from mprj.settings import *
|
from mprj.settings import *
|
||||||
@ -11,20 +12,24 @@ class MakeOptions(Group):
|
|||||||
'flags' : String,
|
'flags' : String,
|
||||||
'cmd' : String,
|
'cmd' : String,
|
||||||
'n_jobs' : Int(default=1),
|
'n_jobs' : Int(default=1),
|
||||||
'vars' : Dict
|
'vars' : Dict(str)
|
||||||
}
|
}
|
||||||
|
__item_name__ = _('Make options')
|
||||||
|
__item_descrption__ = _('Make options')
|
||||||
|
|
||||||
class ConfigureOptions(Group):
|
class ConfigureOptions(Group):
|
||||||
__items__ = {
|
__items__ = {
|
||||||
'args' : String,
|
'args' : String(name=_('Configure arguments')),
|
||||||
'cppflags' : String,
|
'cppflags' : String,
|
||||||
'ldflags' : String,
|
'ldflags' : String,
|
||||||
'cflags' : String,
|
'cflags' : String,
|
||||||
'cxxflags' : String,
|
'cxxflags' : String,
|
||||||
'cc' : String,
|
'cc' : String,
|
||||||
'cxx' : String,
|
'cxx' : String,
|
||||||
'vars' : Dict
|
'vars' : Dict(str, name=_('Environment variables'))
|
||||||
}
|
}
|
||||||
|
__item_name__ = _('Configure options')
|
||||||
|
__item_descrption__ = _('Configure options')
|
||||||
|
|
||||||
class Commands(Group):
|
class Commands(Group):
|
||||||
__items__ = {
|
__items__ = {
|
||||||
@ -36,6 +41,8 @@ class Commands(Group):
|
|||||||
'distclean' : String(default='cd $(top_builddir) && $(make) distclean'),
|
'distclean' : String(default='cd $(top_builddir) && $(make) distclean'),
|
||||||
'install' : String(default='cd $(top_builddir) && $(make) install')
|
'install' : String(default='cd $(top_builddir) && $(make) install')
|
||||||
}
|
}
|
||||||
|
__item_name__ = _('Build commands')
|
||||||
|
__item_descrption__ = _('Build commands')
|
||||||
|
|
||||||
class RunOptions(Group):
|
class RunOptions(Group):
|
||||||
__items__ = {
|
__items__ = {
|
||||||
@ -43,8 +50,10 @@ class RunOptions(Group):
|
|||||||
'run_from_dir' : String,
|
'run_from_dir' : String,
|
||||||
'exe' : String,
|
'exe' : String,
|
||||||
'args' : String,
|
'args' : String,
|
||||||
'vars' : Dict
|
'vars' : Dict(str)
|
||||||
}
|
}
|
||||||
|
__item_name__ = _('Run options')
|
||||||
|
__item_descrption__ = _('Run options')
|
||||||
|
|
||||||
def load(self, node):
|
def load(self, node):
|
||||||
Group.load(self, node)
|
Group.load(self, node)
|
||||||
@ -59,11 +68,13 @@ class RunOptions(Group):
|
|||||||
|
|
||||||
class BuildConfiguration(Group):
|
class BuildConfiguration(Group):
|
||||||
__items__ = {
|
__items__ = {
|
||||||
'build_dir' : String,
|
'build_dir' : String(name=_('Build directory')),
|
||||||
'make' : MakeOptions,
|
'make' : MakeOptions,
|
||||||
'run' : RunOptions,
|
'run' : RunOptions,
|
||||||
'configure' : ConfigureOptions
|
'configure' : ConfigureOptions
|
||||||
}
|
}
|
||||||
|
__item_name__ = _('Build configuration')
|
||||||
|
__item_descrption__ = _('Build configuration')
|
||||||
|
|
||||||
def load(self, node):
|
def load(self, node):
|
||||||
self.name = node.name
|
self.name = node.name
|
||||||
@ -74,27 +85,26 @@ class CConfig(SimpleConfig):
|
|||||||
__items__ = {
|
__items__ = {
|
||||||
'run' : RunOptions,
|
'run' : RunOptions,
|
||||||
'make' : MakeOptions,
|
'make' : MakeOptions,
|
||||||
'configurations' : List(BuildConfiguration),
|
'configurations' : Dict(BuildConfiguration),
|
||||||
'active' : String,
|
'active' : String,
|
||||||
'commands' : Commands
|
'commands' : Commands
|
||||||
}
|
}
|
||||||
|
|
||||||
def load(self):
|
def load_xml(self):
|
||||||
SimpleConfig.load(self)
|
SimpleConfig.load_xml(self)
|
||||||
|
|
||||||
if not self.configurations:
|
if not len(self.configurations):
|
||||||
raise RuntimeError("No configurations defined")
|
raise RuntimeError("No configurations defined")
|
||||||
|
|
||||||
if self.active:
|
if self.active:
|
||||||
confs = [c.name for c in self.configurations]
|
if self.active not in self.configurations.keys():
|
||||||
if self.active not in confs:
|
|
||||||
raise RuntimeError("Invalid configuration %s" % (self.active,))
|
raise RuntimeError("Invalid configuration %s" % (self.active,))
|
||||||
else:
|
else:
|
||||||
self.active = self.configurations[0].name
|
self.active = self.configurations.keys()[0]
|
||||||
|
|
||||||
self.confs = {}
|
self.confs = {}
|
||||||
for c in self.configurations:
|
for name in self.configurations:
|
||||||
self.confs[c.name] = c
|
self.confs[name] = self.configurations[name]
|
||||||
|
|
||||||
def get_active_conf(self):
|
def get_active_conf(self):
|
||||||
if not self.confs:
|
if not self.confs:
|
||||||
@ -193,7 +203,7 @@ class CConfig(SimpleConfig):
|
|||||||
self.get_build_dir(topdir))
|
self.get_build_dir(topdir))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
from mprj.configxml import File
|
from mprj.config import File
|
||||||
|
|
||||||
s1 = """
|
s1 = """
|
||||||
<medit-project name="moo" type="C" version="2.0">
|
<medit-project name="moo" type="C" version="2.0">
|
||||||
@ -227,13 +237,11 @@ if __name__ == '__main__':
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
c = CConfig(File(s1))
|
c = CConfig(File(s1))
|
||||||
c.load()
|
|
||||||
s2 = str(c.get_xml())
|
s2 = str(c.get_xml())
|
||||||
|
|
||||||
print s2
|
print s2
|
||||||
|
|
||||||
c = CConfig(File(s2))
|
c = CConfig(File(s2))
|
||||||
c.load()
|
|
||||||
s3 = str(c.get_xml())
|
s3 = str(c.get_xml())
|
||||||
|
|
||||||
assert s2 == s3
|
assert s2 == s3
|
||||||
|
@ -3,7 +3,6 @@ from moo.utils import _
|
|||||||
import mprj.optdialog
|
import mprj.optdialog
|
||||||
from mprj.optdialog import page_new_from_file
|
from mprj.optdialog import page_new_from_file
|
||||||
|
|
||||||
print __file__
|
|
||||||
dir = os.path.dirname(__file__)
|
dir = os.path.dirname(__file__)
|
||||||
|
|
||||||
class Page(mprj.optdialog.Page):
|
class Page(mprj.optdialog.Page):
|
||||||
|
@ -28,7 +28,7 @@ class LatexConfig(SimpleConfig):
|
|||||||
None, filename, topdir, None)
|
None, filename, topdir, None)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
from mprj.configxml import File
|
from mprj.config import File
|
||||||
|
|
||||||
s1 = """
|
s1 = """
|
||||||
<medit-project name="moo" type="LaTeX" version="1.0">
|
<medit-project name="moo" type="LaTeX" version="1.0">
|
||||||
@ -37,13 +37,11 @@ if __name__ == '__main__':
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
c = LatexConfig(File(s1))
|
c = LatexConfig(File(s1))
|
||||||
c.load()
|
|
||||||
s2 = str(c.get_xml())
|
s2 = str(c.get_xml())
|
||||||
|
|
||||||
print s2
|
print s2
|
||||||
|
|
||||||
c = LatexConfig(File(s2))
|
c = LatexConfig(File(s2))
|
||||||
c.load()
|
|
||||||
s3 = str(c.get_xml())
|
s3 = str(c.get_xml())
|
||||||
|
|
||||||
assert s2 == s3
|
assert s2 == s3
|
||||||
|
Loading…
x
Reference in New Issue
Block a user