def create_symlink(src, dst): """ Creates a symlink at dst to src. """ if not os.path.exists(src): console.logerror("'%s' is not a valid path" % src) sys.exit(1) try: os.symlink(src, dst) console.pretty_print('Creating symlink', console.white) console.pretty_print(' "%s" ' % dst, console.bold) console.pretty_print("->", console.white) console.pretty_println(' "%s." ' % src, console.bold) except Exception as ex_symlink: console.logerror("Could not symlink '%s' to %s [%s]." % (src, dst, str(ex_symlink))) raise RuntimeError()
def init_workspace(): args = parse_arguments() if not args.track: args.track = settings.get_default_track() if args.list_rosinstalls: list_rosinstalls(args.track) sys.exit(0) # if not which("/opt/ros/" + args.track + "/bin/catkin_init_workspace"): # sys.exit("\nCatkin is not installed: 'sudo apt-get install ros-%s-catkin'\n" % args.track) if os.path.isabs(args.dir): workspace_dir = args.dir else: workspace_dir = os.path.join(os.getcwd(), args.dir) if not os.path.isdir(workspace_dir): os.mkdir(workspace_dir) if os.path.isdir(os.path.join(workspace_dir, 'src')): sys.exit("This workspace is already initialised") if args.uri: uri = args.uri # assume its an absolute path or http uri if not os.path.isabs(args.uri): if os.path.isfile(os.path.join(os.getcwd(), args.uri)): uri = os.path.join(os.getcwd(), args.uri) else: if urlparse.urlparse(args.uri).scheme == "": # not a http element, let's look up our databas console.pretty_print("Retrieving", console.cyan) console.pretty_print(" %s " % args.uri, console.yellow) console.pretty_print("on track", console.cyan) console.pretty_print(" %s " % args.track, console.yellow) console.pretty_print("from", console.cyan) console.pretty_println(" %s " % settings.get_rosinstall_database_uri(), console.yellow) response = urllib2.urlopen('%s/%s.yaml' % (settings.get_rosinstall_database_uri(), args.track)) rosinstalls = yaml.load(response.read()) if args.uri in rosinstalls: uri = rosinstalls[args.uri] else: console.logerror("Uri not an absolute path, local file, http or in our rosinstall database.") sys.exit(1) else: uri = "" populate_worskpace(os.path.join(workspace_dir, 'src'), uri) print_details(workspace_dir, uri)
def clean(dir_to_be_cleaned, dir_sources): if common.is_same_dir(dir_to_be_cleaned, os.getcwd()): if not os.path.isfile(os.path.join(dir_to_be_cleaned, 'config.cmake')): console.logerror( "Could not clean the current directory [build artifacts do not exist]" ) return console.pretty_print( "\nCleaning current directory of yujin_init_build artifacts : ", console.cyan) for f in [ os.path.join(dir_to_be_cleaned, x) for x in [ 'config.cmake', 'eclipse', 'gnome-terminal', 'konsole', 'toolchain.cmake', '.bashrc', 'android-studio' ] ]: if os.path.isfile(f): os.remove(f) for f in [ os.path.join(dir_to_be_cleaned, dir_sources, x) for x in ['CMakeLists.txt', '.yujin_init_build'] ]: if os.path.isfile(f): os.remove(f) for d in [ os.path.join(dir_to_be_cleaned, x) for x in ['build', 'devel'] ]: if os.path.isdir(d): shutil.rmtree(d) console.pretty_println('done.\n', console.yellow) else: if os.path.isdir(os.path.abspath(dir_to_be_cleaned)): console.pretty_print("Cleaning build directory : ", console.cyan) console.pretty_println(dir_to_be_cleaned, console.yellow) shutil.rmtree(os.path.abspath(dir_to_be_cleaned)) else: console.logerror("Could not clean %s [does not exist]" % dir_to_be_cleaned)
def clean(dir_to_be_cleaned, dir_sources): if common.is_same_dir(dir_to_be_cleaned, os.getcwd()): if not os.path.isfile(os.path.join(dir_to_be_cleaned, 'config.cmake')): console.logerror("Could not clean the current directory [build artifacts do not exist]") return console.pretty_print("\nCleaning current directory of yujin_init_build artifacts : ", console.cyan) for f in [os.path.join(dir_to_be_cleaned, x) for x in ['config.cmake', 'eclipse', 'gnome-terminal', 'konsole', 'toolchain.cmake', '.bashrc', 'android-studio']]: if os.path.isfile(f): os.remove(f) for f in [os.path.join(dir_to_be_cleaned, dir_sources, x) for x in ['CMakeLists.txt', '.yujin_init_build']]: if os.path.isfile(f): os.remove(f) for d in [os.path.join(dir_to_be_cleaned, x) for x in ['build', 'devel']]: if os.path.isdir(d): shutil.rmtree(d) console.pretty_println('done.\n', console.yellow) else: if os.path.isdir(os.path.abspath(dir_to_be_cleaned)): console.pretty_print("Cleaning build directory : ", console.cyan) console.pretty_println(dir_to_be_cleaned, console.yellow) shutil.rmtree(os.path.abspath(dir_to_be_cleaned)) else: console.logerror("Could not clean %s [does not exist]" % dir_to_be_cleaned)