Ejemplo n.º 1
0
def reduceSolutionOptions(options, indent):
    #print indent+"OPTIONS:", options
    optionsOp = libListType(options)
    if optionsOp != 'STRING':
        i = 0
        while i < len(options[1]):
            opt = options[1][i]
            if not isinstance(opt, str):
                reduceSolutionOptions(options[1][i], indent + '|   ')
                if len(opt[1]) == 0:
                    del options[1][i]
                    cdlog(1, "DELETED:", i)
                    continue
                changesMade = True
                while changesMade:
                    changesMade = False
                    opt = options[1][i]
                    optOp = libListType(opt)
                    optionsOp = libListType(options)
                    if (optOp == 'AND' or optOp == 'OR') and (
                            optOp == optionsOp or len(opt[1])
                            == 1):  # Both AND or both OR so unwrap child list
                        options[1][i:i + 1] = opt[1]
                        changesMade = True
                    #elif optionsOp=='AND' and optOp=='OR':print("CROSS")
                # removeDuplicates(options)  # TODO: Make this line remove duplicates
            i += 1
Ejemplo n.º 2
0
def checkIfLibFileMightSatisyNeedWithRequirements(tags, need, libFile, indent):
    [ReqTags,interfaceTags] = extractLibTags(libFile)
    Requirements = []
    LibCanWork=True
    if need[0] == 'require':
        LibCanWork=False
        if 'provides' in interfaceTags:
            if need[1] in interfaceTags['provides']:
                #print(indent, '{}REQUIRE: {} in {}'.format(indent, need[1], interfaceTags['provides']))
                LibCanWork = True

    for ReqTag in ReqTags:
        #print("REQUIREMENT: {}".format(ReqTag))
        if ReqTag[0]=='feature':
            print("\n    Nested Features should be implemented. Please implement them. (", ReqTag[1], ")n")
            exit(2)
        elif ReqTag[0]=='require':
            Requirements.append(ReqTag)
        elif ReqTag[0]=='tagOneOf':
            tagToCheck = ReqTag[1]
            validValues = progSpec.extractListFromTagList(ReqTag[2])
            parentTag = progSpec.fetchTagValue(tags, tagToCheck)  # E.g.: "platform"
            if parentTag==None:
                LibCanWork=False
                cdErr("ERROR: The tag '"+ tagToCheck + "' was not found in" + libFile + ".\n")
            if not parentTag in validValues: LibCanWork=False
            else: cdlog(1, "  Validated: "+tagToCheck+" = "+parentTag)

    return [LibCanWork, Requirements]
Ejemplo n.º 3
0
def codeIsEQ(item, objsRefed, returnType, xlator):
    #print '      IsEq item:', item
    [S, retTypeSpec] = codeComparison(item[0], objsRefed, returnType, xlator)
    if len(item) > 1 and len(item[1]) > 0:
        if len(item[1]) > 1:
            print "Error: Chained == or !=.\n"
            exit(1)
        if (isinstance(retTypeSpec, int)):
            cdlog(logLvl(), "Invalid item in ==: {}".format(item[0]))
        leftOwner = owner = progSpec.getTypeSpecOwner(retTypeSpec)
        for i in item[1]:
            #print '      IsEq ', i
            if (i[0] == '=='): op = ' == '
            elif (i[0] == '!='): op = ' != '
            elif (i[0] == '==='): op = ' == '
            else:
                print "ERROR: '==' or '!=' or '===' expected."
                exit(2)
            [S2, retType2] = codeComparison(i[1], objsRefed, returnType,
                                            xlator)
            rightOwner = progSpec.getTypeSpecOwner(retType2)
            if not isinstance(retTypeSpec, basestring) and isinstance(
                    retTypeSpec['fieldType'], basestring) and isinstance(
                        retType2, basestring):
                if retTypeSpec[
                        'fieldType'] == "char" and retType2 == "string" and S2[
                            0] == '"':
                    S2 = "'" + S2[1:-1] + "'"
            if i[0] == '===':
                S = S + " == " + S2
            else:
                S += op + S2
            retTypeSpec = 'bool'
    return [S, retTypeSpec]
Ejemplo n.º 4
0
 def processField(self, fieldName, field, fldCat):
     S = ""
     itemName = '_' + fieldName + '_item'
     if fldCat == 'func': return ''
     typeSpec = field['typeSpec']
     if progSpec.isAContainer(typeSpec):
         if (progSpec.getDatastructID(typeSpec) == "list"):
             innerFieldType = progSpec.getFieldType(typeSpec)
             #print "ARRAYSPEC:",innerFieldType, field
             fldCatInner = progSpec.innerTypeCategory(innerFieldType)
             itemName = '_' + fieldName + '_item'
             calcdName = fieldName + '["+toString(' + itemName + '_key)+"]'
             S += "    withEach " + itemName + " in " + fieldName + "{\n"
             S += "        " + self.displayTextFieldAction(
                 calcdName, itemName, field, fldCatInner) + "    }\n"
         else:
             cdlog(2, "Map not supported")
     else:
         S += self.displayTextFieldAction(fieldName, fieldName, field,
                                          fldCat)
     if progSpec.typeIsPointer(typeSpec):
         T = "    if(" + fieldName + ' == NULL){SRet_ <- SRet_ + ' + 'indent + dispFieldAsText("' + fieldName + '", 15)+"NULL\\n"}\n'
         T += "    else{\n    " + S + "    }\n"
         S = T
     self.textFuncBody += S
Ejemplo n.º 5
0
def apply(classes, tags, className, dispMode):
    if dispMode[:4] == 'TAG_':
        dispModeTagName = dispMode[4:]
        dispMode = progSpec.fetchTagValue(tags, dispModeTagName)
    if (dispMode != 'none' and dispMode != 'text' and dispMode != 'draw'
            and dispMode != 'Proteus' and dispMode != 'toGUI'):
        cdErr(
            'Invalid parameter for display mode in Code Data Display pattern: '
            + str(dispMode))
    if dispMode == 'none': return

    global classesToProcess
    classesToProcess = [className]
    global classesEncoded
    #classesEncoded={}

    if (dispMode == 'Proteus'): processor = structAsProteusWriter()
    elif (dispMode == 'text'): processor = structToStringWriter()
    elif (dispMode == 'draw'): processor = structDrawingWriter()
    processor.addGlobalCode(classes)

    for classToEncode in classesToProcess:
        if classToEncode in classesEncoded: continue
        cdlog(1, "  ENCODING " + dispMode + ": " + classToEncode)
        classesEncoded[classToEncode] = 1
        pattern_GenSymbols.apply(
            classes, {}, [classToEncode])  # Invoke the GenSymbols pattern
        processor.processStruct(classes, classToEncode)
    return
Ejemplo n.º 6
0
def Write_Extracter(classes, ToStructName, FromStructName, logLvl):
    global extracterFunctionAccumulator
    global alreadyWrittenFunctions
    nameForFunc = getFunctionName(FromStructName, ToStructName)
    cdlog(
        logLvl,
        "WRITING function {}() to extract struct {} from parse tree: stage 1..."
        .format(nameForFunc, ToStructName))
    if nameForFunc in alreadyWrittenFunctions: return
    alreadyWrittenFunctions[nameForFunc] = True
    S = ''
    ObjectDef = progSpec.findSpecOf(classes[0], FromStructName, 'string')
    fields = ObjectDef["fields"]
    configType = ObjectDef['configType']
    SeqOrAlt = ''
    if configType == 'SEQ': SeqOrAlt = 'parseSEQ'
    elif configType == 'ALT': SeqOrAlt = 'parseALT'
    cdlog(
        logLvl,
        "WRITING function {}() to extract struct {} from parse tree: stage 2..."
        .format(nameForFunc, ToStructName))
    if configType == 'SEQ':
        S += Write_structExtracter(classes, ToStructName, FromStructName,
                                   fields, nameForFunc, logLvl)
    elif configType == 'ALT':
        S += Write_ALT_Extracter(classes, ToStructName, fields, 'SRec', '',
                                 'tmpStr', '    ', -1, logLvl)

    seqExtracter = "\n    void: " + nameForFunc + "(our stateRec: SRec0, their " + ToStructName + ": memStruct, their EParser: EP) <- {\n" + S + "    }\n"
    extracterFunctionAccumulator += seqExtracter
Ejemplo n.º 7
0
def downloadExtractZip(downloadUrl, packageName, packageDirectory):
    zipExtension = ""
    if downloadUrl.endswith(".zip"):
        zipExtension = ".zip"
    elif downloadUrl.endswith(".tar.gz"):
        zipExtension = ".tar.gz"
    elif downloadUrl.endswith(".tar.bz2"):
        zipExtension = ".tar.bz2"
    elif downloadUrl.endswith(".tar.xz"):
        zipExtension = ".tar.xz"
    elif downloadUrl.endswith(".tar"):
        zipExtension = ".tar"
    else:
        pass

    zipFileDirectory = packageDirectory + '/' + packageName
    innerPackageName = packageName  # TODO: get actual innerPackageName
    innerPackageDir = zipFileDirectory + '/' + innerPackageName
    packagePath = zipFileDirectory + '/' + packageName + zipExtension
    checkDirectory = os.path.isdir(zipFileDirectory)
    zipFileName = os.path.basename(downloadUrl)
    if not checkDirectory:
        makeDirs(zipFileDirectory + "/INSTALL")
        emgr.downloadFile(packagePath, downloadUrl)
        try:
            cdlog(1, "Extracting zip file: " + zipFileName)
            shutil.unpack_archive(packagePath, zipFileDirectory)
        except:
            cdErr("Could not extract zip archive file: " + zipFileName)
Ejemplo n.º 8
0
def parseInput(inputStr):
    cdlog(2, "Parsing build-specs...")
    progSpec.saveTextToErrFile(inputStr)
    try:
        localResults = progSpecParser.parseString(inputStr, parseAll=True)
    except ParseBaseException as pe:
        cdErr("While parsing: {}".format(pe))
    return localResults
