YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
yarprobot.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
7#include <yarp/os/Property.h>
10#include <yarp/os/Bottle.h>
11#include <cstdio>
12
13#include "yarpcontextutils.h"
14#include "yarprobot.h"
15
16using namespace yarp::os;
17
19 printf("Usage: yarp-config robot [OPTION]\n\n");
20 printf("Known values for OPTION are:\n\n");
21 printf(" --help display this help and exit\n");
22 printf(" --list list robots that are available; add optional '--user', '--sysadm' or '--installed' parameters to limit the search locations\n");
23// printf(" --show <context-name> show files that make up a context, and the location of each\n");
24 printf(" --import <robot_name> import specified robot files to home directory\n");
25 printf(" --import-all-robots import all robots to home directory\n");
26 printf(" --remove <robot_name> remove specified robot files from home directory\n");
27 printf(" --diff <robot_name> find differences from the robot in the home directory with respect to the installation directory\n");
28 printf(" --diff-list list the robots in the home directory that are different from the installation directory\n");
29 //printf(" --where <context_name> print full paths to the contexts that are found for <context_name> (the first one is the default one)\n");
30 printf(" --merge <robot_name> file1 file2 ... merge differences in selected files-directories\n");
31 printf("\n");
32
33}
34
35int yarp_robot_main(int argc, char *argv[]) {
36 yarp::os::Property options;
37 options.fromCommand(argc,argv);
38 if (options.check("help")) {
40 return 0;
41 }
42 if (options.check("list")) {
44#ifndef YARP_NO_DEPRECATED // Since YARP 3.4
47 if (options.check("verbose")) {
48 rf.setVerbose(true);
49 }
51#endif // YARP_NO_DEPRECATED
52 if(options.check("user") || options.check("sysadm") || options.check("installed"))
53 {
54 if (options.check("user")) {
56 }
57 if (options.check("sysadm")) {
59 }
60 if (options.check("installed")) {
62 }
63 }
64 else
65 {
69 }
70 return 0;
71 }
72
73 if(options.check("import"))
74 {
75 Bottle importArg=options.findGroup("import");
76#ifndef YARP_NO_DEPRECATED // Since YARP 3.4
77 return import(importArg, ROBOTS, options.check("verbose"));
78#else
79 return import(importArg, ROBOTS);
80#endif
81 }
82
83 if(options.check("import-all-robots"))
84 {
85#ifndef YARP_NO_DEPRECATED // Since YARP 3.4
86 return importAll(ROBOTS, options.check("verbose"));
87#else
88 return importAll(ROBOTS);
89#endif
90 }
91
92 if(options.check("remove"))
93 {
94
95 Bottle removeArg=options.findGroup("remove");
96#ifndef YARP_NO_DEPRECATED // Since YARP 3.4
97 return remove(removeArg, ROBOTS, options.check("verbose"));
98#else
99 return remove(removeArg, ROBOTS);
100#endif
101 }
102
103 if(options.check("where"))
104 {
105 std::string contextName=options.find("where").asString();
106 if (contextName=="")
107 {
108 printf("No robot name provided\n");
109 return 0;
110 }
112 if (options.check("user") || options.check("sysadm") || options.check("installed"))
113 {
115 if (options.check("user")) {
117 }
118 if (options.check("sysadm")) {
120 }
121 if (options.check("installed")) {
123 }
124 }
126#ifndef YARP_NO_DEPRECATED // Since YARP 3.4
129 if (options.check("verbose")) {
130 rf.setVerbose(true);
131 }
133#endif // YARP_NO_DEPRECATED
134
135 yarp::os::Bottle paths=rf.findPaths(std::string("robots") + PATH_SEPARATOR +contextName, opts);
136 for (size_t curCont = 0; curCont < paths.size(); ++curCont) {
137 printf("%s\n", paths.get(curCont).asString().c_str());
138 }
139 return 0;
140 }
141 if(options.check("current"))
142 {
143 std::string result = yarp::conf::environment::get_string("YARP_ROBOT_NAME");
144 if (result.empty()) {
145 printf("Current robot is %s, identified by the environment variable YARP_ROBOT_NAME\n", result.c_str());
146 } else {
147 printf("No robot is set; please set the YARP_ROBOT_NAME environment variable.\n");
148 }
149 return 0;
150
151 }
152
153// if(options.check("show"))
154// {
155// std::string contextName=options.find("show").asString().c_str();
156// if (contextName=="")
157// {
158// printf("No context name provided\n");
159// return 0;
160// }
161// yarp::os::ResourceFinder rf;
162// if (options.check("verbose"))
163// rf.setVerbose(true);
164// yarp::os::Bottle paths=rf.findPaths((std::string("contexts") + PATH_SEPARATOR +contextName).c_str());
165// std::vector<std::string> fileList;
166// for (int curCont=0; curCont<paths.size(); ++curCont)
167// {
168// std::vector<std::string> newList;
169// fileList.resize(fileList.size()+);
170// }
171// printf("%s\n", paths.get(curCont).asString().c_str());
172// return 0;
173// }
174
175 if(options.check("diff"))
176 {
177 std::string contextName=options.find("diff").asString();
178 if (contextName=="")
179 {
180 printf("No robot name provided\n");
181 return 0;
182 }
183#ifndef YARP_NO_DEPRECATED // Since YARP 3.4
184 return diff(contextName, ROBOTS, options.check("verbose"));
185#else
186 return diff(contextName, ROBOTS);
187#endif
188 }
189 if(options.check("diff-list"))
190 {
191#ifndef YARP_NO_DEPRECATED // Since YARP 3.4
192 return diffList(ROBOTS, options.check("verbose"));
193#else
194 return diffList(ROBOTS);
195#endif
196 }
197 if(options.check("merge"))
198 {
199 Bottle mergeArg=options.findGroup("merge");
200#ifndef YARP_NO_DEPRECATED // Since YARP 3.4
201 return merge(mergeArg, ROBOTS, options.check("verbose"));
202#else
203 return merge(mergeArg, ROBOTS);
204#endif
205 }
207 return 1;
208}
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:64
A mini-server for performing network communication in the background.
A class for storing options and configuration information.
Definition Property.h:33
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
Bottle & findGroup(const std::string &key) const override
Gets a list corresponding to a given keyword.
void fromCommand(int argc, char *argv[], bool skipFirst=true, bool wipe=true)
Interprets a list of command arguments as a list of properties.
These options are loosely based on http://wiki.icub.org/wiki/YARP_ResourceFinder.
Helper class for finding config files and other external resources.
yarp::os::Bottle findPaths(const std::string &name)
Expand a partial path to a list of paths.
bool setVerbose(bool verbose=true)
Request that information be printed to the console on how resources are being found.
virtual std::string asString() const
Get string value.
Definition Value.cpp:234
std::string get_string(const std::string &key, bool *found=nullptr)
Read a string from an environment variable.
Definition environment.h:66
An interface to the operating system, including Port based communication.
#define YARP_WARNING_POP
Ends a temporary alteration of the enabled warnings.
Definition system.h:334
#define YARP_WARNING_PUSH
Starts a temporary alteration of the enabled warnings.
Definition system.h:333
#define YARP_DISABLE_DEPRECATED_WARNING
Disable deprecated warnings in the following code.
Definition system.h:335
void printSysadmFolders(yarp::os::ResourceFinder &rf, folderType ftype)
void printInstalledFolders(yarp::os::ResourceFinder &rf, folderType ftype)
void printUserFolders(yarp::os::ResourceFinder &rf, folderType ftype)
int remove(yarp::os::Bottle &removeArg, folderType fType, bool verbose)
int diffList(folderType fType, bool verbose)
int diff(std::string contextName, folderType fType, bool verbose)
int importAll(folderType fType, bool verbose)
int merge(yarp::os::Bottle &mergeArg, folderType fType, bool verbose)
#define PATH_SEPARATOR
@ ROBOTS
int yarp_robot_main(int argc, char *argv[])
Definition yarprobot.cpp:35
void yarp_robot_help()
Definition yarprobot.cpp:18