Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
nanospace-python-client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nanostar
nanospace
nanospace-clients
nanospace-python-client
Commits
d64f8711
Commit
d64f8711
authored
Jul 24, 2019
by
lucien senaneuch
Committed by
GATEAU Thibault
Dec 19, 2022
Browse files
Options
Downloads
Patches
Plain Diff
[Create, Delete functions] implements create and delete function for all elements
parent
471e1d43
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+28
-0
28 additions, 0 deletions
README.md
nanospace.py
+94
-3
94 additions, 3 deletions
nanospace.py
simple_example.py
+11
-5
11 additions, 5 deletions
simple_example.py
with
133 additions
and
8 deletions
README.md
+
28
−
0
View file @
d64f8711
...
...
@@ -19,6 +19,34 @@ nanospace.update_value(66, 'sma', '9000000')
print
(
nanospace
.
get_value
(
66
))
# 9000000
```
### Creation of element
It is also possibile to create component, value, and modes from python. However, we advice to use the UI instead.
```
python
# from nanospace import Nanospace
# nanospace = Nanospace('http://yourSrvUrl/','yourUsername', 'yourPassword')
nanospace
.
_create_component
(
12
,
'
new_component)
nanospace._create_mode(12, my_new_mode)
nanospace._create_string_value(45,
''
)
```
If the id is missing check the nanospace_ui url can help you to get one.
Then each one of the _create_ function are returning a python dictionary where you can find id.
### Delete a element
Even if it is advise to delete element from the UI we give also the possibilities to delete element from python.
```
python
# from nanospace import Nanospace
# nanospace = Nanospace('http://yourSrvUrl/','yourUsername', 'yourPassword')
nanospace
.
_delete_component
(
12
)
nanospace
.
_delete_mode
(
45
)
nanospace
.
_delete_value
(
63
)
```
Note that __delete_value__ is working either if the value is a formula, or a string
## Bash client
...
...
This diff is collapsed.
Click to expand it.
nanospace.py
+
94
−
3
View file @
d64f8711
...
...
@@ -208,13 +208,13 @@ class Nanospace:
# return r_data
def
create_component
(
self
,
idParent
,
componentName
):
def
_
create_component
(
self
,
idParent
,
componentName
):
"""
Create a component children of the parent passed as id
Return
the
a JSON component
Return a JSON component
:Exemple:
nanospace.create_component(89,
'
mySuperComponent
'
)
nanospace.
_
create_component(89,
'
mySuperComponent
'
)
"""
r
=
rq
.
post
(
self
.
ApiBaseAddress
+
'
component?parentId=
'
+
str
(
idParent
),
json
=
{
'
name
'
:
componentName
},
headers
=
self
.
headers
)
r_data
=
r
.
json
()
...
...
@@ -223,6 +223,97 @@ class Nanospace:
else
:
return
r_data
def
_create_mode
(
self
,
idParent
,
modeName
):
"""
Create a mode of a component parent passed as id
Return the a JSON component
:Exemple:
nanospace._create_mode(28,
'
test-mode
'
)
"""
r
=
rq
.
post
(
self
.
ApiBaseAddress
+
'
mode?parentId=
'
+
str
(
idParent
),
json
=
{
'
name
'
:
modeName
},
headers
=
self
.
headers
)
r_data
=
r
.
json
()
if
r
.
status_code
<
200
or
r
.
status_code
>=
300
:
raise
ValueError
(
r_data
)
else
:
return
r_data
def
_create_string_value
(
self
,
idParent
,
valueName
,
value
):
"""
Create a string of a mode parent passed as id
Return the a JSON component
:Exemple:
nanospace._create_string_value(28,
'
string_value
'
,
'
Hello-World
'
)
"""
r
=
rq
.
post
(
self
.
ApiBaseAddress
+
'
string?parentId=
'
+
str
(
idParent
),
json
=
{
'
name
'
:
valueName
,
'
value
'
:
value
,
'
type
'
:
'
string_value
'
},
headers
=
self
.
headers
)
r_data
=
r
.
json
()
if
r
.
status_code
<
200
or
r
.
status_code
>=
300
:
raise
ValueError
(
r_data
)
else
:
return
r_data
def
_create_formula_value
(
self
,
idParent
,
valueName
,
value
):
"""
Create a formula of a mode parent passed as id
Return the a JSON component
:Exemple:
nanospace._create_formula_value(28,
'
value
'
,
'
5*8
'
)
"""
r
=
rq
.
post
(
self
.
ApiBaseAddress
+
'
formula?parentId=
'
+
str
(
idParent
),
json
=
{
'
name
'
:
valueName
,
'
formula
'
:
value
,
'
type
'
:
'
string_value
'
},
headers
=
self
.
headers
)
r_data
=
r
.
json
()
if
r
.
status_code
<
200
or
r
.
status_code
>=
300
:
raise
ValueError
(
r_data
)
else
:
return
r_data
def
_delete_value
(
self
,
idValue
):
"""
Delete a value which the id has been passed as parameter
Return the a JSON component
:Exemple:
nanospace._delete_value(28)
"""
r
=
rq
.
delete
(
self
.
ApiBaseAddress
+
'
value/
'
+
str
(
idValue
),
headers
=
self
.
headers
)
# r_data = r.json()
# if r.status_code < 200 or r.status_code >= 300:
# raise ValueError(r_data)
# else:
# return r_data
def
_delete_mode
(
self
,
idMode
):
"""
Delete a mode which the id has been passed as parameter
Return the a JSON component
:Exemple:
nanospace._delete_mode(28)
"""
r
=
rq
.
delete
(
self
.
ApiBaseAddress
+
'
mode/
'
+
str
(
idMode
),
headers
=
self
.
headers
)
# r_data = r.json()
# if r.status_code < 200 or r.status_code >= 300:
# raise ValueError(r_data)
# else:
# return r_data
def
_delete_component
(
self
,
idComponent
):
"""
Delete a component which the id has been passed as parameter
Return the a JSON component
:Exemple:
nanospace._delete_component(28)
"""
r
=
rq
.
delete
(
self
.
ApiBaseAddress
+
'
component/
'
+
str
(
idComponent
),
headers
=
self
.
headers
)
# r_data = r.json()
# if r.status_code < 200 or r.status_code >= 300:
# raise ValueError(r_data)
# else:
# return r_data
def
setApiBaseAddress
(
self
,
url
):
'''
...
...
This diff is collapsed.
Click to expand it.
simple_example.py
+
11
−
5
View file @
d64f8711
from
nanospace
import
Nanospace
usr
=
'
usr
'
pw
=
'
usrPw
'
usr
=
'
lucien
'
pw
=
'
coucou
'
srvAddr
=
'
http://localhost:8888/
'
nanospace
=
Nanospace
(
srvAddr
,
usr
,
pw
)
print
(
nanospace
.
get_string_value
(
83
))
nanospace
.
update__string_value
(
83
,
'
test
'
,
'
1Kg5
'
)
print
(
nanospace
.
get_formula_value
(
84
))
nanospace
.
update__formula_value
(
84
,
'
multiplication
'
,
'
5*20
'
)
# create component
nanospace
.
create_component
(
40
,
'
newComponent
'
)
\ No newline at end of file
nanospace
.
update_formula_value
(
84
,
'
multiplication
'
,
'
5*20
'
)
create
component
nanospace
.
_create_component
(
40
,
'
newComponent
'
)
nanospace
.
_create_formula_value
(
231
,
'
test2
'
,
'
5*5
'
)
nanospace
.
_create_string_value
(
231
,
'
test3
'
,
'
Hello-world
'
)
nanospace
.
_create_mode
(
60
,
'
new_mode
'
)
nanospace
.
_delete_component
(
60
)
nanospace
.
_delete_value
(
102
)
nanospace
.
_delete_mode
(
231
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment