def snapshot(self, filename): """Writes current workspace configuration to file :param filename: Name of file to create """ source_aggregate = multiproject_cmd.cmd_snapshot(self.wstool_config) with open(filename, 'w') as f: f.writelines(yaml.safe_dump(source_aggregate))
def cmd_info(self, target_path, argv, reverse=True, config=None): parser = OptionParser( usage="usage: %s info [localname]* [OPTIONS]" % self.progname, formatter=IndentedHelpFormatterWithNL(), description=__MULTIPRO_CMD_DICT__["info"] + """ The Status (S) column shows x for missing L for uncommited (local) changes V for difference in version and/or remote URI The 'Version-Spec' column shows what tag, branch or revision was given in the .rosinstall file. The 'UID' column shows the unique ID of the current (and specified) version. The 'URI' column shows the configured URL of the repo. If status is V, the difference between what was specified and what is real is shown in the respective column. For SVN entries, the url is split up according to standard layout (trunk/tags/branches). When given one localname, just show the data of one element in list form. This also has the generic properties element which is usually empty. The --only option accepts keywords: %(opts)s Examples: $ %(prog)s info -t ~/ros/fuerte $ %(prog)s info robot_model $ %(prog)s info --yaml $ %(prog)s info --only=path,cur_uri,cur_revision robot_model geometry """ % {'prog': self.progname, 'opts': ONLY_OPTION_VALID_ATTRS}, epilog="See: http://www.ros.org/wiki/rosinstall for details\n") parser.add_option( "--data-only", dest="data_only", default=False, help="Does not provide explanations", action="store_true") parser.add_option( "--only", dest="only", default=False, help="Shows comma-separated lists of only given comma-separated attribute(s).", action="store") parser.add_option( "--yaml", dest="yaml", default=False, help="Shows only version of single entry. Intended for scripting.", action="store_true") parser.add_option( "-u", "--untracked", dest="untracked", default=False, help="Also show untracked files as modifications", action="store_true") # -t option required here for help but used one layer above, see cli_common parser.add_option( "-t", "--target-workspace", dest="workspace", default=None, help="which workspace to use", action="store") parser.add_option( "-m", "--managed-only", dest="unmanaged", default=True, help="only show managed elements", action="store_false") (options, args) = parser.parse_args(argv) if config is None: config = multiproject_cmd.get_config( target_path, additional_uris=[], config_filename=self.config_filename) elif config.get_base_path() != target_path: raise MultiProjectException("Config path does not match %s %s " % (config.get_base_path(), target_path)) if args == []: args = None if options.only: only_options = options.only.split(",") if only_options == '': parser.error('No valid options given') lines = get_info_table_raw_csv(config, properties=only_options, localnames=args) print('\n'.join(lines)) return 0 elif options.yaml: source_aggregate = multiproject_cmd.cmd_snapshot(config, localnames=args) print(yaml.safe_dump(source_aggregate), end='') return 0 # this call takes long, as it invokes scms. outputs = multiproject_cmd.cmd_info(config, localnames=args, untracked=options.untracked) if args and len(args) == 1: # if only one element selected, print just one line print(get_info_list(config.get_base_path(), outputs[0], options.data_only)) return 0 header = 'workspace: %s' % (target_path) print(header) table = get_info_table(config.get_base_path(), outputs, options.data_only, reverse=reverse) if table is not None and table != '': print("\n%s" % table) if options.unmanaged: outputs2 = multiproject_cmd.cmd_find_unmanaged_repos(config) table2 = get_info_table(config.get_base_path(), outputs2, options.data_only, reverse=reverse, unmanaged=True) if table2 is not None and table2 != '': print("\nAlso detected these repositories in the workspace, add using '%s set':\n\n%s" % (self.progname, table2)) return 0
def rosinstall_main(argv): if len(argv) < 2: usage() args = argv[1:] parser = OptionParser( usage= "usage: rosinstall [OPTIONS] INSTALL_PATH [ROSINSTALL FILES OR DIRECTORIES]\n\n\ rosinstall does the following:\n\ 1. Merges all URIs into new or existing .rosinstall file at PATH\n\ 2. Checks out or updates all version controlled URIs\n\ 3. If ros stack is installed from source, calls rosmake after checkout or updates.\n\ 4. Generates/overwrites updated setup files\n\n\ If running with --catkin mode:\ 1. Merges all URIs into new or existing .rosinstall file at PATH\n\ 2. Checks out or updates all version controlled URIs\n\ 4. Generates/overwrites updated setup files and creates CMakeLists.txt at the root.\n\n\ URIs can be web urls to remote .rosinstall files, local .rosinstall files,\n\ git, svn, bzr, hg URIs, or other (local directories)\n\ Later URIs will shadow packages of earlier URIs.\n", epilog="See: http://www.ros.org/wiki/rosinstall for details\n") parser.add_option("-c", "--catkin", dest="catkin", default=False, help="Declare this is a catkin build.", action="store_true") parser.add_option( "--cmake-prefix-path", dest="catkinpp", default=None, help="Where to set the CMAKE_PREFIX_PATH, implies --catkin", action="store") parser.add_option("--version", dest="version", default=False, help="display version information", action="store_true") parser.add_option("--verbose", dest="verbose", default=False, help="display more information", action="store_true") parser.add_option("-n", "--nobuild", dest="nobuild", default=False, help="skip the build step for the ROS stack", action="store_true") parser.add_option("--rosdep-yes", dest="rosdep_yes", default=False, help="Pass through --rosdep-yes to rosmake", action="store_true") parser.add_option("--continue-on-error", dest="robust", default=False, help="Continue despite checkout errors", action="store_true") parser.add_option( "--delete-changed-uris", dest="delete_changed", default=False, help="Delete the local copy of a directory before changing uri.", action="store_true") parser.add_option("--abort-changed-uris", dest="abort_changed", default=False, help="Abort if changed uri detected", action="store_true") parser.add_option( "--backup-changed-uris", dest="backup_changed", default='', help= "backup the local copy of a directory before changing uri to this directory.", action="store") parser.add_option("--diff", dest="vcs_diff", default=False, help="shows a combined diff over all SCM entries", action="store_true") parser.add_option( "--status", dest="vcs_status", default=False, help="shows a combined status command over all SCM entries", action="store_true") parser.add_option( "--status-untracked", dest="vcs_status_untracked", default=False, help= "shows a combined status command over all SCM entries, also showing untracked files", action="store_true") parser.add_option("-j", "--parallel", dest="jobs", default=1, help="How many parallel threads to use for installing", action="store") parser.add_option("--generate-versioned-rosinstall", dest="generate_versioned", default=None, help="generate a versioned rosinstall file", action="store") (options, args) = parser.parse_args(args) if options.version: print("rosinstall %s\n%s" % (rosinstall.__version__.version, multiproject_cmd.cmd_version())) sys.exit(0) if len(args) < 1: parser.error("rosinstall requires at least 1 argument") mode = 'prompt' if options.delete_changed: mode = 'delete' if options.abort_changed: if mode == 'delete': parser.error( "delete-changed-uris is mutually exclusive with abort-changed-uris" ) mode = 'abort' if options.backup_changed != '': if mode == 'delete': parser.error( "delete-changed-uris is mutually exclusive with backup-changed-uris" ) if mode == 'abort': parser.error( "abort-changed-uris is mutually exclusive with backup-changed-uris" ) mode = 'backup' # Catkin must be enabled if catkinpp is set if options.catkinpp: options.catkin = True # Get the path to the rosinstall options.path = os.path.abspath(args[0]) config_uris = args[1:] config = multiproject_cmd.get_config(basepath=options.path, additional_uris=config_uris, config_filename=ROSINSTALL_FILENAME) if options.generate_versioned: filename = os.path.abspath(options.generate_versioned) source_aggregate = multiproject_cmd.cmd_snapshot(config) with open(filename, 'w') as fhand: fhand.write(yaml.safe_dump(source_aggregate)) print("Saved versioned rosinstall of current directory %s to %s" % (options.path, filename)) return True if options.vcs_diff: difflist = multiproject_cmd.cmd_diff(config) alldiff = [] for entrydiff in difflist: if entrydiff['diff'] is not None and entrydiff['diff'] != '': alldiff.append(entrydiff['diff']) print('\n'.join(alldiff)) return True if options.vcs_status or options.vcs_status_untracked: statuslist = multiproject_cmd.cmd_status( config, untracked=options.vcs_status_untracked) allstatus = "" for entrystatus in statuslist: if entrystatus['status'] is not None: allstatus += entrystatus['status'] print(allstatus, end='') return True print("rosinstall operating on", options.path, "from specifications in rosinstall files ", ", ".join(config_uris)) # includes ROS specific files print("(Over-)Writing %s" % os.path.join(options.path, ROSINSTALL_FILENAME)) if (os.path.isfile(os.path.join(options.path, ROSINSTALL_FILENAME))): shutil.move(os.path.join(options.path, ROSINSTALL_FILENAME), "%s.bak" % os.path.join(options.path, ROSINSTALL_FILENAME)) rosinstall_cmd.cmd_persist_config(config) ## install or update each element install_success = multiproject_cmd.cmd_install_or_update( config, backup_path=options.backup_changed, mode=mode, robust=options.robust, num_threads=int(options.jobs), verbose=options.verbose) rosinstall_cmd.cmd_generate_ros_files(config, options.path, options.nobuild, options.rosdep_yes, options.catkin, options.catkinpp) if not install_success: print( "Warning: installation encountered errors, but --continue-on-error was requested. Look above for warnings." ) print("\nrosinstall update complete.") if (options.catkin is False and options.catkinpp is None): print( "\n\nNow, type 'source %s/setup.bash' to set up your environment.\nAdd that to the bottom of your ~/.bashrc to set it up every time.\n\nIf you are not using bash please see http://www.ros.org/wiki/rosinstall/NonBashShells " % os.path.abspath(options.path)) return True
def cmd_info(self, target_path, argv, reverse=True, config=None): # similar to multiproject_cli except shows ros-pkg-path # options parser = OptionParser( usage="usage: %s info [localname]* [OPTIONS]" % self.progname, formatter=IndentedHelpFormatterWithNL(), description=__MULTIPRO_CMD_DICT__["info"] + """ The Status (S) column shows x for missing L for uncommited (local) changes V for difference in version and/or remote URI C for difference in local and remote versions The 'Version-Spec' column shows what tag, branch or revision was given in the .rosinstall file. The 'UID' column shows the unique ID of the current (and specified) version. The 'URI' column shows the configured URL of the repo. If status is V, the difference between what was specified and what is real is shown in the respective column. For SVN entries, the url is split up according to standard layout (trunk/tags/branches). The ROS_PACKAGE_PATH follows the order of the table, earlier entries overlay later entries. When given one localname, just show the data of one element in list form. This also has the generic properties element which is usually empty. The --only option accepts keywords: %(opts)s Examples: $ %(prog)s info -t ~/ros/fuerte $ %(prog)s info robot_model $ %(prog)s info --yaml $ %(prog)s info --only=path,cur_uri,cur_revision robot_model geometry """ % { 'prog': self.progname, 'opts': ONLY_OPTION_VALID_ATTRS }, epilog="See: http://wiki.ros.org/rosinstall for details\n") parser.add_option("--root", dest="show_ws_root", default=False, help="Show workspace root path", action="store_true") parser.add_option("--data-only", dest="data_only", default=False, help="Does not provide explanations", action="store_true") parser.add_option("--no-pkg-path", dest="no_pkg_path", default=False, help="Suppress ROS_PACKAGE_PATH.", action="store_true") parser.add_option( "--pkg-path-only", dest="pkg_path_only", default=False, help= "Shows only ROS_PACKAGE_PATH separated by ':'. Supercedes all other options.", action="store_true") parser.add_option( "--only", dest="only", default=False, help= "Shows comma-separated lists of only given comma-separated attribute(s).", action="store") parser.add_option( "--yaml", dest="yaml", default=False, help="Shows only version of single entry. Intended for scripting.", action="store_true") parser.add_option( "--fetch", dest="fetch", default=False, help= "When used, retrieves version information from remote (takes longer).", action="store_true") parser.add_option("-u", "--untracked", dest="untracked", default=False, help="Also show untracked files as modifications", action="store_true") # -t option required here for help but used one layer above, see cli_common parser.add_option("-t", "--target-workspace", dest="workspace", default=None, help="which workspace to use", action="store") parser.add_option("-m", "--managed-only", dest="unmanaged", default=True, help="only show managed elements", action="store_false") (options, args) = parser.parse_args(argv) if config is None: config = get_config(target_path, additional_uris=[], config_filename=self.config_filename) elif config.get_base_path() != target_path: raise MultiProjectException("Config path does not match %s %s " % (config.get_base_path(), target_path)) if options.show_ws_root: print(config.get_base_path()) return 0 if args == []: args = None if options.pkg_path_only: print(":".join(get_ros_package_path(config))) return 0 if options.no_pkg_path: header = 'workspace: %s\nROS_ROOT: %s' % ( target_path, get_ros_stack_path(config)) print(header) return 0 elif options.only: only_options = options.only.split(",") if only_options == '': parser.error('No valid options given') lines = get_info_table_raw_csv(config, parser, properties=only_options, localnames=args) print('\n'.join(lines)) return 0 elif options.yaml: source_aggregate = cmd_snapshot(config, localnames=args) print(yaml.safe_dump(source_aggregate), end='') return 0 # this call takes long, as it invokes scms. outputs = cmd_info(config, localnames=args, untracked=options.untracked, fetch=options.fetch) if args and len(args) == 1: # if only one element selected, print just one line print( get_info_list(config.get_base_path(), outputs[0], options.data_only)) return 0 header = 'workspace: %s\nROS_ROOT: %s' % (target_path, get_ros_stack_path(config)) print(header) table = get_info_table(config.get_base_path(), outputs, options.data_only, reverse=reverse) if table is not None and table != '': print("\n%s" % table) if options.unmanaged: outputs2 = cmd_find_unmanaged_repos(config) table2 = get_info_table(config.get_base_path(), outputs2, options.data_only, reverse=reverse, unmanaged=True) if table2 is not None and table2 != '': print( "\nAlso detected these repositories in the workspace, add using '%s set':\n\n%s" % (self.progname, table2)) return 0
def rosinstall_main(argv): if len(argv) < 2: usage() args = argv[1:] parser = OptionParser( usage="usage: rosinstall [OPTIONS] INSTALL_PATH [ROSINSTALL FILES OR DIRECTORIES]\n\n\ rosinstall does the following:\n\ 1. Merges all URIs into new or existing .rosinstall file at PATH\n\ 2. Checks out or updates all version controlled URIs\n\ 3. If ros stack is installed from source, calls rosmake after checkout or updates.\n\ 4. Generates/overwrites updated setup files\n\n\ If running with --catkin mode:\ 1. Merges all URIs into new or existing .rosinstall file at PATH\n\ 2. Checks out or updates all version controlled URIs\n\ 4. Generates/overwrites updated setup files and creates CMakeLists.txt at the root.\n\n\ URIs can be web urls to remote .rosinstall files, local .rosinstall files,\n\ git, svn, bzr, hg URIs, or other (local directories)\n\ Later URIs will shadow packages of earlier URIs.\n", epilog="See: http://www.ros.org/wiki/rosinstall for details\n", ) parser.add_option( "-c", "--catkin", dest="catkin", default=False, help="Declare this is a catkin build.", action="store_true" ) parser.add_option( "--cmake-prefix-path", dest="catkinpp", default=None, help="Where to set the CMAKE_PREFIX_PATH, implies --catkin", action="store", ) parser.add_option( "--version", dest="version", default=False, help="display version information", action="store_true" ) parser.add_option("--verbose", dest="verbose", default=False, help="display more information", action="store_true") parser.add_option( "-n", "--nobuild", dest="nobuild", default=False, help="skip the build step for the ROS stack", action="store_true", ) parser.add_option( "--rosdep-yes", dest="rosdep_yes", default=False, help="Pass through --rosdep-yes to rosmake", action="store_true", ) parser.add_option( "--continue-on-error", dest="robust", default=False, help="Continue despite checkout errors", action="store_true", ) parser.add_option( "--delete-changed-uris", dest="delete_changed", default=False, help="Delete the local copy of a directory before changing uri.", action="store_true", ) parser.add_option( "--abort-changed-uris", dest="abort_changed", default=False, help="Abort if changed uri detected", action="store_true", ) parser.add_option( "--backup-changed-uris", dest="backup_changed", default="", help="backup the local copy of a directory before changing uri to this directory.", action="store", ) parser.add_option( "--diff", dest="vcs_diff", default=False, help="shows a combined diff over all SCM entries", action="store_true" ) parser.add_option( "--status", dest="vcs_status", default=False, help="shows a combined status command over all SCM entries", action="store_true", ) parser.add_option( "--status-untracked", dest="vcs_status_untracked", default=False, help="shows a combined status command over all SCM entries, also showing untracked files", action="store_true", ) parser.add_option( "-j", "--parallel", dest="jobs", default=1, help="How many parallel threads to use for installing", action="store", ) parser.add_option( "--generate-versioned-rosinstall", dest="generate_versioned", default=None, help="generate a versioned rosinstall file", action="store", ) (options, args) = parser.parse_args(args) if options.version: print("rosinstall %s\n%s" % (rosinstall.__version__.version, multiproject_cmd.cmd_version())) sys.exit(0) if len(args) < 1: parser.error("rosinstall requires at least 1 argument") mode = "prompt" if options.delete_changed: mode = "delete" if options.abort_changed: if mode == "delete": parser.error("delete-changed-uris is mutually exclusive with abort-changed-uris") mode = "abort" if options.backup_changed != "": if mode == "delete": parser.error("delete-changed-uris is mutually exclusive with backup-changed-uris") if mode == "abort": parser.error("abort-changed-uris is mutually exclusive with backup-changed-uris") mode = "backup" # Catkin must be enabled if catkinpp is set if options.catkinpp: options.catkin = True # Get the path to the rosinstall options.path = os.path.abspath(args[0]) config_uris = args[1:] config = multiproject_cmd.get_config( basepath=options.path, additional_uris=config_uris, config_filename=ROSINSTALL_FILENAME ) if options.generate_versioned: filename = os.path.abspath(options.generate_versioned) source_aggregate = multiproject_cmd.cmd_snapshot(config) with open(filename, "w") as fhand: fhand.write(yaml.safe_dump(source_aggregate)) print("Saved versioned rosinstall of current directory %s to %s" % (options.path, filename)) return True if options.vcs_diff: difflist = multiproject_cmd.cmd_diff(config) alldiff = [] for entrydiff in difflist: if entrydiff["diff"] is not None and entrydiff["diff"] != "": alldiff.append(entrydiff["diff"]) print("\n".join(alldiff)) return True if options.vcs_status or options.vcs_status_untracked: statuslist = multiproject_cmd.cmd_status(config, untracked=options.vcs_status_untracked) allstatus = "" for entrystatus in statuslist: if entrystatus["status"] is not None: allstatus += entrystatus["status"] print(allstatus, end="") return True print("rosinstall operating on", options.path, "from specifications in rosinstall files ", ", ".join(config_uris)) # includes ROS specific files print("(Over-)Writing %s" % os.path.join(options.path, ROSINSTALL_FILENAME)) if os.path.isfile(os.path.join(options.path, ROSINSTALL_FILENAME)): shutil.move( os.path.join(options.path, ROSINSTALL_FILENAME), "%s.bak" % os.path.join(options.path, ROSINSTALL_FILENAME) ) rosinstall_cmd.cmd_persist_config(config) ## install or update each element install_success = multiproject_cmd.cmd_install_or_update( config, backup_path=options.backup_changed, mode=mode, robust=options.robust, num_threads=int(options.jobs), verbose=options.verbose, ) rosinstall_cmd.cmd_generate_ros_files( config, options.path, options.nobuild, options.rosdep_yes, options.catkin, options.catkinpp ) if not install_success: print( "Warning: installation encountered errors, but --continue-on-error was requested. Look above for warnings." ) print("\nrosinstall update complete.") if options.catkin is False and options.catkinpp is None: print( "\n\nNow, type 'source %s/setup.bash' to set up your environment.\nAdd that to the bottom of your ~/.bashrc to set it up every time.\n\nIf you are not using bash please see http://www.ros.org/wiki/rosinstall/NonBashShells " % os.path.abspath(options.path) ) return True