import os from sys import argv from multiprocessing import Process, Queue import apt OUTPUT = '' LOLCAT = Queue() def check_lolcat(queue): if apt.Cache()['lolcat'].is_installed: queue.put(True) print('lolcat detected!') else: queue.put(False) def echo(text): global OUTPUT OUTPUT += text + '\n' def output_flush(): global OUTPUT os.system(f"echo \"{OUTPUT[:-1]}\"{'| /usr/games/lolcat' if LOLCAT.get() else ''}") if os.getuid() != 0: print('root rights required\nrun \'sudo python install.py\'') exit(1) path = 'src/ompl_src/' check_lolcat_process = Process(target=check_lolcat, args=(LOLCAT,)) check_lolcat_process.start() if 'r' in argv: os.system(f'rm {path}obj/ -rf') os.system(f'rm {path}lib/ -rf') echo('building .c files to .o files') if not os.path.exists(f'{path}obj/'): os.system(f'mkdir {path}obj/') if not os.path.exists(f'{path}lib/'): os.system(f'mkdir {path}lib/') name_ext = None for f in os.listdir(f'{path}c'): name_ext = os.path.splitext(f) if name_ext[1] == '.c': echo(f) os.system(f'gcc -fPIC -c {path}c/{name_ext[0]}.c -o {path}obj/{name_ext[0]}.o') echo('=' * 13) echo('building .o files to .so libs') for f in os.listdir(f'{path}obj'): name_ext = os.path.splitext(f)[0] echo(f) os.system(f'gcc -shared {path}obj/{name_ext}.o -o {path}lib/{name_ext}.so') echo('=' * 13) echo('installing') echo('copying src/main.py') os.system(f'cp src/main.py /usr/bin/ompl') os.system('chmod +x /usr/bin/ompl') echo('copying src/ompl_src/') os.system(f'cp src/ompl_src /usr/bin/ -r') echo('=' * 13) if 'c' in argv: echo('cleaning') echo('deleting lib/ and obj/ folders') os.system('rm src/ompl_src/lib/ -r | rm src/ompl_src/obj/ -r') echo('=' * 13) echo('done') check_lolcat_process.join() output_flush()