Ejemplo n.º 9
0
def writeFile(path, fileName, fileSpecs, fileExtension):
    #print path
    makeDir(path)
    fileName += fileExtension
    pathName = path + os.sep + fileName
    cdlog(1, "WRITING FILE: "+pathName)
    fo=open(pathName, 'w')
    fo.write(fileSpecs[0][1])
    fo.close()
Ejemplo n.º 10
0
def packageInstalled(packageManagar, packageName):
    cdlog(1, "Package Installing: " + packageName)
    if subprocess.call(f'{packageManagar} {packageName}' +
                       " -y > /dev/null 2>&1",
                       shell=True) == 0:
        cdlog(1, "Package installed Successfully")
        return True
    else:
        cdErr("Unable to install package. \nPlease install manually : " +
              packageName)
Ejemplo n.º 11
0
def AddToObjectFromText(ProgSpec, clsNames, inputStr, description):
    macroDefs = {} # This var is not used here. If needed, make it an argument.
    inputStr = comment_remover(inputStr)
    #print '####################\n',inputStr, "\n######################^\n\n\n"
    errLevl=logLvl(); cdlog(errLevl, 'Parsing: '+description)
    progSpec.saveTextToErrFile(inputStr)
    # (map of classes, array of objectNames, string to parse)
    try:
        results = objectList.parseString(inputStr, parseAll = True)
    except ParseException , pe:
        cdErr( "Error parsing generated class {}: {}".format(description, pe))
Ejemplo n.º 12
0
def codeMain(classes, tags, objsRefed, xlator):
    cdlog(3, "\n            Generating GLOBAL...")
    if("GLOBAL" in classes[1]):
        if(classes[0]["GLOBAL"]['stateType'] != 'struct'):
            print("ERROR: GLOBAL must be a 'struct'.")
            exit(2)
        [structCode, funcCode, globalFuncs]=codeStructFields(classes, "GLOBAL", tags, '', objsRefed, xlator)
        if(funcCode==''): funcCode="// No main() function.\n"
        if(structCode==''): structCode="// No Main Globals.\n"
        funcCode = "\n\n"+funcCode+"\nmain();"
        return ["\n\n// Globals\n" + structCode + globalFuncs, funcCode]
    return ["// No Main Globals.\n", "// No main() function defined.\n"]
Ejemplo n.º 13
0
def BuildAndPrintResults(workingDirectory, buildStr, runStr):
    cdlog(1, "Compiling From: {}".format(workingDirectory))
    print("\n     NOTE: Build Command is: ", buildStr)
    print("     NOTE: Working Dir is: ", workingDirectory)
    print("     NOTE: Run Command is: ", runStr, "\n")

    result = runCmdStreaming(buildStr, workingDirectory)
    if result == 0:
        print("\nSUCCESS\n")
    else:
        print("\nBuild failed\n")
        exit(-1)
Ejemplo n.º 14
0
def writeNonTermParseRule(classes, tags, modelName, fields, SeqOrAlt, nameSuffix, logLvl):
    global nextParseNameID
    nameIn=modelName+nameSuffix

    # Allocate or fetch a rule identifier for each '>' field.

    partIndexes=[]
    for field in fields:
        fname=field['fieldName']
        if fname==None: fname=''
        else: fname='_'+fname
        typeSpec   =field['typeSpec']
        if(field['isNext']==True): # means in the parse there was a '>' symbol, a sequence seperator
            firstItm=progSpec.getFieldType(field['typeSpec'])[0]
            if firstItm=='[' or firstItm=='{': # Handle an ALT or SEQ sub structure
                cdlog(logLvl, "NonTERM: {} = {}".format(fname, firstItm))
                nextParseNameID+=1
                if firstItm=='[':
                    innerSeqOrAlt='parseALT'
                    newNameSuffix = nameSuffix+fname+'_ALT'+str(nextParseNameID)
                else:
                    innerSeqOrAlt='parseSEQ'
                    newNameSuffix = nameSuffix+fname+'_SEQ'+str(nextParseNameID)
                innerFields=field['innerDefs']
                ruleIdxStr = writeNonTermParseRule(classes, tags, modelName, innerFields, innerSeqOrAlt, newNameSuffix, logLvl+1)
                field['parseRule']=ruleIdxStr


                if progSpec.isAContainer(typeSpec):
                    # anything with [] is a container: lists and optionals
                    global rules
                    containerSpec = progSpec.getContainerSpec(typeSpec)
                    idxType=''
                    if 'indexType' in containerSpec:
                        idxType=containerSpec['indexType']
                    if(isinstance(containerSpec['datastructID'], str)):
                        datastructID = containerSpec['datastructID']
                    else:   # it's a parseResult
                        datastructID = containerSpec['datastructID'][0]
                    if idxType[0:4]=='uint': pass
                    if(datastructID=='list'):
                        ruleIdxStr=appendRule(ruleIdxStr+'_REP', "nonterm", "parseREP", [ruleIdxStr, 0, 0])
                    elif datastructID=='opt':
                        ruleIdxStr=appendRule(ruleIdxStr+'_OPT', "nonterm", "parseREP", [ruleIdxStr, 0, 1])
            else:
                ruleIdxStr = fetchOrWriteTerminalParseRule(modelName, field, logLvl)

            partIndexes.append(ruleIdxStr)
        else: pass; # These fields probably have corresponding cofactuals

    nameOut=appendRule(nameIn, "nonterm", SeqOrAlt, partIndexes)
    return nameOut
