elapi 1.0.7.dev1__tar.gz → 1.0.7.dev3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/PKG-INFO +83 -27
  2. elapi-1.0.7.dev3/README.md +201 -0
  3. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/pyproject.toml +3 -5
  4. elapi-1.0.7.dev3/src/elapi/VERSION +1 -0
  5. elapi-1.0.7.dev3/src/elapi/_exceptions.py +1 -0
  6. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/src/elapi/api.py +2 -2
  7. elapi-1.0.7.dev3/src/elapi/cli/__init__.py +1 -0
  8. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/src/elapi/cli/doc.py +6 -1
  9. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/src/elapi/cli/elapi.py +47 -25
  10. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/src/elapi/configuration/config.py +19 -10
  11. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/src/elapi/configuration/log_file.py +1 -1
  12. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/src/elapi/path.py +83 -25
  13. elapi-1.0.7.dev3/src/elapi/plugins/bill_teams/_doc.py +44 -0
  14. elapi-1.0.7.dev3/src/elapi/plugins/bill_teams/bill_teams.py +253 -0
  15. elapi-1.0.7.dev3/src/elapi/plugins/bill_teams/cli.py +386 -0
  16. elapi-1.0.7.dev3/src/elapi/plugins/bill_teams/format.py +30 -0
  17. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/src/elapi/plugins/bill_teams/invoice.py +8 -19
  18. elapi-1.0.7.dev3/src/elapi/plugins/bill_teams/validator.py +221 -0
  19. elapi-1.0.7.dev3/src/elapi/plugins/commons/__init__.py +3 -0
  20. elapi-1.0.7.dev1/src/elapi/cli/helpers.py → elapi-1.0.7.dev3/src/elapi/plugins/commons/cli_helpers.py +19 -9
  21. {elapi-1.0.7.dev1/src/elapi/plugins/utils → elapi-1.0.7.dev3/src/elapi/plugins/commons}/export.py +37 -3
  22. elapi-1.0.7.dev3/src/elapi/plugins/commons/get_information.py +117 -0
  23. elapi-1.0.7.dev3/src/elapi/plugins/experiments/_doc.py +65 -0
  24. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/src/elapi/plugins/experiments/cli.py +24 -12
  25. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/src/elapi/plugins/experiments/experiments.py +3 -3
  26. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/src/elapi/plugins/show_config.py +4 -4
  27. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/src/elapi/styles/__init__.py +2 -2
  28. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/src/elapi/styles/format.py +47 -4
  29. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/src/elapi/styles/highlight.py +10 -2
  30. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/src/elapi/validators/__init__.py +3 -2
  31. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/src/elapi/validators/base.py +23 -13
  32. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/src/elapi/validators/identity.py +46 -3
  33. elapi-1.0.7.dev3/src/elapi/validators/path.py +111 -0
  34. elapi-1.0.7.dev3/src/elapi/validators/permission.py +136 -0
  35. elapi-1.0.7.dev1/README.md +0 -145
  36. elapi-1.0.7.dev1/src/elapi/VERSION +0 -1
  37. elapi-1.0.7.dev1/src/elapi/cli/__init__.py +0 -1
  38. elapi-1.0.7.dev1/src/elapi/plugins/bill_teams/_doc.py +0 -3
  39. elapi-1.0.7.dev1/src/elapi/plugins/bill_teams/bill_teams.py +0 -164
  40. elapi-1.0.7.dev1/src/elapi/plugins/bill_teams/cli.py +0 -143
  41. elapi-1.0.7.dev1/src/elapi/plugins/experiments/_doc.py +0 -24
  42. elapi-1.0.7.dev1/src/elapi/plugins/utils/__init__.py +0 -2
  43. elapi-1.0.7.dev1/src/elapi/validators/path.py +0 -77
  44. elapi-1.0.7.dev1/src/elapi/validators/permission.py +0 -84
  45. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/LICENSE +0 -0
  46. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/src/elapi/__init__.py +0 -0
  47. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/src/elapi/_names.py +0 -0
  48. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/src/elapi/cli/__main__.py +0 -0
  49. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/src/elapi/cli/_plugin_handler.py +0 -0
  50. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/src/elapi/configuration/__init__.py +0 -0
  51. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/src/elapi/configuration/_config_history.py +0 -0
  52. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/src/elapi/endpoint.py +0 -0
  53. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/src/elapi/loggers/__init__.py +0 -0
  54. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/src/elapi/loggers/base.py +0 -0
  55. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/src/elapi/loggers/handlers/__init__.py +0 -0
  56. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/src/elapi/loggers/handlers/file.py +0 -0
  57. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/src/elapi/loggers/handlers/stderr.py +0 -0
  58. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/src/elapi/plugins/__init__.py +0 -0
  59. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/src/elapi/plugins/bill_teams/__init__.py +0 -0
  60. {elapi-1.0.7.dev1/src/elapi/plugins/utils → elapi-1.0.7.dev3/src/elapi/plugins/commons}/get_location_from_headers.py +0 -0
  61. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/src/elapi/plugins/experiments/__init__.py +0 -0
  62. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/src/elapi/plugins/experiments/formats.py +0 -0
  63. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/src/elapi/plugins/version.py +0 -0
  64. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/src/elapi/styles/_markdown_doc.py +0 -0
  65. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/src/elapi/styles/_missing.py +0 -0
  66. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/src/elapi/styles/base.py +0 -0
  67. {elapi-1.0.7.dev1 → elapi-1.0.7.dev3}/src/elapi/styles/colors.py +0 -0
@@ -1,12 +1,12 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: elapi
3
- Version: 1.0.7.dev1
4
- Summary: elAPI is a powerful, extensible API interface to eLabFTW built for the University Computing Centre (URZ, FIRE division) at Universität Heidelberg.
3
+ Version: 1.0.7.dev3
4
+ Summary: elAPI is a powerful, extensible API client for eLabFTW.
5
5
  Home-page: https://www.urz.uni-heidelberg.de/en/service-catalogue/software-and-applications/elabftw
6
6
  License: AGPL-3.0-only
7
7
  Keywords: elabftw,api
8
- Author: Alexander Haller
9
- Author-email: alexander.haller@urz.uni-heidelberg.de
8
+ Author: Alexander Haller, Mahadi Xion
9
+ Author-email: elabftw@uni-heidelberg.de
10
10
  Maintainer: Mahadi Xion
11
11
  Maintainer-email: mahadi.xion@urz.uni-heidelberg.de
12
12
  Requires-Python: >=3.9.0,<4.0.0
@@ -38,7 +38,10 @@ Description-Content-Type: text/markdown
38
38
 
39
39
  # elAPI
40
40
 
41
- elAPI is a powerful, extensible API interface to eLabFTW. It supports serving almost all kinds of requests documented in
41
+ elAPI is a powerful, extensible API client for eLabFTW built for
42
+ the [University Computing Centre](https://www.urz.uni-heidelberg.de/en) (
43
+ URZ, [FIRE](https://www.urz.uni-heidelberg.de/en/node/64/organisation/future-it-research-education) division) at
44
+ Universität Heidelberg. It supports serving almost all kinds of requests documented on
42
45
  [eLabFTW API documentation](https://doc.elabftw.net/api/v2/) with ease. elAPI treats eLabFTW API endpoints as its
43
46
  arguments.
44
47
 
@@ -55,18 +58,47 @@ $ elapi get users --id <id>
55
58
 
56
59
  ## Installation
57
60
 
58
- Support for installing packages with `pip install --user` has been deprecated with the adoption of [PEP 688](https://peps.python.org/pep-0668/) on many systems like [Debian 12](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1030335#5).
59
- We recommend [`pipx`](https://pipx.pypa.io/stable/) for installing elAPI.
61
+ elAPI can be used both as a CLI tool and as a Python library. If you are interested in simply using elAPI's
62
+ off-the-shelf features from the command-line, install elAPI as a CLI tool. If you intend to write automation script for
63
+ eLabFTW, you should install elAPI as a library inside a virtual environment. Of course, if you're interested in
64
+ both, you can have elAPI installed in both ways.
65
+
66
+ ### Install elAPI as a CLI tool
67
+
68
+ Support for installing Python packages with `pip install --user` has been deprecated with the adoption
69
+ of [PEP 688](https://peps.python.org/pep-0668/) on many systems
70
+ like [Debian 12](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1030335#5).
71
+ We recommend [`pipx`](https://pipx.pypa.io/stable/) for installing elAPI for use of its CLI functionalities. Pipx
72
+ installs packages in isolated virtual environments, so Pipx-installed elAPI should not conflict with elAPI installed
73
+ inside other virtual environments.
60
74
 
61
75
  ```shell
62
76
  $ pipx install elapi
63
77
  ```
64
78
 
65
- Of course, `pip install --user elapi` might continue to work on some systems.
79
+ After installation with Pipx is complete, you would also be able to run elAPI just by entering the `elapi` command on
80
+ the
81
+ terminal.
82
+
83
+ ### Install elAPI as a library
84
+
85
+ It is recommended to install elAPI inside a Python virtual environment for use of its rich APIs for
86
+ working with eLabFTW. From inside a virtual environment, elAPI CLI can be invoked with `python -m elapi.cli`.
87
+ At the moment, though, the documentation about using elAPI as a library is severely lacking.
66
88
 
67
89
  ## Configuration
68
90
 
69
- elAPI needs to be configured first before we can do anything useful with it. elAPI supports a YAML configuration file in
91
+ elAPI needs to be configured first before you can do anything useful with it. Mainly, elAPI needs to know your eLabFTW
92
+ server's API URL and your API key (or token) for access.
93
+
94
+ ### Quick configuration
95
+
96
+ You can run `elapi init` to simplify the configuration process. You will be prompted with questions
97
+ about your eLabFTW server with examples to help you fill in the answers.
98
+
99
+ ### Advanced configuration
100
+
101
+ elAPI supports a YAML configuration file in
70
102
  the following locations.
71
103
 
72
104
  - Current directory: `./elapi.yml`
@@ -74,12 +106,12 @@ the following locations.
74
106
  - Root directory: `/etc/elapi.yml`
75
107
 
76
108
  elAPI supports configuration overloading. I.e., a keyword set in root configuration file `/etc/elapi.yml` can be
77
- overriden by setting a different value in user configuration file `$HOME/.config/elapi.yml`. In terms of precedence,
109
+ overridden by setting a different value in user configuration file `$HOME/.config/elapi.yml`. In terms of precedence,
78
110
  configuration file present in the currently active directory has the highest priority, and configuration in root
79
111
  directory has the lowest.
80
112
 
81
113
  The following parameters are currently configurable, with `host` and `api_token` being the required fields. For testing
82
- purposes it would be safe to store everything in the user configuration file.
114
+ purposes it would be safe to store everything in `$HOME/.config/elapi.yml`.
83
115
 
84
116
  ```yaml
85
117
  # elAPI configuration
@@ -94,13 +126,13 @@ export_dir: ~/Downloads/elAPI
94
126
  unsafe_api_token_warning: yes
95
127
  ```
96
128
 
97
- We can get an overview of detected configurations.
129
+ You can get an overview of detected configurations.
98
130
 
99
131
  ```shell
100
132
  $ elapi show-config
101
133
  ```
102
134
 
103
- If both `host` and `api_token` are detected, we are good to go!
135
+ If both `host` and `api_token` are detected, you are good to go!
104
136
 
105
137
  ## Usage
106
138
 
@@ -112,14 +144,14 @@ $ elapi --help
112
144
 
113
145
  ### `GET` requests
114
146
 
115
- We can request an overview of running eLabFTW server.
147
+ Request an overview of running eLabFTW server:
116
148
 
117
149
  ```shell
118
150
  $ elapi get info -F yml
119
151
  # Here -F (or --format) defines the output format
120
152
  ```
121
153
 
122
- We can request a list o all active experiments and export it to a `JSON` file.
154
+ You can request a list o all active experiments and export it to a `JSON` file.
123
155
 
124
156
  ```shell
125
157
  $ elapi get experiments --export ~/Downoads/experiments.json
@@ -127,7 +159,7 @@ $ elapi get experiments --export ~/Downoads/experiments.json
127
159
 
128
160
  ### `POST` requests
129
161
 
130
- We can create a new user by the name 'John Doe'.
162
+ Create a new user by the name 'John Doe':
131
163
 
132
164
  ```shell
133
165
  $ elapi post users --id <user id> -d '{"firstname": "John", "lastname": "Doe", "email": "test_test@itnerd.de"}'
@@ -135,46 +167,70 @@ $ elapi post users --id <user id> -d '{"firstname": "John", "lastname": "Doe", "
135
167
 
136
168
  ### `PATCH` requests
137
169
 
138
- We can update an existing user's email address.
170
+ Update an existing user's email address:
139
171
 
140
172
  ```shell
141
173
  $ elapi patch users --id <user id> -d '{"email": "new_email@itnerd.de"}'
142
174
  ```
143
175
 
144
- `patch` command allows us to make changes to eLabFTW server settings. E.g., we can update the time (in minutes)
176
+ `patch` command allows us to make changes to eLabFTW server settings. E.g., you can update the time (in minutes)
145
177
  after which the authentication cookie will expire.
146
178
 
147
179
  ```shell
148
180
  $ elapi patch config -d '{"cookie_validity_time": 43200}'
149
181
  ```
150
182
 
151
- We can publish an announcement to all the members.
183
+ You can publish an announcement to all the members.
152
184
 
153
185
  ```shell
154
186
  $ elapi patch config -d '{"announcement": "Notice: Server will be down tomorrow at midnight due to scheduled maintenance."}'
155
187
  ```
156
188
 
157
- ### Bill teams
189
+ ### `DELETE` requests
158
190
 
159
- We can generate invoice for eLabFTW teams.
191
+ Delete all the tags associated to an experiment:
160
192
 
161
193
  ```shell
162
- $ elapi bill-teams generate-invoice
194
+ $ elapi delete experiments -i <experiment ID> --sub tags
163
195
  ```
164
196
 
165
- We may just want to have a look at the billing information without generating invoice.
197
+ You can reset the configuration to default values.
166
198
 
167
199
  ```shell
168
- $ elapi bill-teams info -F yaml
200
+ $ elapi delete config
169
201
  ```
170
202
 
171
- We can also export this information as a `YAML` file to the export directory defined in configuration
172
- file (`export_dir`).
203
+ ### `experiments` plugin
204
+
205
+ `experiments` plugin enables experiments-specific actions. You can download an experiment in PDF by its "Unique eLabID"
206
+ to `~/Downloads` directory.
173
207
 
174
208
  ```shell
175
- elapi bill-teams info -F yaml --export
209
+ $ elapi experiments get -i <experiment unique elabid> -F pdf --export ~/Downloads/
176
210
  ```
177
211
 
212
+ Append text in markdown to an existing experiment by its ID:
213
+
214
+ ```shell
215
+ $ elapi experiments append --id <experiment ID> -M -t "**New content.**"
216
+ ```
217
+
218
+ You can also upload an attachment to an experiment.
219
+
220
+ ```shell
221
+ $ elapi experiments upload-attachment --id <experiment ID> --path <path to attachment file> --comment <comment for your attachment>
222
+ ```
223
+
224
+ ### Bill teams
225
+
226
+ You can get a list of all teams and its users for billing purposes and export it to home directory.
227
+
228
+ ```shell
229
+ $ elapi bill-teams teams-info --export ~
230
+ ```
231
+
232
+ Most sub-commands available under `elapi bill-teams` plugin are for Universität Heidelberg specific use-cases.
233
+
178
234
  ## Open-source
179
235
 
180
236
  elAPI is open-source and published under AGPLv3 license. The repository is however hosted internally within
@@ -0,0 +1,201 @@
1
+ # elAPI
2
+
3
+ elAPI is a powerful, extensible API client for eLabFTW built for
4
+ the [University Computing Centre](https://www.urz.uni-heidelberg.de/en) (
5
+ URZ, [FIRE](https://www.urz.uni-heidelberg.de/en/node/64/organisation/future-it-research-education) division) at
6
+ Universität Heidelberg. It supports serving almost all kinds of requests documented on
7
+ [eLabFTW API documentation](https://doc.elabftw.net/api/v2/) with ease. elAPI treats eLabFTW API endpoints as its
8
+ arguments.
9
+
10
+ **Example:**
11
+
12
+ From [the documentation](https://doc.elabftw.net/api/v2/#/Users/read-user):
13
+ > GET /users/{id}
14
+
15
+ With elAPI you can do the following:
16
+
17
+ ```sh
18
+ $ elapi get users --id <id>
19
+ ```
20
+
21
+ ## Installation
22
+
23
+ elAPI can be used both as a CLI tool and as a Python library. If you are interested in simply using elAPI's
24
+ off-the-shelf features from the command-line, install elAPI as a CLI tool. If you intend to write automation script for
25
+ eLabFTW, you should install elAPI as a library inside a virtual environment. Of course, if you're interested in
26
+ both, you can have elAPI installed in both ways.
27
+
28
+ ### Install elAPI as a CLI tool
29
+
30
+ Support for installing Python packages with `pip install --user` has been deprecated with the adoption
31
+ of [PEP 688](https://peps.python.org/pep-0668/) on many systems
32
+ like [Debian 12](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1030335#5).
33
+ We recommend [`pipx`](https://pipx.pypa.io/stable/) for installing elAPI for use of its CLI functionalities. Pipx
34
+ installs packages in isolated virtual environments, so Pipx-installed elAPI should not conflict with elAPI installed
35
+ inside other virtual environments.
36
+
37
+ ```shell
38
+ $ pipx install elapi
39
+ ```
40
+
41
+ After installation with Pipx is complete, you would also be able to run elAPI just by entering the `elapi` command on
42
+ the
43
+ terminal.
44
+
45
+ ### Install elAPI as a library
46
+
47
+ It is recommended to install elAPI inside a Python virtual environment for use of its rich APIs for
48
+ working with eLabFTW. From inside a virtual environment, elAPI CLI can be invoked with `python -m elapi.cli`.
49
+ At the moment, though, the documentation about using elAPI as a library is severely lacking.
50
+
51
+ ## Configuration
52
+
53
+ elAPI needs to be configured first before you can do anything useful with it. Mainly, elAPI needs to know your eLabFTW
54
+ server's API URL and your API key (or token) for access.
55
+
56
+ ### Quick configuration
57
+
58
+ You can run `elapi init` to simplify the configuration process. You will be prompted with questions
59
+ about your eLabFTW server with examples to help you fill in the answers.
60
+
61
+ ### Advanced configuration
62
+
63
+ elAPI supports a YAML configuration file in
64
+ the following locations.
65
+
66
+ - Current directory: `./elapi.yml`
67
+ - User directory: `$HOME/.config/elapi.yml`
68
+ - Root directory: `/etc/elapi.yml`
69
+
70
+ elAPI supports configuration overloading. I.e., a keyword set in root configuration file `/etc/elapi.yml` can be
71
+ overridden by setting a different value in user configuration file `$HOME/.config/elapi.yml`. In terms of precedence,
72
+ configuration file present in the currently active directory has the highest priority, and configuration in root
73
+ directory has the lowest.
74
+
75
+ The following parameters are currently configurable, with `host` and `api_token` being the required fields. For testing
76
+ purposes it would be safe to store everything in `$HOME/.config/elapi.yml`.
77
+
78
+ ```yaml
79
+ # elAPI configuration
80
+ # Saved in `$HOME/.config/elapi.yml`
81
+
82
+ host: <host API url>
83
+ # Example: https://demo.elabftw.net/api/v2/
84
+ # Note the host URL ends with the API endpoint
85
+ api_token: <token with at least read-access>
86
+ # You can generate an API token from eLabFTW user panel -> API keys tab.
87
+ export_dir: ~/Downloads/elAPI
88
+ unsafe_api_token_warning: yes
89
+ ```
90
+
91
+ You can get an overview of detected configurations.
92
+
93
+ ```shell
94
+ $ elapi show-config
95
+ ```
96
+
97
+ If both `host` and `api_token` are detected, you are good to go!
98
+
99
+ ## Usage
100
+
101
+ elAPI can be invoked from the command-line.
102
+
103
+ ```shell
104
+ $ elapi --help
105
+ ```
106
+
107
+ ### `GET` requests
108
+
109
+ Request an overview of running eLabFTW server:
110
+
111
+ ```shell
112
+ $ elapi get info -F yml
113
+ # Here -F (or --format) defines the output format
114
+ ```
115
+
116
+ You can request a list o all active experiments and export it to a `JSON` file.
117
+
118
+ ```shell
119
+ $ elapi get experiments --export ~/Downoads/experiments.json
120
+ ```
121
+
122
+ ### `POST` requests
123
+
124
+ Create a new user by the name 'John Doe':
125
+
126
+ ```shell
127
+ $ elapi post users --id <user id> -d '{"firstname": "John", "lastname": "Doe", "email": "test_test@itnerd.de"}'
128
+ ```
129
+
130
+ ### `PATCH` requests
131
+
132
+ Update an existing user's email address:
133
+
134
+ ```shell
135
+ $ elapi patch users --id <user id> -d '{"email": "new_email@itnerd.de"}'
136
+ ```
137
+
138
+ `patch` command allows us to make changes to eLabFTW server settings. E.g., you can update the time (in minutes)
139
+ after which the authentication cookie will expire.
140
+
141
+ ```shell
142
+ $ elapi patch config -d '{"cookie_validity_time": 43200}'
143
+ ```
144
+
145
+ You can publish an announcement to all the members.
146
+
147
+ ```shell
148
+ $ elapi patch config -d '{"announcement": "Notice: Server will be down tomorrow at midnight due to scheduled maintenance."}'
149
+ ```
150
+
151
+ ### `DELETE` requests
152
+
153
+ Delete all the tags associated to an experiment:
154
+
155
+ ```shell
156
+ $ elapi delete experiments -i <experiment ID> --sub tags
157
+ ```
158
+
159
+ You can reset the configuration to default values.
160
+
161
+ ```shell
162
+ $ elapi delete config
163
+ ```
164
+
165
+ ### `experiments` plugin
166
+
167
+ `experiments` plugin enables experiments-specific actions. You can download an experiment in PDF by its "Unique eLabID"
168
+ to `~/Downloads` directory.
169
+
170
+ ```shell
171
+ $ elapi experiments get -i <experiment unique elabid> -F pdf --export ~/Downloads/
172
+ ```
173
+
174
+ Append text in markdown to an existing experiment by its ID:
175
+
176
+ ```shell
177
+ $ elapi experiments append --id <experiment ID> -M -t "**New content.**"
178
+ ```
179
+
180
+ You can also upload an attachment to an experiment.
181
+
182
+ ```shell
183
+ $ elapi experiments upload-attachment --id <experiment ID> --path <path to attachment file> --comment <comment for your attachment>
184
+ ```
185
+
186
+ ### Bill teams
187
+
188
+ You can get a list of all teams and its users for billing purposes and export it to home directory.
189
+
190
+ ```shell
191
+ $ elapi bill-teams teams-info --export ~
192
+ ```
193
+
194
+ Most sub-commands available under `elapi bill-teams` plugin are for Universität Heidelberg specific use-cases.
195
+
196
+ ## Open-source
197
+
198
+ elAPI is open-source and published under AGPLv3 license. The repository is however hosted internally within
199
+ Universität Heidelberg's network. The codebase can still be accessed from [PyPI](https://pypi.org/project/elapi/#files).
200
+ If you express interest in having the repository made completely public, or if you have any question, feel free
201
+ to [contact us](mailto:elabftw@uni-heidelberg.de).
@@ -1,11 +1,9 @@
1
1
  [tool.poetry]
2
2
  name = "elapi"
3
- version = "1.0.7-dev1"
4
- description = """elAPI is a powerful, extensible API interface to eLabFTW built for \
5
- the University Computing Centre (URZ, FIRE division) at Universität Heidelberg."""
3
+ version = "1.0.7.dev3"
4
+ description = "elAPI is a powerful, extensible API client for eLabFTW."
6
5
  authors = [
7
- "Alexander Haller <alexander.haller@urz.uni-heidelberg.de>",
8
- "Mahadi Xion <mahadi.xion@urz.uni-heidelberg.de>",
6
+ "Alexander Haller, Mahadi Xion <elabftw@uni-heidelberg.de>",
9
7
  ]
10
8
  maintainers = [
11
9
  "Mahadi Xion <mahadi.xion@urz.uni-heidelberg.de>",
@@ -0,0 +1 @@
1
+ 1.0.7.dev3
@@ -0,0 +1 @@
1
+ class NoException(Exception): ...
@@ -154,7 +154,7 @@ class ElabFTWURL:
154
154
  @endpoint_id.setter
155
155
  def endpoint_id(self, value):
156
156
  if value is not None:
157
- if not re.match(r"^\w+$", value := str(value)):
157
+ if not re.match(r"^(\d+)$|^(me)$", value := str(value)):
158
158
  # Although, eLabFTW primarily supports integer-only IDs, there are exceptions, like the alias
159
159
  # ID "me" for receiving one's own user information.
160
160
  raise ElabFTWURLError("Invalid endpoint ID (or entity ID).")
@@ -173,7 +173,7 @@ class ElabFTWURL:
173
173
  "Sub-endpoint ID cannot be defined without first specifying its sub-endpoint name."
174
174
  )
175
175
  if value is not None:
176
- if not re.match(r"^\w+$", value := str(value)):
176
+ if not re.match(r"^(\d+)$|^(me)$", value := str(value)):
177
177
  raise ElabFTWURLError("Invalid sub-endpoint ID (or entity sub-ID).")
178
178
  self._sub_endpoint_id = value
179
179
  else:
@@ -0,0 +1 @@
1
+ from ..plugins.commons.cli_helpers import CLIExport, CLIFormat, OrderedCommands # noqa: F401
@@ -71,12 +71,17 @@ __PARAMETERS__doc__ = {
71
71
  f"If _--format/-F_ is absent, then {APP_NAME} can use the file extension as the data format. "
72
72
  f"If _--format/-F_ is also present, then file extension is ignored, "
73
73
  f"and --format value takes precedence.\n",
74
+ "export_overwrite": f"If given --export/-e path is a file, but it already **exists**, "
75
+ f"{APP_NAME} will not overwrite the file by default, and will instead use the "
76
+ f"fallback location. _--overwrite_ needs to be passed if {APP_NAME} should overwrite "
77
+ f"an existing file when exporting.",
74
78
  "data_format": f"Format style for the output. Supported values are: {supported_highlighting_formats}. "
75
79
  f"The values are case insensitive. The default format is `{DEFAULT_EXPORT_DATA_FORMAT.upper()}`. "
76
80
  "When 'txt' is used, the response will be sent in *original*, un-formatted (almost), "
77
81
  "without syntax highlighting. This can be utilized if one wishes to pipe the output "
78
82
  " to some external formatting program like `less`. "
79
- "If an unsupported format value is provided then the output format falls back to 'txt'.",
83
+ "If an unsupported format value is provided then the output format "
84
+ f"falls back to `{DEFAULT_EXPORT_DATA_FORMAT.upper()}`.",
80
85
  "no_keys": "Do not show the names of configuration keywords.",
81
86
  "init_host": 'The host URL of your eLabFTW instance. It will look like \"https://demo.elabftw.net/api/v2\".',
82
87
  "init_api_token": 'API token (or API key) of your eLabFTW instance. You can generate it from eLabFTW "User Panel". '
@@ -21,10 +21,10 @@ from typing_extensions import Annotated
21
21
 
22
22
  from ._plugin_handler import internal_plugin_typer_apps
23
23
  from .doc import __PARAMETERS__doc__ as docs
24
- from .helpers import OrderedCommands
25
24
  from .. import APP_NAME
26
25
  from ..configuration import EXPORT_DIR
27
26
  from ..loggers import Logger
27
+ from ..plugins.commons.cli_helpers import OrderedCommands
28
28
  from ..styles import get_custom_help_text
29
29
  from ..styles import stdin_console, stderr_console
30
30
 
@@ -101,6 +101,7 @@ def init(
101
101
  from ..configuration import LOCAL_CONFIG_LOC
102
102
  from ..validators import Validate, ValidationError
103
103
  from ..validators import PathValidator
104
+ from ..path import ProperPath
104
105
  from time import sleep
105
106
 
106
107
  with stdin_console.status(
@@ -119,27 +120,42 @@ def init(
119
120
  )
120
121
  raise typer.Exit(1)
121
122
  else:
122
- with LOCAL_CONFIG_LOC.open(mode="r+") as f:
123
- if f.read():
124
- logger.error(
125
- f"A configuration file '{LOCAL_CONFIG_LOC}' already exists and it's not empty! "
126
- f"It's ambiguous what to do in this situation. {APP_NAME} will abort. "
127
- f"Configuration initialization has failed!"
128
- )
129
- raise typer.Exit(1)
123
+ path = ProperPath(LOCAL_CONFIG_LOC)
124
+ try:
125
+ with path.open(mode="r") as f:
126
+ if f.read():
127
+ logger.error(
128
+ f"A configuration file '{LOCAL_CONFIG_LOC}' already exists and it's not empty! "
129
+ f"It's ambiguous what to do in this situation."
130
+ )
131
+ logger.error("Configuration initialization has failed!")
132
+ raise typer.Exit(1)
133
+ except path.PathException as e:
134
+ if isinstance(e, FileNotFoundError):
135
+ path.create()
130
136
  else:
137
+ logger.error(e)
138
+ logger.error("Configuration initialization has failed!")
139
+ raise typer.Exit(1)
140
+ try:
141
+ with path.open(mode="w") as f:
131
142
  _configuration_yaml_text = f"""host: {host_url}
132
- api_token: {api_token}
133
- export_dir: {export_directory}
134
- unsafe_api_token_warning: yes
135
- """
143
+ api_token: {api_token}
144
+ export_dir: {export_directory}
145
+ unsafe_api_token_warning: yes
146
+ """
136
147
  f.write(_configuration_yaml_text)
137
- stdin_console.print(
138
- "Configuration file has been successfully created! "
139
- f"Run '{APP_NAME} show-config' to see the configuration path "
140
- "and more configuration details.",
141
- style="green",
142
- )
148
+ except path.PathException as e:
149
+ logger.error(e)
150
+ logger.error("Configuration initialization has failed!")
151
+ raise typer.Exit(1)
152
+ else:
153
+ stdin_console.print(
154
+ "Configuration file has been successfully created! "
155
+ f"Run '{APP_NAME} show-config' to see the configuration path "
156
+ "and more configuration details.",
157
+ style="green",
158
+ )
143
159
 
144
160
 
145
161
  @app.command(short_help="Make `GET` requests to eLabFTW endpoints.")
@@ -179,6 +195,10 @@ def get(
179
195
  ),
180
196
  ] = False,
181
197
  _export_dest: Annotated[Optional[str], typer.Argument(hidden=True)] = None,
198
+ export_overwrite: Annotated[
199
+ bool,
200
+ typer.Option("--overwrite", help=docs["export_overwrite"], show_default=False),
201
+ ] = False,
182
202
  ) -> dict:
183
203
  """
184
204
  Make `GET` requests to eLabFTW endpoints as documented in
@@ -200,9 +220,9 @@ def get(
200
220
  import re
201
221
  from .. import APP_NAME
202
222
  from ..api import GETRequest, ElabFTWURLError
203
- from .helpers import CLIExport, CLIFormat
223
+ from ..plugins.commons.cli_helpers import CLIExport, CLIFormat
204
224
  from ..validators import Validate, HostIdentityValidator
205
- from ..plugins.utils import Export
225
+ from ..plugins.commons import Export
206
226
  from ..styles import Highlight
207
227
 
208
228
  validate_config = Validate(HostIdentityValidator())
@@ -219,7 +239,9 @@ def get(
219
239
  style="red",
220
240
  )
221
241
  raise typer.Exit(1)
222
- data_format, export_dest, export_file_ext = CLIExport(data_format, _export_dest)
242
+ data_format, export_dest, export_file_ext = CLIExport(
243
+ data_format, _export_dest, export_overwrite
244
+ )
223
245
  if not query:
224
246
  format = CLIFormat(data_format, export_file_ext)
225
247
  else:
@@ -324,7 +346,7 @@ def post(
324
346
 
325
347
  With `elapi` you can do the following:
326
348
  <br/>
327
- `$ elapi post users --id <user id> -d '{"firstname": "John", "lastname": "Doe", "email": "test_test@itnerd.de"}'`
349
+ `$ elapi post users -d '{"firstname": "John", "lastname": "Doe", "email": "test_test@itnerd.de"}'`
328
350
  will create a new user.
329
351
  """
330
352
  import ast
@@ -332,7 +354,7 @@ def post(
332
354
  from ..api import POSTRequest, ElabFTWURLError
333
355
  from json import JSONDecodeError
334
356
  from ..validators import Validate, HostIdentityValidator
335
- from ..plugins.utils import get_location_from_headers
357
+ from ..plugins.commons import get_location_from_headers
336
358
  from ..styles import Format, Highlight
337
359
  from ..path import ProperPath
338
360
 
@@ -670,7 +692,7 @@ def show_config(
670
692
  no_keys: Annotated[
671
693
  Optional[bool],
672
694
  typer.Option("--no-keys", help=docs["no_keys"], show_default=True),
673
- ] = True,
695
+ ] = False,
674
696
  ) -> None:
675
697
  """
676
698
  Get information about detected configuration values.