Commit d1c60bac authored by Thanassis Tsiodras's avatar Thanassis Tsiodras
Browse files

Merged distutils work for Python3 setup

Step1: asn2dataModel and related coverage tests.
parent f17fc369
......@@ -26,7 +26,7 @@ import os
import sys
import distutils.spawn as spawn
from commonPy.utility import panic
from ..commonPy.utility import panic
def Version():
......
......@@ -26,7 +26,7 @@ import os
import sys
import distutils.spawn as spawn
from commonPy.utility import panic
from ..commonPy.utility import panic
def Version():
......
......@@ -35,16 +35,17 @@ import copy
from typing import Tuple, List
import commonPy.configMT
from commonPy.asnAST import sourceSequenceLimit, AsnNode # NOQA pylint: disable=unused-import
from commonPy.asnParser import ( # NOQA pylint: disable=unused-import
from ..commonPy import configMT
from ..commonPy.asnAST import sourceSequenceLimit, AsnNode # NOQA pylint: disable=unused-import
from ..commonPy import asnParser
from ..commonPy.asnParser import ( # NOQA pylint: disable=unused-import
AST_Lookup, AST_Leaftypes,
Typename, Filename, ParseAsnFileList)
from commonPy.utility import inform, panic
import commonPy.cleanupNodes
from commonPy.recursiveMapper import RecursiveMapper
from ..commonPy.utility import inform, panic
from ..commonPy import cleanupNodes
from ..commonPy.recursiveMapper import RecursiveMapper
import commonPy.verify
from ..commonPy import verify
def usage():
......@@ -149,22 +150,19 @@ class Printer(RecursiveMapper):
def main():
sys.path.append(os.path.abspath(os.path.dirname(sys.argv[0])))
sys.path.append('commonPy')
if sys.argv.count("-o") != 0:
idx = sys.argv.index("-o")
try:
commonPy.configMT.outputDir = os.path.normpath(sys.argv[idx + 1]) + os.sep
configMT.outputDir = os.path.normpath(sys.argv[idx + 1]) + os.sep
except: # pragma: no cover
usage() # pragma: no cover
del sys.argv[idx]
del sys.argv[idx]
if not os.path.isdir(commonPy.configMT.outputDir):
panic("'%s' is not a directory!\n" % commonPy.configMT.outputDir) # pragma: no cover
if not os.path.isdir(configMT.outputDir):
panic("'%s' is not a directory!\n" % configMT.outputDir) # pragma: no cover
if "-verbose" in sys.argv:
commonPy.configMT.verbose = True
configMT.verbose = True
sys.argv.remove("-verbose")
if len(sys.argv) < 2:
......@@ -181,30 +179,30 @@ def main():
for asnFile in uniqueASNfiles:
tmpNames = {} # Dict[Typename, AsnNode]
for name in commonPy.asnParser.g_typesOfFile[asnFile]:
tmpNames[name] = commonPy.asnParser.g_names[name]
for name in asnParser.g_typesOfFile[asnFile]:
tmpNames[name] = asnParser.g_names[name]
uniqueASNfiles[asnFile] = (
copy.copy(tmpNames), # map Typename to type definition class from asnAST
copy.copy(commonPy.asnParser.g_astOfFile[asnFile]), # list of nameless type definitions
copy.copy(commonPy.asnParser.g_leafTypeDict) # map from Typename to leafType
copy.copy(asnParser.g_astOfFile[asnFile]), # list of nameless type definitions
copy.copy(asnParser.g_leafTypeDict) # map from Typename to leafType
)
inform("Checking that all base nodes have mandatory ranges set in %s..." % asnFile)
for node in list(tmpNames.values()):
commonPy.verify.VerifyRanges(node, commonPy.asnParser.g_names)
verify.VerifyRanges(node, asnParser.g_names)
# If some AST nodes must be skipped (for any reason), go learn about them
badTypes = commonPy.cleanupNodes.DiscoverBadTypes()
badTypes = cleanupNodes.DiscoverBadTypes()
C_HeaderFile = open(commonPy.configMT.outputDir + os.sep + "PrintTypes.h", "w")
C_HeaderFile = open(configMT.outputDir + os.sep + "PrintTypes.h", "w")
C_HeaderFile.write('#ifndef __PRINTTYPES_H__\n')
C_HeaderFile.write('#define __PRINTTYPES_H__\n\n')
C_HeaderFile.write('#ifdef __cplusplus\n')
C_HeaderFile.write('extern "C" {\n')
C_HeaderFile.write('#endif\n\n')
C_SourceFile = open(commonPy.configMT.outputDir + os.sep + "PrintTypes.c", "w")
C_SourceFile = open(configMT.outputDir + os.sep + "PrintTypes.c", "w")
C_SourceFile.write('#include <stdio.h>\n\n')
C_SourceFile.write('#include "PrintTypes.h"\n\n')
C_SourceFile.write('#ifdef __linux__\n')
......@@ -247,7 +245,7 @@ def main():
'',
node,
leafTypeDict,
commonPy.asnParser.g_names)]
asnParser.g_names)]
C_SourceFile.write("\n".join(lines))
C_SourceFile.write('\n#ifdef __linux__\n')
C_SourceFile.write(' pthread_mutex_unlock(&g_printing_mutex);\n')
......
......@@ -33,16 +33,17 @@ import copy
from typing import Tuple, List
import commonPy.configMT
from commonPy.asnAST import sourceSequenceLimit, AsnNode # NOQA pylint: disable=unused-import
from commonPy.asnParser import ( # NOQA pylint: disable=unused-import
from ..commonPy import configMT
from ..commonPy.asnAST import sourceSequenceLimit, AsnNode # NOQA pylint: disable=unused-import
from ..commonPy import asnParser
from ..commonPy.asnParser import ( # NOQA pylint: disable=unused-import
AST_Lookup, AST_Leaftypes,
Typename, Filename, ParseAsnFileList)
from commonPy.utility import inform, panic
import commonPy.cleanupNodes
from commonPy.recursiveMapper import RecursiveMapper
from ..commonPy.utility import inform, panic
from ..commonPy import cleanupNodes
from ..commonPy.recursiveMapper import RecursiveMapper
import commonPy.verify
from ..commonPy import verify
def usage():
......@@ -174,16 +175,16 @@ def main():
if sys.argv.count("-o") != 0:
idx = sys.argv.index("-o")
try:
commonPy.configMT.outputDir = os.path.normpath(sys.argv[idx + 1]) + os.sep
configMT.outputDir = os.path.normpath(sys.argv[idx + 1]) + os.sep
except: # pragma: no cover
usage() # pragma: no cover
del sys.argv[idx]
del sys.argv[idx]
if not os.path.isdir(commonPy.configMT.outputDir):
panic("'%s' is not a directory!\n" % commonPy.configMT.outputDir) # pragma: no cover
if not os.path.isdir(configMT.outputDir):
panic("'%s' is not a directory!\n" % configMT.outputDir) # pragma: no cover
if "-verbose" in sys.argv:
commonPy.configMT.verbose = True
configMT.verbose = True
sys.argv.remove("-verbose")
if len(sys.argv) < 2:
......@@ -200,30 +201,30 @@ def main():
for asnFile in uniqueASNfiles:
tmpNames = {} # Dict[Typename, AsnNode]
for name in commonPy.asnParser.g_typesOfFile[asnFile]:
tmpNames[name] = commonPy.asnParser.g_names[name]
for name in asnParser.g_typesOfFile[asnFile]:
tmpNames[name] = asnParser.g_names[name]
uniqueASNfiles[asnFile] = (
copy.copy(tmpNames), # map Typename to type definition class from asnAST
copy.copy(commonPy.asnParser.g_astOfFile[asnFile]), # list of nameless type definitions
copy.copy(commonPy.asnParser.g_leafTypeDict) # map from Typename to leafType
copy.copy(asnParser.g_astOfFile[asnFile]), # list of nameless type definitions
copy.copy(asnParser.g_leafTypeDict) # map from Typename to leafType
)
inform("Checking that all base nodes have mandatory ranges set in %s..." % asnFile)
for node in list(tmpNames.values()):
commonPy.verify.VerifyRanges(node, commonPy.asnParser.g_names)
verify.VerifyRanges(node, asnParser.g_names)
# If some AST nodes must be skipped (for any reason), go learn about them
badTypes = commonPy.cleanupNodes.DiscoverBadTypes()
badTypes = cleanupNodes.DiscoverBadTypes()
C_HeaderFile = open(commonPy.configMT.outputDir + os.sep + "PrintTypesAsASN1.h", "w")
C_HeaderFile = open(configMT.outputDir + os.sep + "PrintTypesAsASN1.h", "w")
C_HeaderFile.write('#ifndef __PRINTTYPESASASN1_H__\n')
C_HeaderFile.write('#define __PRINTTYPESASASN1_H__\n\n')
C_HeaderFile.write('#ifdef __cplusplus\n')
C_HeaderFile.write('extern "C" {\n')
C_HeaderFile.write('#endif\n\n')
C_SourceFile = open(commonPy.configMT.outputDir + os.sep + "PrintTypesAsASN1.c", "w")
C_SourceFile = open(configMT.outputDir + os.sep + "PrintTypesAsASN1.c", "w")
C_SourceFile.write('#include <stdio.h>\n\n')
C_SourceFile.write('#include "PrintTypesAsASN1.h"\n\n')
C_SourceFile.write('#ifdef __linux__\n')
......@@ -262,8 +263,8 @@ def main():
C_SourceFile.write('#endif\n')
C_SourceFile.write(' //printf("%%s %s ::= ", paramName);\n' % nodeTypename)
C_SourceFile.write(' printf("%s ", paramName);\n')
# C_SourceFile.write('\n'.join(printer.Map('(*pData)', '', node, leafTypeDict, commonPy.asnParser.g_names)))
lines = [" " + x for x in printer.Map('(*pData)', '', node, leafTypeDict, commonPy.asnParser.g_names)]
# C_SourceFile.write('\n'.join(printer.Map('(*pData)', '', node, leafTypeDict, asnParser.g_names)))
lines = [" " + x for x in printer.Map('(*pData)', '', node, leafTypeDict, asnParser.g_names)]
C_SourceFile.write("\n".join(lines))
C_SourceFile.write('\n#ifdef __linux__\n')
C_SourceFile.write(' pthread_mutex_unlock(&g_printing_mutex);\n')
......
......@@ -23,6 +23,8 @@
# import re
from ..commonPy import asnParser
g_outputDir = ""
g_asnFile = ""
......@@ -88,7 +90,6 @@ def OnShutdown(unused_badTypes):
# text = re.sub(r'--.*', '', text)
outputFile = open(g_outputDir + "DataView.pr", 'w')
outputFile.write('Datamodel DEFINITIONS ::= BEGIN\n\n')
import commonPy.asnParser
commonPy.asnParser.PrintGrammarFromAST(outputFile)
asnParser.PrintGrammarFromAST(outputFile)
outputFile.write('END\n')
outputFile.close()
......@@ -20,15 +20,14 @@
#
import re
import os
import commonPy
import commonPy.asnParser
from commonPy.utility import panic, inform
from commonPy.asnAST import (
from ..commonPy import asnParser
from ..commonPy.utility import panic, inform
from ..commonPy.asnAST import (
AsnBool, AsnInt, AsnReal, AsnString, isSequenceVariable, AsnEnumerated,
AsnSequence, AsnSet, AsnChoice, AsnMetaMember, AsnSequenceOf, AsnSetOf,
AsnBasicNode)
from commonPy.asnParser import AST_Lookup, AST_Leaftypes
from commonPy.cleanupNodes import SetOfBadTypenames
from ..commonPy.asnParser import AST_Lookup, AST_Leaftypes
from ..commonPy.cleanupNodes import SetOfBadTypenames
# The Python file written to
g_outputFile = None
......@@ -174,7 +173,7 @@ clean:
%(tab)srm -f $(BDIR)/$(GRAMMAR)_asn.py
''' % {'tab': '\t', 'base': base, 'origGrammarBase': origGrammarBase, 'mono': mono_exe})
makefile.close()
CreateDeclarationsForAllTypes(commonPy.asnParser.g_names, commonPy.asnParser.g_leafTypeDict, badTypes)
CreateDeclarationsForAllTypes(asnParser.g_names, asnParser.g_leafTypeDict, badTypes)
g_outputGetSetH.write('\n/* Helper functions for NATIVE encodings */\n\n')
g_outputGetSetC.write('\n/* Helper functions for NATIVE encodings */\n\n')
......@@ -203,7 +202,7 @@ clean:
g_outputGetSetC.write("void DestroyInstanceOf_%s(byte *pData) {\n" % typ)
g_outputGetSetC.write(' free(pData);\n')
g_outputGetSetC.write('}\n\n')
for nodeTypename, node in commonPy.asnParser.g_names.items():
for nodeTypename, node in asnParser.g_names.items():
if node._isArtificial:
continue
WorkOnType(nodeTypename)
......
......@@ -30,9 +30,9 @@ import sys
import re
import distutils.spawn as spawn
import commonPy
from commonPy.utility import panic, inform
from commonPy.asnAST import AsnBool, AsnInt, AsnReal, AsnString, AsnEnumerated, AsnSequence, AsnSet, AsnChoice, AsnMetaMember, AsnSequenceOf, AsnSetOf
from ..commonPy import asnParser
from ..commonPy.utility import panic, inform
from ..commonPy.asnAST import AsnBool, AsnInt, AsnReal, AsnString, AsnEnumerated, AsnSequence, AsnSet, AsnChoice, AsnMetaMember, AsnSequenceOf, AsnSetOf
from .createInternalTypes import ScanChildren
# The file written to
......@@ -86,7 +86,7 @@ def OnStartup(unused_modelingLanguage, asnFiles, outputDir, unused_badTypes):
g_definedTypes = {}
global g_octetStrings
g_octetStrings = 0
CreateDeclarationsForAllTypes(commonPy.asnParser.g_names, commonPy.asnParser.g_leafTypeDict)
CreateDeclarationsForAllTypes(asnParser.g_names, asnParser.g_leafTypeDict)
def OnBasic(unused_nodeTypename, unused_node, unused_leafTypeDict):
......
......@@ -23,9 +23,11 @@
#
import re
import commonPy
from commonPy.utility import panic, inform
from commonPy.asnAST import AsnBool, AsnInt, AsnReal, AsnString, AsnEnumerated, AsnSequence, AsnSet, AsnChoice, AsnMetaMember, AsnSequenceOf, AsnSetOf
from ..commonPy.utility import panic, inform
from ..commonPy import asnParser
from ..commonPy.asnAST import (
AsnBool, AsnInt, AsnReal, AsnString, AsnEnumerated, AsnSequence,
AsnSet, AsnChoice, AsnMetaMember, AsnSequenceOf, AsnSetOf)
from .createInternalTypes import ScanChildren
# The file written to
......@@ -65,7 +67,7 @@ def OnStartup(unused_modelingLanguage, unused_asnFile, outputDir, unused_badType
g_definedTypes = {}
global g_octetStrings
g_octetStrings = 0
CreateDeclarationsForAllTypes(commonPy.asnParser.g_names, commonPy.asnParser.g_leafTypeDict)
CreateDeclarationsForAllTypes(asnParser.g_names, asnParser.g_leafTypeDict)
def OnBasic(unused_nodeTypename, unused_node, unused_leafTypeDict):
......
......@@ -30,12 +30,12 @@ import random
from xml.dom.minidom import Document, Node # type: ignore # NOQA pylint: disable=unused-import
from typing import Set # NOQA pylint: disable=unused-import
from commonPy.utility import inform, panic
from commonPy.asnAST import (
from ..commonPy.utility import inform, panic
from ..commonPy.asnAST import (
AsnBasicNode, AsnString, AsnEnumerated, AsnMetaMember, AsnSet,
AsnSetOf, AsnSequence, AsnSequenceOf, AsnChoice
)
import commonPy.asnParser
from ..commonPy import asnParser
g_lookup = {
"INTEGER": "int",
......@@ -79,8 +79,8 @@ def RandomHex(digits: int) -> str:
def FixupNestedStringsAndEnumerated():
names = commonPy.asnParser.g_names
leafTypeDict = commonPy.asnParser.g_leafTypeDict
names = asnParser.g_names
leafTypeDict = asnParser.g_leafTypeDict
for nodeTypename in list(names.keys()):
node = names[nodeTypename]
if isinstance(node, (AsnSequence, AsnChoice, AsnSet)):
......@@ -180,8 +180,8 @@ def GetOID(nodeTypename):
def CheckPrerequisites(nodeTypename):
names = commonPy.asnParser.g_names
leafTypeDict = commonPy.asnParser.g_leafTypeDict
names = asnParser.g_names
leafTypeDict = asnParser.g_leafTypeDict
if nodeTypename not in g_declaredTypes:
node = names[nodeTypename]
leafType = leafTypeDict[nodeTypename]
......@@ -211,10 +211,10 @@ def CheckPrerequisites(nodeTypename):
def HandleTypedef(nodeTypename: str) -> bool:
if nodeTypename not in commonPy.asnParser.g_metatypes:
if nodeTypename not in asnParser.g_metatypes:
return False
controlString = 'Type$name=%s,definition,NamedType,type,TypeRef$name=%s' % \
(CleanNameAsScadeWants(nodeTypename), CleanNameAsScadeWants(commonPy.asnParser.g_metatypes[nodeTypename]))
(CleanNameAsScadeWants(nodeTypename), CleanNameAsScadeWants(asnParser.g_metatypes[nodeTypename]))
RenderElements(controlString)
return True
......
......@@ -19,9 +19,12 @@
# generated code.
#
import re
import commonPy
from commonPy.utility import panic, inform
from commonPy.asnAST import AsnBool, AsnInt, AsnReal, AsnString, AsnEnumerated, AsnSequence, AsnSet, AsnChoice, AsnMetaMember, AsnSequenceOf, AsnSetOf
from ..commonPy.utility import panic, inform
from ..commonPy import asnParser
from ..commonPy.asnAST import (
AsnBool, AsnInt, AsnReal, AsnString, AsnEnumerated, AsnSequence,
AsnSet, AsnChoice, AsnMetaMember, AsnSequenceOf, AsnSetOf)
from .createInternalTypes import ScanChildren
# The file written to
......@@ -61,7 +64,7 @@ def OnStartup(unused_modelingLanguage, unused_asnFile, outputDir, unused_badType
g_definedTypes = {}
global g_octetStrings
g_octetStrings = 0
CreateDeclarationsForAllTypes(commonPy.asnParser.g_names, commonPy.asnParser.g_leafTypeDict)
CreateDeclarationsForAllTypes(asnParser.g_names, asnParser.g_leafTypeDict)
def OnBasic(unused_nodeTypename, unused_node, unused_leafTypeDict):
......
......@@ -25,10 +25,10 @@ import os
import re
import random
from commonPy.asnAST import AsnMetaMember, AsnChoice, AsnSet, AsnSequence, AsnSequenceOf, AsnSetOf
from commonPy.asnParser import g_names, g_leafTypeDict, CleanNameForAST
from commonPy.utility import panic, warn
from commonPy.cleanupNodes import SetOfBadTypenames
from ..commonPy.asnAST import AsnMetaMember, AsnChoice, AsnSet, AsnSequence, AsnSequenceOf, AsnSetOf
from ..commonPy.asnParser import g_names, g_leafTypeDict, CleanNameForAST
from ..commonPy.utility import panic, warn
from ..commonPy.cleanupNodes import SetOfBadTypenames
g_catalogueXML = None
g_innerTypes = {}
......
......@@ -24,11 +24,11 @@ code generator A.'''
import os
import re
from commonPy.asnAST import (
from ..commonPy.asnAST import (
AsnMetaMember, AsnChoice, AsnSet, AsnSequence, AsnSequenceOf, AsnSetOf)
from commonPy.asnParser import g_names, g_leafTypeDict, CleanNameForAST
from commonPy.utility import panic, warn
from commonPy.cleanupNodes import SetOfBadTypenames
from ..commonPy.asnParser import g_names, g_leafTypeDict, CleanNameForAST
from ..commonPy.utility import panic, warn
from ..commonPy.cleanupNodes import SetOfBadTypenames
g_sqlOutput = None
g_innerTypes = {}
......
......@@ -24,12 +24,12 @@ Semantix's code generator A.'''
import os
import re
from commonPy.asnAST import (
from ..commonPy.asnAST import (
AsnMetaMember, AsnChoice, AsnSet, AsnSequence, AsnSequenceOf,
AsnSetOf, isSequenceVariable)
from commonPy.asnParser import g_names, g_leafTypeDict, CleanNameForAST
from commonPy.utility import panic, warn
from commonPy.cleanupNodes import SetOfBadTypenames
from ..commonPy.asnParser import g_names, g_leafTypeDict, CleanNameForAST
from ..commonPy.utility import panic, warn
from ..commonPy.cleanupNodes import SetOfBadTypenames
g_sqlalchemyOutput = None
g_innerTypes = {} # type: Dict[str, int]
......
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