Commit 44a59893 authored by Maxime Perrotin's avatar Maxime Perrotin

Asn1SCC API improvement

parent c87ec835
......@@ -17,11 +17,11 @@ import subprocess
import tempfile
import uuid
import os
import distutils.spawn as spawn
import sys
import importlib
import logging
import PySide.QtCore as Qt
import icons
LOG = logging.getLogger(__name__)
......@@ -57,20 +57,21 @@ def parse_asn1(*files, **options):
assert isinstance(ast_version, ASN1)
assert isinstance(flags, list)
asn1scc_root = os.path.dirname(spawn.find_executable('asn1.exe'))
tempdir = tempfile.mkdtemp()
filename = str(uuid.uuid4()).replace('-', '_')
filepath = tempdir + os.sep + filename + '.py'
# dump python.stg in the temp directory
stg = Qt.QFile(':misc/python.stg')
stg_data = stg.readData(stg.size())
tmp_stg = tempdir + os.sep + 'python.stg'
with open(tmp_stg, 'w') as fd:
fd.write(stg_data)
#stg = Qt.QFile(':misc/python.stg')
#stg_data = stg.readData(stg.size())
stg = asn1scc_root + os.sep + 'python.stg'
#with open(tmp_stg, 'w') as fd:
# fd.write(stg_data)
args = ['asn1.exe',
'-customStgAstVerion', str(ast_version.value),
'-customStg', tmp_stg + ':' + filepath] + list(*files)
'-customStg', stg + ':' + filepath] + list(*files)
LOG.debug('Calling: ' + ' '.join(args))
try:
......
This diff is collapsed.
group python;
//delimiters "$", "$"
RootXml(arrsFiles) ::= <<
#!/usr/bin/env python
# ASN.1 Data model
asn1Files = []
asn1Modules = []
exportedTypes = {}
exportedVariables = {}
importedModules = {}
types = {}
$arrsFiles;separator="\n"$
>>
FileXml(sFileName, arrsModules) ::= <<
asn1Files.append("$sFileName$")
$arrsModules;separator="\n"$
>>
ModuleXml(sName, arrsImportedModules, arrsExpTypes, arrsExpVars, arrsTases) ::=<<
asn1Modules.append("$sName$")
exportedTypes["$sName$"] = [$arrsExpTypes:{x|"$x$"};separator=", "$]
exportedVariables["$sName$"] = [$arrsExpVars:{x|"$x$"};separator=", "$]
importedModules["$sName$"] = [$arrsImportedModules:{x|$x$};separator=", "$]
$arrsTases;separator="\n"$
>>
ImportedMod(sName, arrsTypes, arrsVars) ::= <<
{"$sName$":{"ImportedTypes": [$arrsTypes:{t|"$t$"};separator=","$], "ImportedVariables": [$arrsVars:{t|"$t$"};separator=","$]}}
>>
TasXml(sName, nLine, nPos, sType) ::= <<
types["$sName$"] = type("$sName$", (object,), {
"Line": $nLine$, "CharPositionInLine": $nPos$, "type": type("$sName$_type", (object,), {
$sType$
})
})
>>
TypeGeneric(nLine, nPos, sSubType) ::= <<
"Line": $nLine$, "CharPositionInLine": $nPos$, $sSubType$
>>
MinMaxType(sName, sMin, sMax) ::= <<
"kind": "$sName$", "Min": "$sMin$", "Max": "$sMax$"
>>
MinMaxType2(sName, sMin, sMax) ::= <<
"kind": "$sName$", "Min": "$sMin$", "Max": "$sMax$"
>>
BooleanType () ::= <<"kind": "BooleanType">>
NullType () ::= <<"kind": "NullType">>
EnumItem (sName, nVal, nLine, nPos, sCID) ::= <<
"$sName$": type("$sCID$", (object,), {
"IntValue": $nVal$, "Line": $nLine$, "CharPositionInLine": $nPos$, "EnumID": "$sCID$"
})
>>
EnumType(arrsItems) ::= <<
"kind": "EnumeratedType", "Extensible": "False", "ValuesAutoCalculated": "False", "EnumValues": {
$arrsItems;separator=",\n"$
}
>>
ChoiceChild(sName, nLine, nPos, sChildContent, sNamePresent ) ::= <<
"$sName$": type("$sNamePresent$", (object,), {
"Line": $nLine$, "CharPositionInLine": $nPos$, "EnumID": "$sNamePresent$", "type": type("$sNamePresent$_type", (object,), {
$sChildContent$
})
})
>>
ChoiceType(arrsChildren) ::= <<
"kind": "ChoiceType", "Children": {
$arrsChildren;separator=",\n"$
}
>>
SequenceChild(sName, bOptional, sDefVal, nLine, nPos, sChildContent ) ::= <<
"$sName$": type("$sName$", (object,), {
"Optional": "$bOptional$"$if(sDefVal)$, "DefaultValue": "$sDefVal$"$endif$, "Line": $nLine$, "CharPositionInLine": $nPos$, "type": type("$sName$_type", (object,), {
$sChildContent$
})
})
>>
SequenceType(arrsChildren) ::= <<
"kind": "SequenceType", "Children": {
$arrsChildren;separator=",\n"$
}
>>
SequenceOfType(sMin, sMax, sChild) ::= <<
"kind": "SequenceOfType", "Min": "$sMin$", "Max": "$sMax$", "type": type("SeqOf_type", (object,), {
$sChild$
})
>>
RefTypeMinMax(sMin, sMax, sName, sModName) ::= <<
"kind": "ReferenceType", "ReferencedTypeName": "$sName$", "Min": "$sMin$", "Max": "$sMax$"$if(sModName)$, "ReferencedModName": "$sModName$"$endif$
>>
RefType(sName, sModName) ::= <<
"kind": "ReferenceType", "ReferencedTypeName": "$sName$"$if(sModName)$, "ReferencedModName": "$sModName$"$endif$
>>
......@@ -31,6 +31,7 @@ from itertools import chain
# pylint: disable=W0611
import enum # NOQA
import subprocess # NOQA
import distutils # NOQA
import tempfile # NOQA
import uuid # NOQA
import importlib # NOQA
......
......@@ -26,6 +26,5 @@
<file>fonts/Ubuntu-R.ttf</file>
<file>fonts/Ubuntu-RI.ttf</file>
<file>misc/lander.mp3</file>
<file>misc/python.stg</file>
</qresource>
</RCC>
# $ANTLR 3.1.3 Mar 17, 2009 19:23:44 sdl92.g 2014-06-20 11:33:36
# $ANTLR 3.1.3 Mar 17, 2009 19:23:44 sdl92.g 2014-06-20 15:21:41
import sys
from antlr3 import *
......
# $ANTLR 3.1.3 Mar 17, 2009 19:23:44 sdl92.g 2014-06-20 11:33:35
# $ANTLR 3.1.3 Mar 17, 2009 19:23:44 sdl92.g 2014-06-20 15:21:40
import sys
from antlr3 import *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment