Skip to content

Commit 932b1b7

Browse files
authored
Merge pull request #60 from drscholly/core/better_links
Enhance copy_links and some code cleaning
2 parents c1353e3 + 0833297 commit 932b1b7

17 files changed

+229
-876
lines changed

README.md

Lines changed: 108 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,64 @@
1-
# Toolbox
1+
# DataGalaxy Toolbox
22

33
[![Build status](../../workflows/CI/badge.svg)](../../actions?query=workflow%3ACI)
44

5-
Toolbox allows you to perform admin operations on [DataGalaxy](https://www.datagalaxy.com).
5+
Welcome to the DataGalaxy Toolbox!
6+
7+
This is an opensource command-line tool that allows to perform admin operations on [DataGalaxy](https://www.datagalaxy.com).
68

79
## Features
8-
- **Copy attributes** from a source client space to a target client space.
9-
- **Delete attributes** on client space.
10-
- **Copy technologies** from a source client space to a target client space.
11-
- **Copy screens** from a source client space or workspace to a target client space or workspace.
12-
- **Copy glossary** properties from a workspace to another.
13-
- **Delete glossary** of a workspace.
10+
### Clientspace operations
11+
- **Copy custom attributes** from a clientspace to another.
12+
- **Delete custom attributes** on a clientspace.
13+
- **Copy technologies** from a clientspace to another.
14+
15+
### Clientspace / workspace operations
16+
- **Copy screens** from a clientspace (or workspace) to another clientspace (or workspace).
17+
18+
### Workspace operations
19+
Note that the workspaces can be on different clientspaces.
20+
- **Copy glossary** objects from a workspace to another.
1421
- **Copy dictionary** objects from a workspace to another.
15-
- **Delete dictionary** of a workspace.
16-
- **Copy dataprocessings** from a workspace to another.
17-
- **Delete dataprocessings** of a workspace.
18-
- **Copy usages** from a workspace to another.
19-
- **Delete usages** of a workspace.
22+
- **Copy dataprocessings** objects from a workspace to another.
23+
- **Copy usages** objects from a workspace to another.
2024
- **Copy links** from a workspace to another.
25+
- **Delete glossary** objects of a workspace.
26+
- **Delete dictionary** objects of a workspace.
27+
- **Delete dataprocessings** objects of a workspace.
28+
- **Delete usages** objects of a workspace.
29+
30+
#### General remarks
31+
- As DataGalaxy do not support link creation when the objects do not already exist in the target workspace, we suggest that you run the copy commands in this order:
32+
1. `copy-glossary`, `copy-dictionary`, `copy-usages` (order doesn't matter)
33+
2. `copy-dataprocessings` (as they can have dataProcessingItems that connect dictionary elements, this command might fail if you run it before copying the dictionary)
34+
3. `copy-links` (this command will fail if you haven't copied all the objects before)
35+
- All module copy commands will fail if the source objects have a custom technology value that do not exist in the target clientspace (there is no issue if you run the module copy in the same clientspace). As a consequence, we suggest that you run `copy-technologies` before copying modules.
36+
- All copy module commands will fail if the source objects have a custom tag value that do not exist in the target clientspace (there is no issue if you run the module copy in the same clientspace). As a consequence, we suggest that you run `copy-attributes` before copying modules.
2137

2238
## Installation
2339

24-
For now we provide an executable file `datagalaxy-toolbox.exe` which makes Toolbox usable only on Windows.
40+
An executable file `datagalaxy-toolbox.exe` is provided, which makes the DataGalaxy Toolbox usable only on Windows.
2541
You can download it from the `Assets` section of the [Releases page](https://github.com/datagalaxy-lab/datagalaxy-toolbox/releases).
26-
If you want to use Toolbox on Mac or Linux you need to build a binary file following the [development](#development) section.
2742

28-
## Usage
43+
If you want to use the DataGalaxy Toolbox on MacOS or Unix, you need to build a binary file following the [development](#development) section.
2944

30-
### CLI
45+
## How to use
3146

32-
##### Flags
47+
##### Parameters
3348
- [optional arguments] `-h`, `--help`- show help message
34-
- `--url` - URL
35-
- `--token` - Token
36-
- `--url-source`- URL source environnement
37-
- `--url-target` - URL target environnement
38-
- `--token-source` - Token from source environnement
39-
- `--token-target` - Token from target environnement
40-
- `--workspace-source` - Workspace source name
41-
- `--workspace-target` - Workspace target name
49+
- `--url` - The API URL of your DataGalaxy environment
50+
- `--token` - A DataGalaxy Token, either an Integration Token or a Personal Access Token
51+
- `--url-source`- The API URL of the source environnement
52+
- `--url-target` - The API URL of the target environnement
53+
- `--token-source` - A DataGalaxy Token from the source environnement
54+
- `--token-target` - A DataGalaxy Token from the Token from target environnement
55+
- `--workspace-source` - The name of the source workspace
56+
- `--workspace-target` - The name of the target workspace
4257
- `--tag-value` - Filter objects on a specific tag
4358

4459

4560

46-
47-
48-
#### delete-attributes
49-
50-
Toolbox checks that there is no identical attribute on the target client space before running the copy from the source. It raises an exception and stops the program if it finds duplicate attributes.
51-
To delete attributes from the target client space to allow copying run:
52-
```
53-
datagalaxy-toolbox.exe delete-attributes [-h] --url URL --token TOKEN
54-
```
61+
### Clientspace operations
5562

5663
#### copy-attributes
5764

@@ -65,91 +72,114 @@ datagalaxy-toolbox.exe copy-attributes [-h] --url-source URL_SOURCE --url-target
6572
datagalaxy-toolbox.exe copy-technologies [-h] --url-source URL_SOURCE --url-target URL_TARGET --token-source TOKEN_SOURCE --token-target TOKEN_TARGET
6673
```
6774

75+
#### delete-attributes
76+
77+
```
78+
datagalaxy-toolbox.exe delete-attributes [-h] --url URL --token TOKEN
79+
```
80+
81+
### Clientspace / Workspace operations
82+
6883
#### copy-screens
6984

7085
```
7186
datagalaxy-toolbox.exe copy-screens [-h] --url-source URL_SOURCE [--url-target URL_TARGET] --token-source TOKEN_SOURCE [--token-target TOKEN_TARGET] [--workspace-source WORKSPACE_SOURCE] [--workspace-target WORKSPACE_TARGET]
7287
```
73-
`--url-target` and `--token-target` are optional if the copy is made on the same client space.
88+
`--url-target` and `--token-target` are optional if the copy is made on the same clientspace.
7489

75-
`--workspace-source` is optional if the copy is made from a client space.
90+
`--workspace-source` is optional if the copy is made from a clientspace.
7691

77-
`--workspace-target` is optional if the copy is made to a client space.
92+
`--workspace-target` is optional if the copy is made to a clientspace.
7893

7994
4 scenarios are possible:
80-
- Copy screens from a client space to another client space (different client spaces)
81-
- Copy screens from a workspace to a client space (can be on the same client space or not)
82-
- Copy screens from a client space to a workspace (can be on the same client space or not)
83-
- Copy screens from a workspace to another workspace (can be on the same client space or not)
95+
- Copy screens from a clientspace to another clientspace (different clientspaces)
96+
- Copy screens from a workspace to a clientspace (can be on the same clientspace or not)
97+
- Copy screens from a clientspace to a workspace (can be on the same clientspace or not)
98+
- Copy screens from a workspace to another workspace (can be on the same clientspace or not)
99+
100+
101+
102+
### Workspace operations
84103

85104
#### copy-glossary
86105

87106
```
88107
datagalaxy-toolbox.exe copy-glossary [-h] --url-source URL_SOURCE --token-source TOKEN_SOURCE [--url-target URL_TARGET] [--token-target TOKEN_TARGET] --workspace-source WORKSPACE_SOURCE --workspace-target WORKSPACE_TARGET [--tag-value TAG_NAME]
89108
```
90-
`--url-target` and `--token-target` are optional if the copy is made on the same client space.
109+
`--url-target` and `--token-target` are optional if the copy is made on the same clientspace.
91110

92-
#### delete-glossary
111+
112+
#### copy-dictionary
93113

94114
```
95-
datagalaxy-toolbox.exe delete-glossary [-h] --url URL --token TOKEN --workspace WORKSPACE
115+
datagalaxy-toolbox.exe copy-dictionary [-h] --url-source URL_SOURCE --token-source TOKEN_SOURCE [--url-target URL_TARGET] [--token-target TOKEN_TARGET] --workspace-source WORKSPACE_SOURCE --workspace-target WORKSPACE_TARGET [--tag-value TAG_NAME]
96116
```
117+
`--url-target` and `--token-target` are optional if the copy is made on the same clientspace.
97118

98-
#### copy-dictionary
119+
120+
#### copy-dataprocessings
99121

100122
```
101-
datagalaxy-toolbox.exe copy-dictionary [-h] --url-source URL_SOURCE --token-source TOKEN_SOURCE [--url-target URL_TARGET] [--token-target TOKEN_TARGET] --workspace-source WORKSPACE_SOURCE --workspace-target WORKSPACE_TARGET [--tag-value TAG_NAME]
123+
datagalaxy-toolbox.exe copy-dataprocessings [-h] --url-source URL_SOURCE --token-source TOKEN_SOURCE [--url-target URL_TARGET] [--token-target TOKEN_TARGET] --workspace-source WORKSPACE_SOURCE --workspace-target WORKSPACE_TARGET [--tag-value TAG_NAME]
102124
```
103-
`--url-target` and `--token-target` are optional if the copy is made on the same client space.
125+
`--url-target` and `--token-target` are optional if the copy is made on the same clientspace.
104126

105-
#### delete-dictionary
127+
128+
#### copy-usages
106129

107130
```
108-
datagalaxy-toolbox.exe delete-dictionary [-h] --url URL --token TOKEN --workspace WORKSPACE
131+
datagalaxy-toolbox.exe copy-usages [-h] --url-source URL_SOURCE --token-source TOKEN_SOURCE [--url-target URL_TARGET] [--token-target TOKEN_TARGET] --workspace-source WORKSPACE_SOURCE --workspace-target WORKSPACE_TARGET [--tag-value TAG_NAME]
109132
```
133+
`--url-target` and `--token-target` are optional if the copy is made on the same clientspace.
110134

111-
#### copy-dataprocessings
135+
136+
#### copy-links
112137

113138
```
114-
datagalaxy-toolbox.exe copy-dataprocessings [-h] --url-source URL_SOURCE --token-source TOKEN_SOURCE [--url-target URL_TARGET] [--token-target TOKEN_TARGET] --workspace-source WORKSPACE_SOURCE --workspace-target WORKSPACE_TARGET [--tag-value TAG_NAME]
139+
datagalaxy-toolbox.exe copy-links [-h] --url-source URL_SOURCE --token-source TOKEN_SOURCE [--url-target URL_TARGET] [--token-target TOKEN_TARGET] --workspace-source WORKSPACE_SOURCE --workspace-target WORKSPACE_TARGET
115140
```
116-
`--url-target` and `--token-target` are optional if the copy is made on the same client space.
141+
`--url-target` and `--token-target` are optional if the copy is made on the same clientspace.
117142

118-
#### delete-dataprocessings
143+
144+
#### delete-glossary
119145

120146
```
121-
datagalaxy-toolbox.exe delete-dataprocessings [-h] --url URL --token TOKEN --workspace WORKSPACE
147+
datagalaxy-toolbox.exe delete-glossary [-h] --url URL --token TOKEN --workspace WORKSPACE
122148
```
123149

124-
#### copy-usages
150+
151+
#### delete-dictionary
125152

126153
```
127-
datagalaxy-toolbox.exe copy-usages [-h] --url-source URL_SOURCE --token-source TOKEN_SOURCE [--url-target URL_TARGET] [--token-target TOKEN_TARGET] --workspace-source WORKSPACE_SOURCE --workspace-target WORKSPACE_TARGET [--tag-value TAG_NAME]
154+
datagalaxy-toolbox.exe delete-dictionary [-h] --url URL --token TOKEN --workspace WORKSPACE
128155
```
129-
`--url-target` and `--token-target` are optional if the copy is made on the same client space.
130156

131-
#### delete-usages
157+
158+
#### delete-dataprocessings
132159

133160
```
134-
datagalaxy-toolbox.exe delete-usages [-h] --url URL --token TOKEN --workspace WORKSPACE
161+
datagalaxy-toolbox.exe delete-dataprocessings [-h] --url URL --token TOKEN --workspace WORKSPACE
135162
```
136163

137-
#### copy-links
164+
165+
#### delete-usages
138166

139167
```
140-
datagalaxy-toolbox.exe copy-links [-h] --url-source URL_SOURCE --token-source TOKEN_SOURCE [--url-target URL_TARGET] [--token-target TOKEN_TARGET] --workspace-source WORKSPACE_SOURCE --workspace-target WORKSPACE_TARGET
168+
datagalaxy-toolbox.exe delete-usages [-h] --url URL --token TOKEN --workspace WORKSPACE
141169
```
142-
`--url-target` and `--token-target` are optional if the copy is made on the same client space.
170+
143171

144172

145173
## Development
146174

147175
### Prerequisites
148176

149-
Toolbox requires:
177+
The DataGalaxy Toolbox requires:
150178

151179
- Python >= 3.9
152180

181+
### Steps
182+
153183
1. Clone the repository
154184
2. Create a [virtual env](https://docs.python.org/3/tutorial/venv.html) in the `.venv` folder
155185
```
@@ -164,19 +194,6 @@ source .venv/bin/activate
164194
pip install -r requirements.txt
165195
````
166196

167-
### Testing
168-
169-
To run tests
170-
```
171-
python -m pytest
172-
```
173-
174-
### Linter
175-
176-
We use [Flake8](https://pypi.org/project/flake8/) as a linter
177-
```
178-
python -m flake8 .
179-
```
180197
### Build a binary file
181198

182199
run the command
@@ -191,10 +208,23 @@ This creates a **`dist`** folder with the binary file.
191208
````
192209
./dist/datagalaxy-toolbox --help
193210
````
211+
### Testing
212+
213+
To run tests
214+
```
215+
python -m pytest
216+
```
217+
218+
### Linter
219+
220+
[Flake8](https://pypi.org/project/flake8/) is used as a linter
221+
```
222+
python -m flake8 .
223+
```
194224

195225
## Contributing
196226

197-
This project welcomes contributions and suggestions.
227+
This project is not officially supported by DataGalaxy. We welcome contributions and suggestions.
198228
Please have a look at our [Guidelines](CONTRIBUTING.md) for contributing.
199229

200230
## License

tests/test_copy_dataprocessings.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
from toolbox.api.datagalaxy_api_dataprocessings import DataGalaxyApiDataprocessings
1+
from toolbox.api.datagalaxy_api_modules import DataGalaxyApiModules
22
from toolbox.commands.copy_dataprocessings import copy_dataprocessings
33
from toolbox.api.datagalaxy_api_workspaces import DataGalaxyApiWorkspace
44
import pytest as pytest
55

66

77
# Mocks
88

9-
def mock_list_dataprocessings_on_source_workspace(self, workspace_name):
9+
def mock_list_objects_on_source_workspace(self, workspace_name):
1010
if workspace_name == 'workspace_source':
11-
return ['dataprocessing1', 'dataprocessing2', 'dataprocessing3']
11+
return [['object1', 'object2', 'object3']]
1212
return []
1313

1414

1515
# Scenarios
1616

17-
def test_copy_dataprocessings_when_workspace_source_does_not_exist(mocker):
17+
def test_copy_dataprocessings_when_workspace_target_does_not_exist(mocker):
1818
# GIVEN
1919
workspaces = mocker.patch.object(DataGalaxyApiWorkspace, 'list_workspaces', autospec=True)
2020
workspaces.return_value = ['workspace_source']
2121
workspace_source_mock = mocker.patch.object(DataGalaxyApiWorkspace, 'get_workspace', autospec=True)
2222
workspace_source_mock.return_value = None
23-
dataprocessings_on_source_workspace_mock = mocker.patch.object(
24-
DataGalaxyApiDataprocessings,
25-
'list_dataprocessings',
23+
objects_on_source_workspace_mock = mocker.patch.object(
24+
DataGalaxyApiModules,
25+
'list_objects',
2626
autospec=True
2727
)
28-
dataprocessings_on_source_workspace_mock.side_effect = mock_list_dataprocessings_on_source_workspace
28+
objects_on_source_workspace_mock.side_effect = mock_list_objects_on_source_workspace
2929

3030
# ASSERT / VERIFY
3131
with pytest.raises(Exception, match='workspace workspace_source does not exist'):

tests/test_copy_glossary.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from toolbox.api.datagalaxy_api_modules import DataGalaxyApiModules
22
from toolbox.api.datagalaxy_api_workspaces import DataGalaxyApiWorkspace
33
from toolbox.commands.copy_glossary import copy_glossary
4-
from toolbox.api.datagalaxy_api import DataGalaxyBulkResult
54
import pytest as pytest
65

76

@@ -32,13 +31,7 @@ def test_copy_objects_when_no_object_on_target(mocker):
3231
'bulk_upsert_tree',
3332
autospec=True
3433
)
35-
bulk_upsert_objects_on_target_workspace_mock.return_value = DataGalaxyBulkResult(
36-
total=3,
37-
created=3,
38-
updated=0,
39-
unchanged=0,
40-
deleted=0
41-
)
34+
bulk_upsert_objects_on_target_workspace_mock.return_value = 0
4235

4336
# THEN
4437
result = copy_glossary(
@@ -53,7 +46,7 @@ def test_copy_objects_when_no_object_on_target(mocker):
5346

5447
# ASSERT / VERIFY
5548

56-
assert result == DataGalaxyBulkResult(total=3, created=3, updated=0, unchanged=0, deleted=0)
49+
assert result == 0
5750
assert objects_on_source_workspace_mock.call_count == 1
5851
assert bulk_upsert_objects_on_target_workspace_mock.call_count == 1
5952

tests/test_copy_usages.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from toolbox.api.datagalaxy_api_modules import DataGalaxyApiModules
22
from toolbox.commands.copy_usages import copy_usages
33
from toolbox.api.datagalaxy_api_workspaces import DataGalaxyApiWorkspace
4-
from toolbox.api.datagalaxy_api import DataGalaxyBulkResult
54
import pytest as pytest
65

76

@@ -32,13 +31,7 @@ def test_copy_objects_when_no_object_on_target(mocker):
3231
'bulk_upsert_tree',
3332
autospec=True
3433
)
35-
bulk_upsert_objects_on_target_workspace_mock.return_value = DataGalaxyBulkResult(
36-
total=3,
37-
created=3,
38-
updated=0,
39-
unchanged=0,
40-
deleted=0
41-
)
34+
bulk_upsert_objects_on_target_workspace_mock.return_value = 0
4235

4336
# THEN
4437
result = copy_usages(
@@ -53,7 +46,7 @@ def test_copy_objects_when_no_object_on_target(mocker):
5346

5447
# ASSERT / VERIFY
5548

56-
assert result == DataGalaxyBulkResult(total=3, created=3, updated=0, unchanged=0, deleted=0)
49+
assert result == 0
5750
assert objects_on_source_workspace_mock.call_count == 1
5851
assert bulk_upsert_objects_on_target_workspace_mock.call_count == 1
5952

0 commit comments

Comments
 (0)