Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
rocolib
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
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
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mehtank
rocolib
Commits
e2e04b35
Commit
e2e04b35
authored
3 years ago
by
mehtank
Browse files
Options
Downloads
Patches
Plain Diff
Add new cli features
parent
b9fe202f
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+6
-0
6 additions, 0 deletions
.gitignore
rocolib/__main__.py
+41
-11
41 additions, 11 deletions
rocolib/__main__.py
rocolib/api/components/Component.py
+13
-0
13 additions, 0 deletions
rocolib/api/components/Component.py
with
60 additions
and
11 deletions
.gitignore
+
6
−
0
View file @
e2e04b35
# Vim swapfiles
*.sw[a-p]
# Roco output directories
output/
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
...
...
This diff is collapsed.
Click to expand it.
rocolib/__main__.py
+
41
−
11
View file @
e2e04b35
#!/bin/env python
import
yaml
import
sys
import
logging
import
argparse
...
...
@@ -12,7 +13,7 @@ def test(component, params, thickness, display=False, display3D=False):
f
=
getComponent
(
component
)
if
params
is
not
None
:
for
p
in
params
:
f
.
setParameter
(
p
[
0
],
eval
(
p
[
1
]))
f
.
setParameter
(
p
[
0
],
eval
(
str
(
p
[
1
]))
)
if
thickness
is
None
:
t
=
0
j
=
None
...
...
@@ -29,16 +30,18 @@ if __name__ == '__main__':
parser
=
argparse
.
ArgumentParser
()
cmd
=
parser
.
add_
mutually_exclusive_group
(
required
=
True
)
cmd
.
add_argument
(
"
component
"
,
nargs
=
'
?
'
,
help
=
"
Name of the component you
'
d like to test (cannot be used with --list/-l)
"
)
cmd
.
add_argument
(
"
--list
"
,
"
-l
"
,
action
=
'
store_true
'
,
help
=
"
List all known library components
(cannot be used with component)
"
)
parser
.
add_
argument
(
"
component
"
,
nargs
=
'
?
'
,
help
=
"
Name of the component you
'
d like to test
"
)
parser
.
add_argument
(
"
--file
"
,
"
-f
"
,
type
=
str
,
help
=
"
Load component and parameters from file
"
)
parser
.
add_argument
(
"
--list
"
,
"
-l
"
,
action
=
'
store_true
'
,
help
=
"
List all known library components
"
)
parser
.
add_argument
(
"
--verbose
"
,
"
-v
"
,
help
=
"
Increase logging level (can be used multiple times)
"
,
dest
=
"
log_level
"
,
action
=
"
append_const
"
,
const
=-
1
)
parser
.
add_argument
(
"
--quiet
"
,
"
-q
"
,
help
=
"
Decrease logging level (can be used multiple times)
"
,
dest
=
"
log_level
"
,
action
=
"
append_const
"
,
const
=
1
)
parser
.
add_argument
(
"
-I
"
,
help
=
"
List component interfaces (use multiple times for more detail)
"
,
dest
=
"
interface_list
"
,
action
=
"
append_const
"
,
const
=
1
)
parser
.
add_argument
(
"
-P
"
,
help
=
"
List component parameters (use multiple times for more detail)
"
,
dest
=
"
param_list
"
,
action
=
"
append_const
"
,
const
=
1
)
parser
.
add_argument
(
"
-t
"
,
type
=
float
,
help
=
"
Thickness (i.e. making with wood)
"
)
...
...
@@ -62,7 +65,34 @@ if __name__ == '__main__':
log_level_name
=
LOG_LEVELS
[
log_level
]
logging
.
basicConfig
(
level
=
getattr
(
logging
,
log_level_name
))
acted
=
False
if
args
.
list
:
t
=
getComponentTree
()
for
i
,
cs
in
enumerate
(
t
):
chunks
=
[
cs
[
x
:
x
+
4
]
for
x
in
range
(
0
,
len
(
cs
),
4
)]
print
(
f
"
{
i
:
2
}
:
"
+
"
\n
"
.
join
((
"
"
.
join
(
x
)
for
x
in
chunks
)))
acted
=
True
if
args
.
file
:
with
open
(
args
.
file
)
as
f
:
config
=
yaml
.
safe_load
(
f
)
args
.
component
=
args
.
component
or
config
.
pop
(
"
$component
"
,
None
)
args
.
t
=
args
.
t
or
config
.
pop
(
"
$thickness
"
,
None
)
if
args
.
p
:
config
.
update
(
dict
(
args
.
p
))
args
.
p
=
list
(
config
.
items
())
if
args
.
component
:
if
args
.
interface_list
:
f
=
getComponent
(
args
.
component
)
info
=
f
.
getInterfaceInfo
(
len
(
args
.
interface_list
))
if
len
(
args
.
interface_list
)
==
1
:
print
(
"
\n
"
.
join
(
info
))
else
:
pprint
(
info
)
if
not
args
.
p
or
args
.
t
or
args
.
d
or
args
.
D
:
exit
(
0
)
if
args
.
param_list
:
f
=
getComponent
(
args
.
component
)
info
=
f
.
getParameterInfo
()
...
...
@@ -78,8 +108,8 @@ if __name__ == '__main__':
if
not
args
.
p
or
args
.
t
or
args
.
d
or
args
.
D
:
exit
(
0
)
test
(
args
.
component
,
args
.
p
,
thickness
=
args
.
t
,
display
=
args
.
d
,
display3D
=
args
.
D
)
elif
args
.
list
:
t
=
getComponentTree
()
for
i
,
cs
in
enumerate
(
t
)
:
chunks
=
[
cs
[
x
:
x
+
4
]
for
x
in
range
(
0
,
len
(
cs
),
4
)]
print
(
f
"
{
i
:
2
}
:
"
+
"
\n
"
.
join
((
"
"
.
join
(
x
)
for
x
in
chunks
))
)
acted
=
True
if
not
acted
:
parser
.
print_help
(
sys
.
stderr
)
sys
.
exit
(
1
)
This diff is collapsed.
Click to expand it.
rocolib/api/components/Component.py
+
13
−
0
View file @
e2e04b35
...
...
@@ -113,6 +113,19 @@ class Component(Parameterized):
### Override in Component instance to define individual parameters, interfaces, etc.
pass
def
getInterfaceInfo
(
self
,
detail
=
1
):
if
detail
==
1
:
return
list
(
self
.
interfaces
.
keys
())
if
detail
==
2
:
return
{
x
:
self
.
getInterface
(
x
,
transient
=
True
).
__class__
.
__name__
for
x
in
self
.
interfaces
}
i
=
{
x
:
dict
(
port
=
self
.
getInterface
(
x
,
transient
=
True
).
__class__
.
__name__
)
for
x
in
self
.
interfaces
}
for
k
,
v
in
self
.
interfaces
.
items
():
if
isinstance
(
v
,
dict
):
i
[
k
].
update
(
v
)
return
i
###
# DESIGN PHASE
###
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
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