コード例 #1
0
def AssignJson(uconfig):

    config = ndcDict(uconfig)

    if config['JSONPATH'] and os.path.isfile(config['JSONPATH']):
        with open(config['JSONPATH'], 'r') as assjr:
            config['ASSEMBLY'] = json.load(assjr)
        log.FILE('Confirmed: {}'.format(config['JSONPATH']))

    elif config['JSONPATH']:
        with open(defaultjson, 'r') as jassr:
            assembly = json.load(jassr)
        log.FILE('Confirmed: {}'.format(defaultjson))

        with open(config['JSONPATH'], 'w') as jassw:
            json.dump(assembly, jassw, indent=4)
        log.FILE('{}'.format(config['JSONPATH']))

        log.info('\n*Use auto-named json on next build:\n "{}"' \
                 .format(config['JSONPATH']))

        log.info(('\nUsing defualt assembly:\n\t {}\n\tSaved as:\n\t {}') \
                 .format(defaultjson, config['JSONPATH']))

        with open(config['JSONPATH'], 'r') as jassr:
            config['ASSEMBLY'] = ndcDict(json.load(jassr))
        log.FILE('Confirmed: {}'.format(config['JSONPATH']))

        log.warn(('\nNo user filepath param - using :\n\t {}') \
                 .format(defaultjson))

    else:
        raise FatalError('SynTaxError', 'Try using fully qualified filepaths')

    return ndcDict(config)
コード例 #2
0
ファイル: testbuildconfig.py プロジェクト: PESwim/ipybuilder
    def qLog(self):

        setLogLookBackTimeSec(3)
        curDateTime = time.strftime('%x %X', time.localtime())
        lfiles = list(getWriteLog())
        cnffiles = None
        wfiles = None
        cmplst = None

        if lfiles:
            cnffiles = getFilesConfirmed(list(lfiles))
            wfiles = getFilesWritten(list(lfiles))

        if cnffiles and wfiles:
            cmplst = CompareFilesConfirmedToRequired(cnffiles, self.tfiles)
            if cmplst:
                raise FatalError('ValueError',
                                 '\n {}' * len(cmplst).format(*cmplst))
            print('-' * 59)
            print(('log read time{}\n' + \
                  'proc start time {}').format(curDateTime, self.startTime))

            print(('\n confirmed:' +
                   '\n {}' * len(cnffiles)).format(*cnffiles))
            print('-' * 59)
            print(('\n writtten:' + '\n {}' * len(wfiles)).format(*wfiles))
コード例 #3
0
ファイル: required.py プロジェクト: PESwim/ipybuilder
def FindIronPython():
    '''
      Walk directories to find IronPython Install

      :return: IronPython install path [str] - or - if not main sets gsBuild.IPATH

      :raise: NotImplementedError

    '''
    clr = None
    try:
        import clr
    except Exception as ex:
        pass   
    SEARCHUSER = opn(os.path.expanduser('~'))

    SEARCHCWD = opd(os.getcwd())
    if 'Tests' in os.getcwd():
        SEARCHCWD = opd(SEARCHCWD)
    SEARCHMODSRC = opn(opd(opd(os.__file__)))
    SEARCHROOT = os.path.splitdrive(SEARCHCWD)[0]
    searchList = [SEARCHCWD, SEARCHUSER, SEARCHMODSRC, SEARCHROOT]

    for direct in searchList:
            for root, dirs, files in os.walk(direct, topdown=False):
                for name in files:
                        if gsBuild.IRONPYTHON in name:
                            with open(opn(opab(opj(os.getcwd(), 
                                                   'defaults\\ipath.txt'))),
                                                   'w') as tw:
                                tw.write(opd(opn(opj(root, name))))
                                
                            return opd(opn(opj(root, name)))
                        
    if __name__ == '__main__':
        raise NotImplementedError('Failed to Find/*Access' + \
                     ' loadable IronPython Distribution')
    if clr:
        #print str(clr.References)
        with open(opn(opab(opj(os.getcwd(), 
                               'defaults\\ipath.txt'))), 'w') as tw:
            tw.write('clr')
        print 'Err in clr req'
        return 'clr'
        
    if not clr:# or (clr and clr.References and not any('Iron' in clref for clref in str(clr.References).split(','))):
        log.warn(('\nFailed to find loadable IronPython Distribution:\n Used "{}"' + \
                  ' name to search for directory.\n\n' +
                  '   Searched ordered from base:\n {}\n {}\n {}\n {}\n') \
                .format(gsBuild.IRONPYTHON, *searchList))
    
        log.info('\nCheck Access and/or install IronPython to loadable path.')
    
        raise FatalError('NotImplementedError', 'Failed to Find/*Access' + \
                         ' loadable IronPython Distribution')
    return 
