Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
asn1-value-editor
Commits
3a7123d1
Commit
3a7123d1
authored
Jul 16, 2016
by
Maxime Perrotin
Browse files
Standalone editor needs DV.py
parent
f07ad281
Changes
2
Hide whitespace changes
Inline
Side-by-side
asn1_value_editor/asn1_value_editor.py
View file @
3a7123d1
...
...
@@ -510,9 +510,16 @@ class asn1Editor(QTreeView):
self
.
updateModel
(
root
,
ptr
=
asn1Instance
,
nbRows
=
nbElem
)
elif
asnType
==
'CHOICE'
:
kind
=
asn1Instance
.
kind
.
Get
()
print
kind
,
self
.
model
.
item
(
row
,
3
).
data
(
INTMAP
)
# get the mapping to retrieve the choice name from the kind
intMappings
=
self
.
model
.
item
(
row
,
3
).
data
(
INTMAP
)
for
enumerant
,
num
in
intMappings
.
viewitems
():
try
:
# When using datamodel from standalone editor (OG simu)
import
DV
num
=
getattr
(
DV
,
num
)
except
(
ImportError
,
AttributeError
)
as
err
:
print
(
'XXX - discard when tested:'
+
str
(
err
))
if
num
==
kind
:
break
else
:
...
...
@@ -539,7 +546,7 @@ class asn1Editor(QTreeView):
self
.
model
.
item
(
row
,
3
).
setText
(
enumerant
)
break
else
:
self
.
log
.
error
(
"ENUMERATED value not found"
)
self
.
log
.
error
(
"ENUMERATED value
'{}'
not found"
.
format
(
value
)
)
else
:
# SEQUENCE or SET
self
.
updateModel
(
root
,
asn1Instance
)
if
asnType
in
(
'INTEGER'
,
'REAL'
,
'SEQOF'
):
...
...
asn1_value_editor/standalone_editor.py
View file @
3a7123d1
...
...
@@ -35,15 +35,14 @@ from shutil import rmtree
import
resources
__author__
=
'Maxime Perrotin'
__version__
=
'1.0.0'
__author__
=
'Maxime Perrotin'
__licence__
=
'LGPL v3'
__url__
=
'http://taste.tuxfamily.org'
__url__
=
'http://taste.tuxfamily.org'
from
ColorFormatter
import
ColorFormatter
# Set up the logging facilities
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
console
=
logging
.
StreamHandler
(
sys
.
__stdout__
)
console
.
setFormatter
(
ColorFormatter
())
logger
.
addHandler
(
console
)
...
...
@@ -56,23 +55,24 @@ try:
import
opengeode.Asn1scc
as
asn1scc
asn1scc
.
LOG
=
logger
except
ImportError
:
print
'PySide or Open
geode missing...'
asn1scc
=
None
logger
.
error
(
'PySide or Open
GEODE import error'
)
sys
.
exit
(
1
)
usable
=
True
try
:
UI_FILE
=
':/singleEditor.ui'
# sys.path.append(taste_inst+'/share/asn1-editor/')
# dmt = os.popen('taste-config --dmt').readlines()[0].strip()
# asn1scc = os.path.join(dmt, 'asn1scc')
# PYTHON_STG = os.path.join(asn1scc, 'python.stg')
# sys.path.append('.')
from
asn1_value_editor
import
asn1Editor
from
vn
import
fromValueNotationToPySide
,
toASN1ValueNotation
except
:
usable
=
False
except
ImportError
:
logger
.
error
(
'ASN1 Value Editor import error'
)
sys
.
exit
(
1
)
# DV.py is generated from asn2dataModel (DMT tools)
# It containts constants related to the enumerated and choice types
# If not present it will be generated on the fly using opengeode's API
try
:
import
DV
except
ImportError
:
DV
=
None
def
asn1sccToasn1ValueEditorTypes
(
dataview
,
name
,
asntype
):
''' Convert an ASN.1 type from the Python AST of asn1scc v3
...
...
@@ -123,7 +123,7 @@ def asn1sccToasn1ValueEditorTypes(dataview, name, asntype):
for
child
,
childtype
in
t
.
Children
.
viewitems
():
result
[
'choices'
].
append
(
asn1sccToasn1ValueEditorTypes
(
dataview
,
child
,
childtype
.
type
))
result
[
'choiceIdx'
]
=
{
enumerant
:
"
DV.
{}"
.
format
(
chty
.
EnumID
)
result
[
'choiceIdx'
]
=
{
enumerant
:
"{}"
.
format
(
chty
.
EnumID
)
for
enumerant
,
chty
in
t
.
Children
.
viewitems
()}
elif
t
.
kind
.
endswith
(
'StringType'
):
result
[
'type'
]
=
'STRING'
...
...
@@ -152,6 +152,14 @@ class SingleValueEditor(QObject):
self
.
parent
=
parent
self
.
tc
=
{}
global
DV
if
not
DV
:
try
:
DV
=
asn1scc
.
asn2dataModel
(
asnFile
).
DV
except
TypeError
as
err
:
logger
.
error
(
'Could not execute asn2dataModel: '
+
str
(
err
))
sys
.
exit
(
1
)
try
:
logger
.
info
(
asnFile
)
dataView
=
asn1scc
.
parse_asn1
([
asnFile
],
...
...
@@ -181,14 +189,16 @@ class SingleValueEditor(QObject):
widget
=
self
.
widgets
[
asnType
][
'widget'
]
try
:
# If the parent is a widget, this will place the window in the center of the parent
# If the parent is a widget, this will place the window
# in the center of the parent
widget
.
setParent
(
self
.
parent
)
except
:
logger
.
info
(
'No parent widget - window will be placed randomly'
)
pyType
=
self
.
tc
[
asnType
]
self
.
widgets
[
asnType
][
'editor'
]
=
widget
.
findChild
(
asn1Editor
,
'ASN1EDITOR'
)
self
.
widgets
[
asnType
][
'editor'
]
=
widget
.
findChild
(
asn1Editor
,
'ASN1EDITOR'
)
self
.
widgets
[
asnType
][
'editor'
].
log
=
logger
okButton
=
widget
.
findChild
(
QToolButton
,
'okButton'
)
cancelButton
=
widget
.
findChild
(
QToolButton
,
'cancelButton'
)
...
...
@@ -266,8 +276,8 @@ def main():
# Exit app on Ctrl-C
signal
.
signal
(
signal
.
SIGINT
,
signal
.
SIG_DFL
)
usage
=
'usage: asn1_value_editor -a file.asn
[
-t type
]
[-d default value]'
version
=
'ASN.1 Value Editor
%s'
%
(
__version__
)
usage
=
'usage: asn1_value_editor -a file.asn -t type [-d default value]'
version
=
'ASN.1 Value Editor
'
logger
.
info
(
'Starting ASN.1 Value Editor'
)
...
...
@@ -303,7 +313,6 @@ def main():
# Open the value editor and retrieve the value, if Cancel has not been pressed
result
=
s
.
editParam
(
options
.
asnType
,
options
.
asnValue
)
# s.cleanUp()
if
result
is
not
None
:
print
result
sys
.
exit
(
0
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment