modelverse.py 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. import urllib
  2. import urllib2
  3. import json
  4. # Helper functions
  5. taskname = "test"
  6. address = "http://localhost:8001"
  7. last_output = None
  8. def _input(value):
  9. # Ugly json encoding of primitives
  10. value = '"%s"' if type(value) == str else value
  11. urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": value, "taskname": taskname})))
  12. def _output():
  13. try:
  14. global last_output
  15. last_output = urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "get_output", "taskname": taskname})))
  16. return last_output
  17. except:
  18. raise UnknownError()
  19. def _output_last():
  20. return last_output
  21. # Exceptions
  22. class UnknownError(Exception):
  23. pass
  24. class UnknownIdentifier(Exception):
  25. pass
  26. class UnknownType(Exception):
  27. pass
  28. class UnsupportedValue(Exception):
  29. pass
  30. class CompilationError(Exception):
  31. pass
  32. class NoSuchAttribute(Exception):
  33. pass
  34. class UnknownModel(Exception):
  35. pass
  36. class ConnectionError(Exception):
  37. pass
  38. class ModelExists(Exception):
  39. pass
  40. class PermissionDenied(Exception):
  41. pass
  42. # Main MvC operations
  43. def init():
  44. """Starts up the connection to the Modelverse."""
  45. pass
  46. # return None
  47. # raises ConnectionError
  48. # raises UnknownError
  49. def login(username, password):
  50. """Log in an existing user."""
  51. pass
  52. # return None
  53. # raises UnknownError
  54. # raises PermissionDenied
  55. def register(username, password):
  56. """Register a new user."""
  57. pass
  58. # return None
  59. # raises UnknownError
  60. # raises UserExists
  61. def model_add(model_name, metamodel_name):
  62. """Instantiate a new model."""
  63. pass
  64. # return None
  65. # raises UnknownModel
  66. # raises ModelExists
  67. # raises UnknownError
  68. def model_modify(model_name):
  69. """Modify an existing model."""
  70. pass
  71. # return is_write
  72. # raises UnknownModel
  73. # raises PermissionDenied
  74. # raises UnknownError
  75. def model_list():
  76. """List all models."""
  77. pass
  78. # return [(model1, metamodel1), (model2, metamodel2), ...]
  79. # raises UnknownError
  80. def model_list_full():
  81. """List full information on all models."""
  82. pass
  83. # return [(model1, metamodel1, owner1, group1, permissions1), (model2, metamodel2, owner2, group2, permissions2), ...]
  84. # raises UnknownError
  85. def model_overwrite(model_name, new_model):
  86. """Upload a new model and overwrite an existing model."""
  87. pass
  88. # return None
  89. # raises UnknownModel
  90. # raises PermissionDenied
  91. # raises CompilationError
  92. # raises UnknownError
  93. # Actual operations on the model
  94. def list():
  95. """Return a list of all IDs and the type of the element"""
  96. pass
  97. # return [(name1, type1), (name2, type2), ...]
  98. # raises UnknownError
  99. def types():
  100. """Return a list of all types usable in the model"""
  101. pass
  102. # return [type1, type2, ...]
  103. # raises UnknownError
  104. def read(ID):
  105. """Return a tuple of information on the element: its type and source/target (None if not an edge)"""
  106. pass
  107. # return (type, (source, target))
  108. # raises UnknownError
  109. # raises UnknownIdentifier
  110. def read_attrs(ID):
  111. """Return a dictionary of attribute value pairs"""
  112. pass
  113. # return {attr1: value1, attr2: value2, ...}
  114. # raises UnknownError
  115. def transformation_add_MT_language():
  116. """Create a new Model Transformation language out of a set of metamodels."""
  117. raise NotImplementedError()
  118. def transformation_add_MT():
  119. """Create a new model transformation."""
  120. raise NotImplementedError()
  121. def transformation_add_AL():
  122. """Create a new action language fragment."""
  123. raise NotImplementedError()
  124. def transformation_add_MANUAL():
  125. """Create a new manual model operation."""
  126. raise NotImplementedError()
  127. def transformation_execute():
  128. """Execute an existing model operation."""
  129. raise NotImplementedError()
  130. def transformation_list():
  131. """List existing model operations."""
  132. raise NotImplementedError()
  133. def transformation_list_full():
  134. """List detailed information on model operations."""
  135. raise NotImplementedError()
  136. def transformation_detail():
  137. """List full details of a a model operation."""
  138. raise NotImplementedError()
  139. def transformation_RAMify():
  140. """Ramify an existing metamodel."""
  141. raise NotImplementedError()
  142. def process_execute():
  143. """Execute a process model."""
  144. raise NotImplementedError()
  145. def permission_modify():
  146. """Modify permissions of a model."""
  147. raise NotImplementedError()
  148. def permission_owner():
  149. """Modify the owning user of a model."""
  150. raise NotImplementedError()
  151. def permission_group():
  152. """Modify the owning group of a model."""
  153. raise NotImplementedError()
  154. def group_create():
  155. """Create a new group."""
  156. raise NotImplementedError()
  157. def group_delete():
  158. """Delete a group of which you are an owner."""
  159. raise NotImplementedError()
  160. def group_owner_add():
  161. """Add a new owning user to a group you own."""
  162. raise NotImplementedError()
  163. def group_owner_delete():
  164. """Delete an owning user to a group you own."""
  165. raise NotImplementedError()
  166. def group_join():
  167. """Add a new user to a group you own."""
  168. raise NotImplementedError()
  169. def group_kick():
  170. """Delete a user from a group you own."""
  171. raise NotImplementedError()
  172. def group_list():
  173. """List existing groups."""
  174. raise NotImplementedError()
  175. def admin_promote():
  176. """Promote a user to admin status."""
  177. raise NotImplementedError()
  178. def admin_demote():
  179. """Demote a user from admin status."""
  180. raise NotImplementedError()
  181. def user_logout():
  182. """Log out the current user. A new login will be required afterwards."""
  183. pass
  184. # return None
  185. # raises UnknownException
  186. def user_delete():
  187. """Removes the current user. A new login will be required afterwards."""
  188. pass
  189. # return None
  190. # raises UnknownException
  191. def instantiate(typename, edge=None, ID=""):
  192. """Create a new instance of the specified typename, between the selected elements (if not None), and with the provided ID (if any)"""
  193. pass
  194. # return instantiated_ID
  195. # raises UnknownError
  196. # raises UnknownType
  197. # raises UnknownIdentifier
  198. def delete(ID):
  199. """Delete the element with the given ID"""
  200. pass
  201. # return None
  202. # raises UnknownError
  203. # raises UnknownIdentifier
  204. def attr_assign(ID, attr, value):
  205. """Assign a value to an attribute"""
  206. pass
  207. # return None
  208. # raises UnknownError
  209. # raises UnknownIdentifier
  210. # raises NoSuchAttribute
  211. # raises UnsupportedValue
  212. def attr_assign_code(ID, attr, code):
  213. """Assign a piece of Action Language code to the attribute"""
  214. pass
  215. # return None
  216. # raises UnknownError
  217. # raises UnknownIdentifier
  218. # raises NoSuchAttribute
  219. # raises UnsupportedValue
  220. def upload(new_model):
  221. """Overwrite the current model with the provided model"""
  222. pass
  223. # return None
  224. # raises UnknownError
  225. # raises CompilationError
  226. def read_outgoing(ID, typename):
  227. """Returns a list of all outgoing associations of a specific type ("" = all)"""
  228. pass
  229. # return [name1, name2, ...]
  230. # raises UnknownError
  231. # raises UnknownIdentifier
  232. # raises UnknownType
  233. def read_incoming(ID, typename):
  234. """Returns a list of all incoming associations of a specific type ("" = all)"""
  235. pass
  236. # return [name1, name2, ...]
  237. # raises UnknownError
  238. # raises UnknownIdentifier
  239. # raises UnknownType