コード例 #4
0
def CheckConfig(uconfig):
    '''
       Check for valid config entries after parse/loading

       :param: config Dict from LoadConfig [OrderedDict]

       :return:
	       userconfig [config Dict] - as written to file path shown in writefiles.log

       :raise: FatalError or partialError [Exception] or [error sink list]

       *user can re-run ipybuild on a partialError fix*
       *why FatalError - a user messed with defaults - error vs program error*

    '''
    userfig = ndcDict(uconfig)

    if not len([val for val in userfig if val or val != '']) >= 1:
        raise ValueError('need at least one parameter for config')

    if not userfig['MAKEDIR'] or not opex(opd(userfig['MAKEDIR'])):
        raise NameError('bad path to config file {}' \
                        .format(opd(userfig['MAKEDIR'])))

    if not all(k in userfig.keys() for k in defaultconfig.keys()):
        log.error('\n keys {}\n\t{}'.format(str(userfig.keys()), \
                                            str(defaultconfig.keys())))
        raise FatalError('KeyError', 'bad userconfig key set')

    if not userfig['MAINFILE'] or userfig['MAINFILE'] == '':
        raise FatalError('NameError', 'need main name.py')

    if not '.py' in userfig['MAINFILE'] or not opex(userfig['MAINFILE']):
        try:
            raise NameError
        except NameError as ex:
            msg = ' main name "{}" must be .py file and exist' \
            .format(userfig['MAINFILE'])

            partialError(ex, msg)

    if not isinstance(userfig['MAKEEXE'], bool) and \
        str(userfig['MAKEEXE']).upper() not in ['TRUE', 'FALSE']:

        try:
            raise ValueError
        except ValueError as ex:
            msg = 'makeEXE {}: need type bool in params (no key needed)' \
                    .format(userfig['MAKEEXE'])
            partialError(ex, msg)

    if not opex(userfig['JSONPATH']):
        try:
            raise NameError
        except NameError as ex:
            msg = 'bad path to assembly.json file "{}"' \
                        .format(userfig['JSONPATH'])
            partialError(ex, msg)

    if not opex(userfig['CONFIGPATH']):
        try:
            raise NameError
        except NameError as ex:
            msg = 'bad path to assembly.json file "{}"' \
                        .format(userfig['CONFIGPATH'])
            partialError(ex, msg)
コード例 #5
0
ファイル: makeparse.py プロジェクト: PESwim/ipybuilder
def _parseTup(tup, argtyps, lists, f_list=False):
    '''
       Handle tuple arg parsing into argtyps <type>
	   
	'''
    tags = ['exe', 'dll', 'zip']
    trylst = None
    f_brokenlst = False
    for arg in tup:
        if arg and '[' in arg and ']' not in arg and not f_brokenlst:
            trylst = arg
            log.info('\nlist paramater {} was not quoted.'.format(arg))
            f_brokenlst = True
            continue

        elif trylst and ']' in arg and '[' in trylst and f_brokenlst:
            arg = trylst + arg
            log.info('\npatched paramater now: {}'.format(arg))
        elif trylst:
            log.error('need to quote lists, tuples, dicts in input parameters')

        try:
            arg = ast.literal_eval(arg)
        except Exception:
            pass

        tagmatch = None
        key = None
        dkey = None
        keys = None
        dkeys = None
        if arg:

            #Only get here on "True" - Must handle bool first or error
            if isinstance(arg, bool):
                argtyps['d']['makeEXE'] = arg
                lists.remove('makeEXE')
                continue
            keys = [k for k in lists if k in arg]
            ms = [m for m in tags if m in arg]
            if keys and len(keys) > 1 or (ms and len(ms) > 1):
                ambigWarn(arg)

            if keys:
                key = keys[0]

            tagmatches = [m for m in tags if m in arg]
            if tagmatches:
                tagmatch = tagmatches[0]
                dkeys = [dk for dk in lists if tagmatch in dk]
            if dkeys:
                dkey = dkeys[0]

            if isinstance(arg, (str, unicode)) and '=' not in arg:
                #put in first match
                if key:
                    argtyps['d'][key] = arg
                    continue

                elif not key and not tagmatch and not f_list:
                    argtyps['s'].append(arg)
                    continue

                elif not key and not tagmatch and f_list:
                    argtyps = _parseDics('listexe', arg, argtyps)
                    continue

                elif tagmatch:
                    argtyps = _parseDics(dkey, arg, argtyps)
                    continue
                else:
                    ambigWarn(arg)
                    raise FatalError('ValueError',
                                     'Error: Ambiguous param: ' + \
                                     str(arg))

            elif isinstance(arg, (str, unicode)) and '=' in arg:
                if (key and key in arg.split('=')[0]) or dkey:
                    if not key and dkey:
                        key = dkey
                    argtyps = _parseDics(key, arg.split('=')[1], argtyps)
                else:
                    ambigWarn(arg)
                    raise FatalError('ValueError',
                                     'Error: Ambiguous param: ' + \
                                     str(arg))
            elif isinstance(arg, dict):
                for k, v in arg.iteritems():
                    argtyps = _parseDics(k, v, argtyps)

            elif arg and isinstance(arg, list) or \
                   isinstance(arg, tuple):
                argtyps, lists = _parseTup(arg, argtyps, lists, True)

    argtyps = ndcDict(_parseOrder(argtyps))

    return argtyps, lists