Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions bridgepoint/ooaofooa.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
import functools
import os
import logging
import zipfile
import keyword
import xtuml
import io

from xtuml import navigate_one as one
from xtuml import navigate_many as many
Expand Down Expand Up @@ -509,12 +511,21 @@ def filename_input(self, path_or_filename):

If the filename is a directory, files that ends with .xtuml located
somewhere in the directory or sub directories will be loaded as well.

If the filename is a zip archive, files that ends with .xtuml located
somewhere in the archive will be loaded as well.
'''
if os.path.isdir(path_or_filename):
for path, _, files in os.walk(path_or_filename):
for name in files:
if name.endswith('.xtuml'):
xtuml.ModelLoader.filename_input(self, os.path.join(path, name))
elif zipfile.is_zipfile(path_or_filename):
with zipfile.ZipFile(path_or_filename) as zipinput:
for zipinfo in zipinput.filelist:
if zipinfo.filename.endswith('.xtuml'):
with zipinput.open(zipinfo) as f:
xtuml.ModelLoader.file_input(self, io.TextIOWrapper(f, encoding='UTF-8'))
else:
xtuml.ModelLoader.filename_input(self, path_or_filename)

Expand Down
18 changes: 17 additions & 1 deletion tests/test_bridgepoint/test_ooaofooa.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#
# You should have received a copy of the GNU Lesser General Public
# License along with pyxtuml. If not, see <http://www.gnu.org/licenses/>.
import atexit
import os
import shutil
import unittest
import xtuml
from bridgepoint import ooaofooa
Expand All @@ -35,7 +38,20 @@ def test_remove_globals(self):
s = xtuml.serialize_instances(m)
self.assertFalse(s)


def test_folder_input(self):
dirname = os.path.dirname(__file__) + os.sep + '..' + os.sep + 'resources'
metamodel = ooaofooa.load_metamodel(dirname, load_globals=False)
self.assertTrue(metamodel.select_any('S_DT', xtuml.where_eq(Name='integer')) is not None)

def test_zipfile_input(self):
dirname = os.path.dirname(__file__) + os.sep + '..' + os.sep + 'resources'
zipfile = shutil.make_archive(dirname, 'zip', dirname)
atexit.register(os.remove, zipfile)

metamodel = ooaofooa.load_metamodel(zipfile, load_globals=False)
self.assertTrue(metamodel.select_any('S_DT', xtuml.where_eq(Name='integer')) is not None)


if __name__ == "__main__":
import logging

Expand Down
2 changes: 1 addition & 1 deletion xtuml/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ def __init__(self, kind, metamodel=None):
self.indices = dict()
self.links = dict()
self.storage = list()
self.clazz = type(kind, (Class,), dict(__metaclass__=self))
self.clazz = type(str(kind), (Class,), dict(__metaclass__=self))

def __call__(self, *args, **kwargs):
'''
Expand Down