Exemplo n.º 1
0
def pprint(s=None, action=None, head=None):
    if head != None and head in HEADS:
        print(PREFIX + ' ' + HEADS[head])
    elif not s:
        print(PREFIX)
    elif action != None and action in ACTIONS:
        print(PREFIX + ' ' + ACTIONS[action] +
              color(s, fg='black', style='bold') + '...')
    else:
        print(PREFIX + ' ' + s)
Exemplo n.º 2
0
def main(args):
    # UTF-8 is off on Windows by default
    if not usingUTF8():  # This fixes it if it's off, though
        print('Changed the codepage to UTF-8. Please rerun this script.')
        return 0
    for line in STARTUP:
        pprint(line)
    argc = len(args)  # Save CPU
    if argc < 3:
        raise Exception('Insufficient arguments provided')
    if not os.path.isfile(args[1]):
        raise Exception('Provided INI file is inaccessible')
    # The solution config file
    mainIni = ini.parse(args[1])
    if int(mainIni['']['version']) > 0:
        # v0 is the latest, as far as we know
        raise Exception('Future INI schema version found; not supported')
    # Either debug/release (w/ optional architecture), or we're linting
    if re.fullmatch(r'((debug|release)(32|64)?)|lint', args[2]) == None:
        raise Exception('Provided build type is invalid')
    pprint(head='prep')
    # Get the project list, ordered for dependency satisfaction
    projectNames = mainIni['']['order'].lower().split(',')
    i = 0
    projectCt = len(projectNames)  # Save CPU
    taskName = 'build'
    projects = {}
    # Get settings for all the projects
    while i < projectCt:
        project = projectInit(mainIni['projects'][projectNames[i]])
        data = {
            projectNames[i]: {
                'projIni': project[0],
                'assetIni': project[1],
                'srcDir': project[2],
                'incDir': project[3],
                'langs': project[4]
            }
        }
        projects = {**projects, **data}
        i += 1
    i = 0
    pprint(head='start')
    try:
        if args[2] == 'lint':
            taskName = 'lint'  # Used if things go wrong
            while i < projectCt:
                project = projects[projectNames[i]]
                pprint(project['projIni']['']['name'], action='lint')
                # 0 = project INI, 2 = source directory
                lint(project['projIni'], project['srcDir'])
                i += 1
        else:  # compiling instead
            # Get project source directories for internal dependency inclusion
            localIncPaths = []
            while i < projectCt:
                project = projects[projectNames[i]]
                localIncPaths += [
                    os.path.join(project['srcDir'],
                                 project['projIni']['']['name'],
                                 project['projIni']['source']['sourcedir'])
                ]
                i += 1
            i = 0
            while i < projectCt:
                # Set up all project variables:-
                project = projects[projectNames[i]]
                # Applicable code languages in project
                pLangs = project['langs']
                # 'executable', 'shared', or 'static'
                pFormat = project['projIni']['output']['type']
                # list of libraries to link
                pLibs = LIBS[:]  # Duplicate array
                if 'depends' in project['projIni']['']:
                    # Include all dependencies in library list
                    _libs = []
                    if ',' in project['projIni']['']['depends']:
                        _libs += project['projIni']['']['depends'].split(',')
                    else:
                        _libs += [project['projIni']['']['depends']]
                    if os.name == 'nt':
                        j = 0
                        _libsCt = len(_libs)
                        while j < _libsCt:
                            _libs[j] = _libs[j].replace('sfml-', 'sfml')
                            j += 1
                    pLibs += _libs
                # Full path for output binary, including name
                _name = project['projIni']['output']['name']
                if os.name != 'nt' and pFormat != 'executable':
                    _name = 'lib' + _name
                pOutPath = os.path.join(project['projIni']['output']['path'],
                                        _name)
                # Language-agnostic location for object code
                pObjPath = os.path.join(project['projIni']['output']['path'],
                                        'code', projectNames[i])
                if not os.path.exists(pObjPath):
                    if os.name == 'nt':
                        # Ya gotta keep 'em separated
                        if 'c' in pLangs or 'c++' in pLangs:
                            os.makedirs(os.path.join(pObjPath, 'c'))
                        if 'd' in pLangs:
                            os.makedirs(os.path.join(pObjPath, 'd'))
                    else:
                        os.makedirs(pObjPath)
                # Direct path to source code
                pSrcPath = os.path.join(
                    mainIni['projects'][projectNames[i]].replace('/', os.sep),
                    project['srcDir'].replace('/', os.sep))
                # Paths for C(++) #includes and D imports
                pIncPaths = [
                    os.path.join(
                        mainIni['']['includedir'].replace('/', os.sep),
                        project['incDir'].replace('/', os.sep)),
                    mainIni['']['includedir'].replace('/', os.sep)
                ] + INCDIRS + localIncPaths
                pObjGlob = os.path.join(pObjPath, '**', '*' + OBJEXT)
                libDepsPath = ''
                if os.name == 'nt':
                    # Manually include external dependencies, since Windows
                    # leaves us on our own with that
                    libDepsPath = '.\\deps\\lib'
                    if IS64BIT:
                        libDepsPath += '64'
                    else:
                        libDepsPath += '32'
                    if DEBUG:
                        libDepsPath += '\\debug'
                    else:
                        libDepsPath += '\\release'
                    if os.path.isdir(libDepsPath):
                        allDeps = os.listdir(libDepsPath)
                        for dep in allDeps:
                            if dep.lower().endswith('.dll'):
                                shutil.copy2(
                                    libDepsPath + '\\' + dep,
                                    project['projIni']['output']['path'])
                for lang in pLangs:
                    # Compile all C code
                    if lang == 'c':
                        flags = CFLAGS[:]  # dup() array
                        if os.name == 'nt':
                            # Path must end with a backslash for CL.EXE
                            # Separate C(++) code from D code because of .obj
                            flags += [COUTFLAG + pObjPath + '\\c\\']
                        else:
                            flags += [COUTFLAG, pObjPath]
                        for incDir in pIncPaths:
                            if os.name == 'nt':
                                flags += [CINCFLAG + incDir]
                            else:
                                flags += [CINCFLAG, incDir]
                        if os.name == 'nt':
                            # MT = multithreaded app
                            # MD = multithreaded library
                            # d suffix = debugging
                            if DEBUG:
                                if pFormat == 'executable':
                                    flags += ['/MTd']
                                elif pFormat == 'shared':
                                    flags += ['/MDd']
                            else:
                                if pFormat == 'executable':
                                    flags += ['/MT']
                                elif pFormat == 'shared':
                                    flags += ['/MD']
                        sources = getSources(pSrcPath, ['c'])
                        for source in sources:
                            source = source.replace('.' + os.sep, '')
                            com = [CC] + flags
                            if os.name != 'nt':
                                com += [
                                    COUTFLAG,
                                    os.path.join(
                                        pObjPath,
                                        os.path.basename(source) + OBJEXT)
                                ]
                            com += [source]
                            pprint(source, action='c')
                            try:
                                run(' '.join(com),
                                    shell=True,
                                    check=True,
                                    stdout=PIPE)
                            except CalledProcessError as ex:
                                lines = ex.stdout.decode().splitlines()
                                for line in lines:
                                    print('ERROR: ' + line)
                                raise Exception(
                                    'Compilation unit failed ' +
                                    'with command ' + color('', fg='white') +
                                    color(' '.join(com), fg='white'))
                    # Compile all project C++ code
                    elif lang == 'c++':
                        flags = CPPFLAGS[:]  # Duplicate array
                        if os.name == 'nt':
                            # Path must end with a backslash for CL.EXE
                            # Separate C(++) code from D code because of .obj
                            flags += [COUTFLAG + pObjPath + '\\c\\']
                        for incDir in pIncPaths:
                            if os.name == 'nt':
                                flags += [CINCFLAG + incDir]
                            else:
                                flags += [CINCFLAG, incDir]
                        if os.name == 'nt':
                            # See notes above for flag meanings
                            if DEBUG:
                                if pFormat == 'executable':
                                    flags += ['/MTd']
                                elif pFormat == 'shared':
                                    flags += ['/MDd']
                            else:
                                if pFormat == 'executable':
                                    flags += ['/MT']
                                elif pFormat == 'shared':
                                    flags += ['/MD']
                        sources = getSources(pSrcPath, ['c++'])
                        for source in sources:
                            source = source.replace('.' + os.sep, '')
                            com = [CXX] + flags
                            if os.name != 'nt':
                                com += [
                                    COUTFLAG,
                                    os.path.join(
                                        pObjPath,
                                        os.path.basename(source) + OBJEXT)
                                ]
                            com += [source]
                            pprint(source, action='c++')
                            try:
                                run(' '.join(com),
                                    shell=True,
                                    check=True,
                                    stdout=PIPE)
                            except CalledProcessError as ex:
                                lines = ex.stdout.decode().splitlines()
                                for line in lines:
                                    print('ERROR: ' + line)
                                raise Exception(
                                    'Compilation unit failed ' +
                                    'with command ' + color('', fg='white') +
                                    color(' '.join(com), fg='white'))
                    # Compile all project D code
                    elif lang == 'd':
                        # Separate D code from C(++) because of .obj
                        flags = DFLAGS
                        if os.name == 'nt':
                            flags += [DOUTFLAG + pObjPath + '\\d\\']
                        else:
                            flags += [DOUTFLAG + pObjPath]
                        if pFormat == 'shared':
                            flags += ['-shared']
                        for incDir in pIncPaths:
                            flags += [DINCFLAG + incDir]
                        sources = getSources(pSrcPath, ['d'])
                        for source in sources:
                            source = source.replace('.' + os.sep, '')
                            # Ignore these, only DMD cares about them
                            # They overwrite each other anyway
                            if source.endswith('package.d'):
                                continue
                            com = [DC, source] + flags
                            pprint(source, action='d')
                            try:
                                run(' '.join(com),
                                    shell=True,
                                    check=True,
                                    stdout=PIPE)
                            except CalledProcessError as ex:
                                lines = ex.stdout.decode().splitlines()
                                for line in lines:
                                    print('ERROR: ' + line)
                                raise Exception(
                                    'Compilation unit failed ' +
                                    'with command ' + color('', fg='white') +
                                    color(' '.join(com), fg='white'))
                # Link the project
                com = [LINK] + glob.glob(pObjGlob, recursive=True)
                # Append a file extension if needed
                if os.name == 'nt':
                    if pFormat == 'executable':
                        pOutPath += '.exe'
                    elif pFormat == 'shared':
                        pOutPath += '.dll'
                        # Windows needs this
                        com += ['/DLL']
                    elif pFormat == 'static':
                        pOutPath += '.lib'
                    # Give the output path to the linker
                    com += [LINKOUTFLAG + pOutPath]
                else:
                    if pFormat == 'shared':
                        pOutPath += '.so'
                        com += ['-shared']
                    elif pFormat == 'static':
                        pOutPath += '.a'
                    com += [LINKOUTFLAG, pOutPath]
                # Add common linker flags
                com += LINKFLAGS
                if libDepsPath != '':
                    # This is for external dependency linkage
                    com += [LINKDIRFLAG + libDepsPath]
                # Add build directory to lib search paths
                com += [LINKDIRFLAG + project['projIni']['output']['path']]
                for libPath in LIBDIRS:
                    # Add common lib search paths
                    com += [LINKDIRFLAG + libPath]
                # Add external dependency libs
                for lib in pLibs:
                    if os.name == 'nt':
                        # On Windows, boost is compiled funny. Check that
                        if lib.startswith('boost'):
                            com += [LINKLIBFLAG + lib + BOOST_SUF + '.lib']
                        else:
                            com += [LINKLIBFLAG + lib + '.lib']
                    else:
                        com += [LINKLIBFLAG + lib]
                pprint(project['projIni']['output']['name'], action='link')
                # Link!
                try:
                    run(' '.join(com), shell=True, check=True, stdout=PIPE)
                except CalledProcessError as ex:
                    lines = ex.stdout.decode().splitlines()
                    for line in lines:
                        print('ERROR: ' + line)
                    raise Exception('Compilation unit failed ' +
                                    'with command ' + color('', fg='white') +
                                    color(' '.join(com), fg='white'))
                i += 1
    except Exception as ex:
        pprint('Exception in ' + taskName + ': ' +
               color('{0}'.format(ex), style='bold'))
        pprint(head='fail')
        return -1
    pprint(head='pass')
    pprint()
    return 0