Ejemplo n.º 15
0
def printResults(workingDirectory, buildStr, runStr):
    cdlog(1, "Compiling From: {}".format(workingDirectory))
    print "     NOTE: Build Command is: ", buildStr, "\n"
    print "     NOTE: Run Command is: ", runStr, "\n"
    #print "workingDirectory: ", workingDirectory
    pipe = subprocess.Popen(buildStr, cwd=workingDirectory, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    out, err = pipe.communicate()
    if out: print "Result: ",out
    if err:
        print "Error Messages:\n--------------------------\n", err,
        print "--------------------------",
        exit(2)
    else: cdlog(1, "SUCCESS!")
Ejemplo n.º 16
0
def apply(classes, tags, topClassName):
    print('APPLY: in Apply\n')
    global classesToProcess
    global classesEncoded
    classesEncoded = {}

    # Choose an appropriate app style
    appStyle = 'default'
    topWhichScreenFieldID = topClassName + '::whichScreen(int)'
    if (progSpec.doesClassDirectlyImlementThisField(
            classes[0], topClassName,
            topWhichScreenFieldID)):  # if all data fields are classes
        appStyle = 'Z_stack'
    else:
        appStyle = 'TabbedStack'
    guiStructName = topClassName + '_GUI'
    classesEncoded[guiStructName] = 1
    classesToProcess = [[topClassName, 'struct', appStyle, guiStructName]]

    # Amend items to each GUI data class
    for classToAmend in classesToProcess:
        [className, widgetType, dialogStyle, newStructName] = classToAmend
        cdlog(
            1, 'BUILDING ' + dialogStyle + ' GUI for ' + widgetType + ' ' +
            className + ' (' + newStructName + ')')
        if widgetType == 'struct':
            BuildGuiForStruct(classes, className, dialogStyle, newStructName)
        #elif widgetType == 'list':
        #buildListRowView(classes, className, dialogStyle, newStructName)

    # Fill createAppArea()
    primaryGUIName = 'primary_GUI_Mgr'

    CODE = '''
struct APP{
    our ''' + topClassName + ''': primary
    our ''' + guiStructName + ''': <PRIMARY_GUI>
    me void: createAppArea(me GUI_Frame: frame) <- {
        Allocate(primary)
        Allocate(<PRIMARY_GUI>)
        their GUI_storyBoard: appStoryBoard <- <PRIMARY_GUI>.initWidget(primary)
        initializeAppGui()
        addToContainerAndExpand (frame, appStoryBoard)
    }
}'''

    CODE = CODE.replace('<PRIMARY_GUI>', primaryGUIName)
    #print ('==========================================================\n'+CODE)
    codeDogParser.AddToObjectFromText(classes[0], classes[1], CODE, 'APP')

    return
Ejemplo n.º 17
0
def parseCodeDogString(inputString, ProgSpec, clsNames, macroDefs, description):
    tmpMacroDefs={}
    inputString = comment_remover(inputString)
    extractMacroDefs(tmpMacroDefs, inputString)
    inputString = doMacroSubstitutions(tmpMacroDefs, inputString)
    LogLvl=logLvl()
    cdlog(LogLvl, "PARSING: "+description+"...")
    results = parseInput(inputString)
    cdlog(LogLvl, "EXTRACTING: "+description+"...")
    tagStore = extractTagDefs(results.tagDefList)
    buildSpecs = extractBuildSpecs(results.buildSpecList)
    newClasses = extractObjectsOrPatterns(ProgSpec, clsNames, macroDefs, results.objectList)
    classes = [ProgSpec, clsNames]
    return[tagStore, buildSpecs, classes, newClasses]
Ejemplo n.º 18
0
def apply(classes, tags, topClassName):
    print "APPLY: in Apply\n"
    global classesToProcess
    global classesEncoded
    classesEncoded={}

    # Choose an appropriate app style
    appStyle='default'
    topWhichScreenFieldID = topClassName+'::whichScreen(int)'
    if (progSpec.doesClassDirectlyImlementThisField(classes[0], topClassName, topWhichScreenFieldID)): # if all data fields are classes
        appStyle='Z_stack'
    else: appStyle='TabbedStack'
    guiStructName = topClassName+'_GUI'
    classesEncoded[guiStructName]=1
    classesToProcess=[[topClassName, 'struct', appStyle, guiStructName]]

    # Amend items to each GUI data class
    for classToAmend in classesToProcess:
        [className, widgetType, dialogStyle, newStructName] = classToAmend
        cdlog(1, "BUILDING "+dialogStyle+" GUI for "+widgetType+" " + className + ' ('+newStructName+')')
        if widgetType == 'struct':
            BuildGuiForStruct(classes, className, dialogStyle, newStructName)
        elif widgetType == 'list':
            BuildGuiForList(classes, className, dialogStyle, newStructName)

    # Fill createAppArea()
    primaryGUIName = 'primary_GUI_Mgr'
    primaryMakerFuncName = 'make'+topClassName[0].upper() + topClassName[1:]+'Widget'

    CODE ='''
struct APP{
    our <TOPCLASSNAME>: primary
    our <GUI_STRUCTNAME>: <PRIMARY_GUI>
    me void: createAppArea(me GUI_Frame: frame) <- {
        Allocate(primary)
        Allocate(<PRIMARY_GUI>)
        their GUI_storyBoard: appStoryBoard <- <PRIMARY_GUI>.<PRIMARY_MAKERFUNCNAME>(primary)
        initializeAppGui()
        gui.addToContainerAndExpand (frame, appStoryBoard)
    }
}'''

    CODE = CODE.replace('<PRIMARY_GUI>', primaryGUIName)
    CODE = CODE.replace('<TOPCLASSNAME>', topClassName)
    CODE = CODE.replace('<GUI_STRUCTNAME>', guiStructName)
    CODE = CODE.replace('<PRIMARY_MAKERFUNCNAME>', primaryMakerFuncName)
    #print '==========================================================\n'+CODE
    codeDogParser.AddToObjectFromText(classes[0], classes[1], CODE, 'APP')

    return
Ejemplo n.º 19
0
def ChooseLibs(classes, buildTags, tags):
    clearFeaturesHandled()
    cdlog(0, "\n##############   C H O O S I N G   L I B R A R I E S")
    featuresNeeded = progSpec.fetchTagValue([tags], 'featuresNeeded')
    initialNeeds = []
    for feature in featuresNeeded:
        featuresNeeded.extend(fetchFeaturesNeededByLibrary(feature))
        initialNeeds.append(["feature", feature])
    solutionOptions = constructANDListFromNeeds([tags, buildTags],
                                                initialNeeds, [], "")
    reduceSolutionOptions(solutionOptions, '')
    for libPath in solutionOptions[1]:
        cdlog(2, "USING LIBRARY:" + libPath)
    return solutionOptions[1]
Ejemplo n.º 20
0
def gitClone(cloneUrl, packageName, packageDirectory):
    checkSys.CheckPipModules({'GitPython': '3.1'})
    import urllib.request
    from git import Repo
    packagePath = packageDirectory + '/' + packageName + '/' + packageName
    checkRepo = os.path.isdir(packagePath)
    if not checkRepo:
        try:
            urllib.request.urlopen(cloneUrl)
        except (urllib.error.URLError, urllib.error.HTTPError):
            cdErr("URL not found: " + cloneUrl)

        cdlog(1, "Cloning git repository: " + packageName)
        Repo.clone_from(cloneUrl, packagePath)
        makeDirs(packageDirectory + '/' + packageName + "/INSTALL")
Ejemplo n.º 21
0
def build(debugMode, minLangVersion, fileName, labelName, launchIconName,
          libFiles, buildName, platform, fileSpecs, progOrLib, packageData,
          tools):
    cdlog(
        0,
        "\n##############   B U I L D I N G    S Y S T E M...   ({})".format(
            buildName))
    progOrLib = progOrLib.lower()
    if platform == 'Linux':
        [workingDirectory, buildStr,
         runStr] = LinuxBuilder(debugMode, minLangVersion, fileName, libFiles,
                                buildName, platform, fileSpecs, progOrLib,
                                packageData, tools)
    elif platform == 'Java' or platform == 'Swing':
        [workingDirectory, buildStr,
         runStr] = SwingBuilder(debugMode, minLangVersion, fileName, libFiles,
                                buildName, platform, fileSpecs)
    elif platform == 'Android':
        buildAndroid.AndroidBuilder(debugMode, minLangVersion, fileName,
                                    labelName, launchIconName, libFiles,
                                    buildName, platform, fileSpecs)
    elif platform == 'Swift':
        [workingDirectory, buildStr,
         runStr] = SwiftBuilder(debugMode, minLangVersion, fileName, libFiles,
                                buildName, platform, fileSpecs)
    elif platform == 'Windows':
        [workingDirectory, buildStr,
         runStr] = WindowsBuilder(debugMode, minLangVersion, fileName,
                                  libFiles, buildName, platform, fileSpecs,
                                  progOrLib, packageData, tools)
    elif platform == 'MacOS':
        [workingDirectory, buildStr,
         runStr] = buildMac.macBuilder(debugMode, minLangVersion, fileName,
                                       libFiles, buildName, platform,
                                       fileSpecs)
    elif platform == 'IOS':
        [workingDirectory, buildStr,
         runStr] = iOSBuilder(debugMode, minLangVersion, fileName, libFiles,
                              buildName, platform, fileSpecs)
    else:
        print("buildDog.py error: build string not generated for " + buildName)
        exit(2)
    if platform != 'Android':
        BuildAndPrintResults(workingDirectory, buildStr, runStr)
    print("--------------------------")
    return
Ejemplo n.º 22
0
def downloadFile(fileName, downloadURL):
    checkSys.CheckPipModules({'urllib3': '1.25'})
    import urllib3
    try:
        cdlog(1, "Downloading file: " + fileName)
        http = urllib3.PoolManager()
        r = http.request('GET', downloadURL, preload_content=False)
    except:
        cdErr("URL not found: " + downloadURL)
    else:
        with open(fileName, 'wb') as out:
            while True:
                data = r.read(1028)
                if not data:
                    break
                out.write(data)
        r.release_conn()
Ejemplo n.º 23
0
def constructANDListFromNeeds(tags, needs, files, indent):
    AND_List = ['AND', []]
    for need in needs:
        #print(indent, "**need*: ", need)
        if need[0] == 'feature':
            if need[1] in featuresHandled: continue
            cdlog(1, "FEATURE: "+str(need[1]))
            featuresHandled.append(need[1])
            filesToTry = [findLibrary(need[1])]
            if filesToTry[0]=='': cdErr('Could not find a dog file for feature '+need[1])
        else:
            filesToTry = files

        if len(filesToTry)>0:
            solutionOptions = constructORListFromFiles(tags, need, filesToTry, indent + "|   ")
            if len(solutionOptions[1])>0:
                AND_List[1].append(solutionOptions)
    return AND_List
Ejemplo n.º 24
0
def build(debugMode, minLangVersion, fileName, libFiles, buildName, platform, fileSpecs):
    cdlog(0,"\n##############   B U I L D I N G    S Y S T E M...   ({})".format(buildName))
    if platform == 'Linux':
        [workingDirectory, buildStr, runStr] = LinuxBuilder(debugMode, minLangVersion, fileName, libFiles, buildName, platform, fileSpecs)
        printResults(workingDirectory, buildStr, runStr)
    elif platform == 'Java':
        [workingDirectory, buildStr, runStr] = SwingBuilder(debugMode, minLangVersion, fileName, libFiles, buildName, platform, fileSpecs)
        printResults(workingDirectory, buildStr, runStr)
    elif platform == 'Android':
        buildAndroid.AndroidBuilder(debugMode, minLangVersion, fileName, libFiles, buildName, platform, fileSpecs)
    elif platform == 'IOS':
        [workingDirectory, buildStr, runStr] = SwiftBuilder(debugMode, minLangVersion, fileName, libFiles, buildName, platform, fileSpecs)
        printResults(workingDirectory, buildStr, runStr)
    elif platform == 'Windows':
        [workingDirectory, buildStr, runStr] = WindowsBuilder(debugMode, minLangVersion, fileName, libFiles, buildName, platform, fileSpecs)
    else:
        print "buildDog.py error: build string not generated for "+ buildName
        exit(2)
    print "--------------------------"
    return
Ejemplo n.º 25
0
def codeIsEQ(item, objsRefed, returnType, expectedTypeSpec, xlator):
    #print('      IsEq item:', item)
    [S, retTypeSpec]=codeComparison(item[0], objsRefed, returnType, expectedTypeSpec, xlator)
    if len(item) > 1 and len(item[1])>0:
        if len(item[1])>1: print("Error: Chained == or !=.\n"); exit(1);
        if (isinstance(retTypeSpec, int)): cdlog(logLvl(), "Invalid item in ==: {}".format(item[0]))
        leftOwner=owner=progSpec.getTypeSpecOwner(retTypeSpec)
        [S_derefd, isDerefd] = derefPtr(S, retTypeSpec)
        for i in item[1]:
            #print '      IsEq ', i
            if   (i[0] == '=='): op=' == '
            elif (i[0] == '!='): op=' != '
            elif (i[0] == '==='): op=' == '
            else: print("ERROR: '==' or '!=' or '===' expected."); exit(2)
            [S2, retTypeSpec] = codeComparison(i[1], objsRefed, returnType, expectedTypeSpec, xlator)
            rightOwner=progSpec.getTypeSpecOwner(retTypeSpec)
            if not( leftOwner=='itr' and rightOwner=='itr') and i[0] != '===':
                if (S2!='nil' ): S=S_derefd
                elif S[-1]=='!': S=S[:-1]   # Todo: Better detect this
                [S2, isDerefd]=derefPtr(S2, retTypeSpec)
            S+= op+S2
            retTypeSpec='bool'
    return [S, retTypeSpec]
Ejemplo n.º 26
0
def ChooseLibs(classes, buildTags, tags):
    """Entry point to libraryMngr

    tags: dict
    """

    featuresHandled.clear()
    cdlog(0, "\n##############   C H O O S I N G   L I B R A R I E S")
    featuresNeeded = progSpec.fetchTagValue([tags], 'featuresNeeded')
    initialNeeds1 = []
    for feature in featuresNeeded:
        featuresNeeded.extend(fetchFeaturesNeededByLibrary(feature))
        if not feature in initialNeeds1: initialNeeds1.append(feature)

    initialNeeds2 = []
    for feature in initialNeeds1:
        initialNeeds2.append(['feature', feature])
    solutionOptions = constructANDListFromNeeds([tags, buildTags],
                                                initialNeeds2, [], "")
    reduceSolutionOptions(solutionOptions, '')
    for libPath in solutionOptions[1]:
        cdlog(2, "USING LIBRARY:" + str(libPath))
    return solutionOptions[1]
Ejemplo n.º 27
0
def CreateStructsForStringModels(classes, newClasses, tags):
    # Define fieldResult struct
    #~ structsName = 'fetchResult'
    #~ StructFieldStr = "mode [fetchOK, fetchNotReady, fetchSyntaxError, FetchIO_Error] : FetchResult"
    #~ progSpec.addObject(classes[0], classes[1], structsName, 'struct', 'SEQ')
    #~ codeDogParser.AddToObjectFromText(classes[0], classes[1], progSpec.wrapFieldListInObjectDef(structsName, StructFieldStr))

    if len(newClasses)==0: return
    populateBaseRules()

    global extracterFunctionAccumulator
    extracterFunctionAccumulator=""
    global nextParseNameID
    nextParseNameID=0
    numStringStructs=0
    for className in newClasses:
        if className[0] == '!': continue
        ObjectDef = classes[0][className]
        if(ObjectDef['stateType'] == 'string'):
            className=className[1:]
            cdlog(1, "  Writing parse system for "+className)
            numStringStructs+=1
            fields    = ObjectDef["fields"]
            configType= ObjectDef['configType']
            classTags = ObjectDef['tags']
            if 'StartSymbol' in classTags:
                writeParserWrapperFunction(classes, className)
            SeqOrAlt=''
            if configType=='SEQ': SeqOrAlt='parseSEQ'   # seq has {}
            elif configType=='ALT': SeqOrAlt='parseALT' # alt has []

            normedObjectName = className.replace('::', '_')
            if normedObjectName==className: normedObjectName+='_str'
            # Write the rules for all the fields, and a parent rule which is either SEQ or ALT, and REP/OPT as needed.
            cdlog(2, "CODING Parser Rules for {}".format(normedObjectName))
            ruleID = writeNonTermParseRule(classes, tags, normedObjectName, fields, SeqOrAlt, '', 3)

            if SeqOrAlt=='parseSEQ':
                [memObj, memVersionName]=fetchMemVersion(classes, className)
                if memObj!=None:
                    Write_Extracter(classes, className, className, 2)
                else: cdlog(2, "NOTE: Skipping {} because it has no struct version defined.".format(className))

    if numStringStructs==0: return

    ExtracterCode = extracterFunctionAccumulator

    ############  Add struct parser
    parserCode=genParserCode()
    codeDogParser.AddToObjectFromText(classes[0], classes[1], parserCode, 'Parser for '+className)

    structsName='EParser'
    progSpec.addObject(classes[0], classes[1], structsName, 'struct', 'SEQ')
    codeDogParser.AddToObjectFromText(classes[0], classes[1], progSpec.wrapFieldListInObjectDef(structsName, ExtracterCode), 'class '+structsName)
Ejemplo n.º 28
0
def Write_ALT_Extracter(classes, parentStructName, fields, VarTagBase, VarTagSuffix, VarName, indent, level, logLvl):
    # Structname should be the name of the structure being parsed. It will be converted to the mem version to get 'to' fields.
    # Fields is the list of alternates.
    # VarTag is a string used to create local variables.
    # VarName is the LVAL variable name.
    global  globalFieldCount
    cdlog(logLvl, "WRITING code to extract one of {} from parse tree...".format(parentStructName))
    InnerMemObjFields = []
    progSpec.populateCallableStructFields(InnerMemObjFields, classes, parentStructName)
    if parentStructName.find('::') != -1: cdErr("TODO: Make string parsing work on derived classes. Probably just select the correct fields for the destination struct.")
    S=""
    # Code to fetch the ruleIDX of this ALT. If the parse was terminal (i.e., 'const'), it will be at a different place.
    if(level==-1):
        level=1
        VarTag='SRec1'
        VarTagSuffix='0'
    else:
        globalFieldCount+=1
        VarTag=VarTagBase+str(level)
        VarTagSuffix=str(level-1)+'.child.next'+VarTagSuffix

    indent2 = indent+'    '
    S+='\n'+indent+'{\n'
    S+='\n'+indent2+'our stateRec: '+VarTag+' <- '+VarTagBase+VarTagSuffix+'\n'
    loopVarName = "ruleIDX"+str(globalFieldCount)
    S+=indent2+'me int: '+loopVarName+' <- '+VarTag+'.child.productionID\n'

    #print "RULEIDX:", indent, parentStructName, VarName
    if VarName!='memStruct':
        S+=indent2 + 'me string: '+VarName+'\n'
    count=0
    S+= indent2+"switch("+loopVarName+"){\n"
    for altField in fields:
        if(altField['isNext']!=True): continue; # This field isn't in the parse stream.
        cdlog(logLvl+1, "ALT: {}".format(altField['parseRule']))
        if not 'parseRule' in altField: print("Error: Is syntax missing a '>'?"); exit(2);
        S+=indent2+"    case " + altField['parseRule'] + ":{\n"
        coFactualCode=''
        if 'coFactuals' in altField:
            #Extract field and cofactsList
            for coFact in altField['coFactuals']:
                coFactualCode+= indent2 +'        ' + VarName + '.' + coFact[0] + ' <- ' + coFact[2] + "\n"
                cdlog(logLvl+2, "Cofactual: "+coFactualCode)
        S+=Write_fieldExtracter(classes, parentStructName, altField, InnerMemObjFields, VarTagBase, VarName, False, indent2+'        ', level, logLvl+1)
        S+=coFactualCode
        S+=indent2+"    }\n"
        count+=1
    S+=indent2+"}"
    S+=indent+"}"
    return S
Ejemplo n.º 29
0
def checkAndUpgradeOSPackageVersions(packageName):
    cdlog(1, f"Searching for package: {packageName}")
    installedPackage = os.popen(
        f'apt-cache policy {packageName} | grep Installed')
    if installedPackage.read():
        installedPackage = os.popen(
            f'apt-cache policy {packageName} | grep Installed')
        candidatePackage = os.popen(
            f'apt-cache policy {packageName} | grep Candidate')
        installedVersion = installedPackage.read().split(" ")[-1].replace(
            '\n', '')
        candidateVersion = candidatePackage.read().split(" ")[-1].replace(
            '\n', '')
        cdlog(1, f"Candidate Package available: {candidateVersion}")
        if installedVersion or installedVersion == '(none)':
            if installedVersion != candidateVersion:
                getPackageManagerCMD(packageName, findPackageManager())
            else:
                cdlog(1, f"Package already Installed: {packageName}")
    else:
        print(
            f"Unable to find package. \nPlease install manually : {packageName}"
        )
Ejemplo n.º 30
0
def FindOrFetchLibraries(buildName, packageData, platform, tools):
    #print("#############:buildName:", buildName, platform)
    packageDirectory = os.path.join(os.getcwd(), buildName)
    [includeFolders, libFolders] = ["", ""]
    for package in packageData:
        packageMap = progSpec.extractMapFromTagMap(package)
        packageName = fetchType = fetchURL = fetchCommit = ""
        buildCmdsMap = {}
        if 'packageName' in packageMap:
            packageName = packageMap['packageName'][1:-1]
        if 'fetchMethod' in packageMap:
            fetchMethod = packageMap['fetchMethod'][1:-1]
            fetchSpec = packageMap['fetchMethod'][1:-1].split(':', 1)
            fetchType = fetchSpec[0]
            splitSpec = fetchSpec[1].split('@', 1)
            fetchURL = splitSpec[0]
            if len(splitSpec) >= 2: fetchCommit = splitSpec[1]
        if 'buildCmds' in packageMap:
            buildCmds = packageMap['buildCmds']
            buildCmdsMap = progSpec.extractMapFromTagMap(buildCmds)

        if packageName != "" and fetchMethod != "":
            if fetchType == "git":
                gitClone(fetchURL, packageName, packageDirectory)
            elif fetchType == "file":
                downloadPackageFile(fetchURL, packageName, packageDirectory)
            elif fetchType == "zip":
                downloadExtractZip(fetchURL, packageName, packageDirectory)
            else:
                pass

        if buildCmdsMap != {} and platform in buildCmdsMap:
            #print("###########:",platform, ' = ', buildCmdsMap[platform])
            buildCommand = buildCmdsMap[platform]
            buildCmdMap = progSpec.extractMapFromTagMap(buildCommand)
            downloadedFolder = packageDirectory + "/" + packageName + "/" + packageName

            if 'buildCmd' in buildCmdMap:
                actualBuildCmd = buildCmdMap['buildCmd'][1:-1]
                for folderKey, folderVal in importantFolders.items():
                    actualBuildCmd = actualBuildCmd.replace(
                        '$' + folderKey, folderVal)
                #print("BUILDCOMMAND:", actualBuildCmd)#, "  INSTALL:", buildCmdsMap[platform][1])

                for toolName in tools:
                    if emgr.checkToolLinux('go' if toolName ==
                                           'golang-go' else toolName):
                        runCmdStreaming(actualBuildCmd, downloadedFolder)
                    else:
                        packageManager = emgr.findPackageManager()
                        if not packageManager:
                            print(
                                f"Unable to find Package Manager.\nPlease install manually : {packageName}"
                            )
                        else:
                            emgr.getPackageManagerCMD(toolName, packageManager)
                        runCmdStreaming(actualBuildCmd, downloadedFolder)

            if 'installFiles' in buildCmdMap:
                installfileList = buildCmdMap['installFiles'][1]
                # ~ installFiles = progSpec.extractListFromTagList(installfileList)
                # ~ print("    DATA:", str(installFiles)[:100])
                LibsFolder = os.path.join(packageDirectory, packageName,
                                          'INSTALL').replace("\\", "/")
                makeDirs(LibsFolder)
                importantFolders[packageName + '@Install'] = LibsFolder
                importantFolders[
                    packageName] = packageDirectory + '/' + packageName + '/' + packageName
                includeFolders += "     '" + LibsFolder + "',\n"
                libFolders += "     '" + LibsFolder + "',\n"
                for filenameX in installfileList:
                    filename = downloadedFolder + '/' + filenameX[0][0][1:-1]
                    cdlog(1, "Install: " + filename)
                    copyRecursive(filename, LibsFolder)

    return [includeFolders, libFolders]