simplified_api.py 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. from copy import deepcopy
  2. from .constraints import (
  3. EnsureDatasetSiblingName,
  4. EnsureExistingDirectory,
  5. )
  6. # each item is a command that is allowed in the API
  7. # the key is the command name in the Python API.
  8. # the values are dicts with the following keys
  9. # - exclude_parameters: set with parameter names to
  10. # exclude from the API
  11. api = dict(
  12. clone=dict(
  13. name='&Clone a dataset',
  14. exclude_parameters=set((
  15. 'git_clone_opts',
  16. 'reckless',
  17. 'description',
  18. )),
  19. parameter_display_names=dict(
  20. source='Clone from',
  21. path='Clone into',
  22. dataset='Register in superdataset',
  23. ),
  24. parameter_order=dict(
  25. source=0,
  26. path=1,
  27. dataset=2,
  28. ),
  29. parameter_constraints=dict(
  30. path=EnsureExistingDirectory(),
  31. ),
  32. ),
  33. create=dict(
  34. name='C&reate a dataset',
  35. exclude_parameters=set((
  36. 'initopts',
  37. 'description',
  38. 'fake_dates',
  39. )),
  40. parameter_display_names=dict(
  41. force='OK if target directory not empty',
  42. path='Create at',
  43. dataset='Register in superdataset',
  44. ),
  45. parameter_order=dict(
  46. path=0,
  47. annex=1,
  48. dataset=2,
  49. ),
  50. parameter_constraints=dict(
  51. path=EnsureExistingDirectory(),
  52. ),
  53. ),
  54. create_sibling_gitlab=dict(
  55. name='Create a Git&Lab sibling',
  56. exclude_parameters=set((
  57. 'dryrun',
  58. 'path',
  59. 'recursive',
  60. )),
  61. ),
  62. create_sibling_gin=dict(
  63. name='Create a GI&N sibling',
  64. exclude_parameters=set((
  65. 'dryrun',
  66. 'api'
  67. 'path',
  68. 'recursive',
  69. )),
  70. parameter_display_names=dict(
  71. dataset='Dataset',
  72. reponame='New repository name on Gin',
  73. name='Sibling name',
  74. private='Make Gin repo private',
  75. existing='If the sibling exists already...',
  76. recursive='Create siblings for subdatasets',
  77. credential='Name of credential to be used',
  78. access_protocol='Access protocol',
  79. publish_depends='Add publication dependency to'
  80. ),
  81. parameter_order=dict(
  82. dataset=0,
  83. reponame=1,
  84. private=2,
  85. name=3,
  86. access_protocol=4,
  87. existing=5,
  88. recursive=6,
  89. credential=7,
  90. ),
  91. ),
  92. create_sibling_github=dict(
  93. name='Create a Git&Hub sibling',
  94. exclude_parameters=set((
  95. 'dryrun',
  96. 'github_login',
  97. 'github_organization',
  98. 'api',
  99. 'path',
  100. 'recursive',
  101. )),
  102. parameter_display_names=dict(
  103. dataset='Dataset',
  104. reponame='New repository name on Github',
  105. name='Sibling name',
  106. private='Make GitHub repo private',
  107. existing='If the sibling exists already...',
  108. recursive='Create siblings for subdatasets',
  109. credential='Name of credential to be used',
  110. access_protocol='Access protocol',
  111. publish_depends='Add publication dependency to'
  112. ),
  113. parameter_order=dict(
  114. dataset=0,
  115. reponame=1,
  116. private=2,
  117. name=3,
  118. access_protocol=4,
  119. existing=5,
  120. recursive=6,
  121. credential=7,
  122. ),
  123. ),
  124. create_sibling_webdav=dict(
  125. name='Create a &WebDAV sibling',
  126. exclude_parameters=set((
  127. 'recursive',
  128. 'path',
  129. )),
  130. ),
  131. drop=dict(
  132. name='Dr&op content',
  133. exclude_parameters=set((
  134. 'check',
  135. 'if_dirty',
  136. )),
  137. parameter_display_names=dict(
  138. dataset='Drop from dataset at',
  139. what='What to drop',
  140. path='Limit to',
  141. recursive='Also drop (in) any subdatasets',
  142. reckless='Disable safeguards',
  143. ),
  144. parameter_order=dict(
  145. dataset=0,
  146. what=1,
  147. path=2,
  148. recursive=3,
  149. reckless=4,
  150. ),
  151. ),
  152. get=dict(
  153. name='&Get content',
  154. exclude_parameters=set((
  155. 'description',
  156. 'reckless',
  157. 'source',
  158. )),
  159. parameter_display_names=dict(
  160. dataset='Get content in dataset at',
  161. path='Limit to',
  162. # 'all' because we have no recursion_limit enabled
  163. recursive='Also get all subdatasets',
  164. get_data='Get file content',
  165. ),
  166. parameter_order=dict(
  167. dataset=0,
  168. get_data=1,
  169. path=2,
  170. recursive=3,
  171. ),
  172. ),
  173. push=dict(
  174. name='&Push data/updates to a sibling',
  175. exclude_parameters=set((
  176. 'since',
  177. )),
  178. parameter_constraints=dict(
  179. to=EnsureDatasetSiblingName(),
  180. ),
  181. parameter_display_names=dict(
  182. dataset='Push from dataset at',
  183. to='To dataset sibling',
  184. data='What to push',
  185. path='Limit to',
  186. force='Force operation',
  187. ),
  188. parameter_order=dict(
  189. dataset=0,
  190. to=1,
  191. data=2,
  192. path=3,
  193. recursive=4,
  194. ),
  195. ),
  196. save=dict(
  197. name='&Save the state in a dataset',
  198. exclude_parameters=set((
  199. 'updated',
  200. 'message_file',
  201. )),
  202. parameter_display_names=dict(
  203. dataset='Save changes in dataset at',
  204. message='Description of change',
  205. path='Limit to',
  206. recursive='Include changes in subdatasets',
  207. to_git='Do not put files in annex',
  208. version_tag='Tag for saved dataset state',
  209. amend='Amend last saved state',
  210. ),
  211. parameter_order=dict(
  212. dataset=0,
  213. message=1,
  214. path=2,
  215. recursive=3,
  216. to_git=4,
  217. version_tag=5,
  218. amend=6,
  219. ),
  220. ),
  221. update=dict(
  222. name='&Update from a sibling',
  223. exclude_parameters=set((
  224. 'merge',
  225. 'fetch_all',
  226. 'how_subds',
  227. 'follow',
  228. 'reobtain_data',
  229. )),
  230. parameter_constraints=dict(
  231. sibling=EnsureDatasetSiblingName(),
  232. ),
  233. ),
  234. )
  235. dataset_api = {
  236. c: s for c, s in api.items()
  237. if c in (
  238. 'clone', 'create',
  239. 'create_sibling_gitlab', 'create_sibling_gin',
  240. 'create_sibling_github', 'create_sibling_webdav',
  241. 'drop', 'get', 'push', 'save', 'update'
  242. )
  243. }
  244. directory_api = {
  245. c: s for c, s in api.items() if c in ('clone', 'create')
  246. }
  247. directory_in_ds_api = {
  248. c: s for c, s in api.items()
  249. if c in ('clone', 'create', 'drop', 'get', 'push', 'save')
  250. }
  251. file_api = {}
  252. file_in_ds_api = {
  253. c: s for c, s in api.items() if c in ('save')
  254. }
  255. annexed_file_api = {}
  256. for c, s in api.items():
  257. if c not in ('drop', 'get', 'push', 'save'):
  258. continue
  259. s = deepcopy(s)
  260. # recursion underneath a file is not possible
  261. s['exclude_parameters'].add('recursive')
  262. # there can only ever be a single path
  263. s['parameter_nargs'] = dict(path=1)
  264. # path subselection does not make sense, but if we exclude it
  265. # the config dialog is practically empty. keep as some kind of
  266. # confirmation
  267. #s['exclude_parameters'].add('path')
  268. annexed_file_api[c] = s
  269. # get of a single annexed files can be simpler
  270. af_get = annexed_file_api['get']
  271. # not getting data for an annexed file makes no sense
  272. af_get['exclude_parameters'].add('get_data')
  273. gooey_suite = dict(
  274. # may contain keyboard navigation hints
  275. title='&Simplified',
  276. description='Simplified access to the most essential operations',
  277. options=dict(
  278. disable_manual_path_input=True,
  279. ),
  280. apis=dict(
  281. dataset=dataset_api,
  282. directory=directory_api,
  283. directory_in_ds=directory_in_ds_api,
  284. file=file_api,
  285. file_in_ds=file_in_ds_api,
  286. annexed_file=annexed_file_api,
  287. ),
  288. # simplified API has no groups
  289. api_group_order={},
  290. exclude_parameters=set((
  291. 'result_renderer',
  292. 'return_type',
  293. 'result_filter',
  294. 'result_xfm',
  295. 'on_failure',
  296. 'jobs',
  297. 'recursion_limit',
  298. )),
  299. parameter_display_names=dict(
  300. annex='Dataset with file annex',
  301. cfg_proc='Configuration procedure(s)',
  302. dataset='Dataset location',
  303. ),
  304. )