Exemplo n.º 3
0
        return os.path.isfile(fpath) and os.access(fpath, os.X_OK)

    fpath, fname = os.path.split(program)
    if fpath:
        if is_exe(program):
            return program
    else:
        for path in os.environ["PATH"].split(os.pathsep):
            path = path.strip('"')
            exe_file = os.path.join(path, program)
            if is_exe(exe_file):
                return exe_file
    return None


PREFIX = color('[\u00D4\u00C7\u00F4]', fg='white', style='bold')
ACTIONS = {
    'asm': color(fg='green', s='Assembling') + '      ',
    'c': color(fg='cyan', s='Compiling') + '       ',
    'c++': color(fg='blue', s='Compiling') + '       ',
    'd': color(fg='magenta', s='Compiling') + '       ',
    'gfx': color(fg='yellow', s='Transmogrifying') + ' ',
    'conv': color(fg='yellow', style='bold', s='Converting') + '      ',
    'link': color(fg='red', s='Linking') + '         ',
    'lint': color(fg='black', style='bold', s='Linting') + '         '
}
HEADS = {
    'prep': color('Preparing the build tool',
                  fg='blue',
                  style='bold+underline'),
    'start': color('Compilation started', fg='blue', style='bold+underline'),
Exemplo n.º 4
0
def sdarken(s):
    c = color(s)
    c2 = color(rgb=[max(float(q) * 0.95 - 0.025, 0) for q in c.get_rgb()])
    return c2.get_hex()
Exemplo n.º 5
0
def gohex(s):
    return color(s).get_hex()
Exemplo n.º 6
0
import requests
import statusArg
import sys
import colour as cms
import string
import delete

c=0	#contatore righe per scruittura intetsazione

if len(sys.argv)!= 3:
	print cms.color('<red>ERROR: Bad parameters</red>')	#controllo argc
	print 'Visita il manuale scrivendo --help come opzione!'
	sys.exit()

f = open(sys.argv[1], "r+")	#apertura file .zona

if sys.argv[1]==None:
	print cms.color('<red>File has not been opened</red>')	#controllo file
	print 'Visita il manuale scrivendo --help come opzione!'
	sys.exit()

while c<20:
	st=f.readline()		#scrittura intestazione del file .zona
	c = c+1

if sys.argv[2]=='--help':	#pannello di aiuto
	print '-----------------------------------------------------------------------'
	print 'PROGRAM MANUAL\nProgramming language used: Python v3.x'
	print 'Selezionare UNA delle seguenti opzioni:'
	print 'USABLE OPTIONS:'
	print '-s : Shows the detailed status of the site content with code;'