YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
yarpcontext.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <yarp/os/Property.h>
10#include <yarp/os/Bottle.h>
11#include <cstdio>
12
13
14#include "yarpcontextutils.h"
15#include "yarpcontext.h"
16
17using namespace yarp::os;
18
20 printf("Usage: yarp-config context [OPTION]\n\n");
21 printf("Known values for OPTION are:\n\n");
22 printf(" --help display this help and exit\n");
23 printf(" --list list contexts that are available; add optional '--user', '--sysadm' or '--installed' parameters to limit the search locations\n");
24// printf(" --show <context-name> show files that make up a context, and the location of each\n");
25 printf(" --import <context_name> import all the files of the specified context to home directory\n");
26 printf(" --import <context_name> file1 file2 ... import specified context files to home directory\n");
27 printf(" --import-all import all contexts to home directory\n");
28 printf(" --remove <context_name> file1 file2 ... remove specified context files from home directory\n");
29 printf(" --diff <context_name> find differences from the context in the home directory with respect to the installation directory\n");
30 printf(" --diff-list list the contexts in the home directory that are different from the installation directory\n");
31 printf(" --where <context_name> print full paths to the contexts that are found for <context_name> (the first one is the default one)\n");
32 printf(" --merge <context_name> file1 file2 ... merge differences in selected files-directories\n");
33 printf("\n");
34
35}
36
37int yarp_context_main(int argc, char *argv[]) {
38 yarp::os::Property options;
39 options.fromCommand(argc,argv);
40 if (options.check("help")) {
42 return 0;
43 }
44 if (options.check("list")) {
46#ifndef YARP_NO_DEPRECATED // Since YARP 3.4
49 if (options.check("verbose")) {
50 rf.setVerbose(true);
51 }
53#endif // YARP_NO_DEPRECATED
54 if(options.check("user") || options.check("sysadm") || options.check("installed"))
55 {
56 if (options.check("user")) {
58 }
59 if (options.check("sysadm")) {
61 }
62 if (options.check("installed")) {
64 }
65 }
66 else
67 {
71 }
72 return 0;
73 }
74
75 if(options.check("import"))
76 {
77 Bottle importArg=options.findGroup("import");
78#ifndef YARP_NO_DEPRECATED // Since YARP 3.4
79 return import(importArg, CONTEXTS, options.check("verbose"));
80#else
81 return import(importArg, CONTEXTS);
82#endif
83 }
84
85 if(options.check("import-all"))
86 {
87#ifndef YARP_NO_DEPRECATED // Since YARP 3.4
88 return importAll(CONTEXTS, options.check("verbose"));
89#else
90 return importAll(CONTEXTS);
91#endif
92 }
93
94 if(options.check("remove"))
95 {
96 Bottle removeArg=options.findGroup("remove");
97#ifndef YARP_NO_DEPRECATED // Since YARP 3.4
98 return remove(removeArg, CONTEXTS, options.check("verbose"));
99#else
100 return remove(removeArg, CONTEXTS);
101#endif
102
103 }
104
105 if(options.check("where"))
106 {
107 std::string contextName=options.find("where").asString();
108 if (contextName=="")
109 {
110 printf("No context name provided\n");
111 return 0;
112 }
114 if (options.check("user") || options.check("sysadm") || options.check("installed"))
115 {
117 if (options.check("user")) {
119 }
120 if (options.check("sysadm")) {
122 }
123 if (options.check("installed")) {
125 }
126 }
128#ifndef YARP_NO_DEPRECATED // Since YARP 3.4
131 if (options.check("verbose")) {
132 rf.setVerbose(true);
133 }
135#endif // YARP_NO_DEPRECATED
136 yarp::os::Bottle paths=rf.findPaths(std::string("contexts") + PATH_SEPARATOR +contextName, opts);
137 for (size_t curCont = 0; curCont < paths.size(); ++curCont) {
138 printf("%s\n", paths.get(curCont).asString().c_str());
139 }
140 return 0;
141 }
142
143// if(options.check("show"))
144// {
145// std::string contextName=options.find("show").asString().c_str();
146// if (contextName=="")
147// {
148// printf("No context name provided\n");
149// return 0;
150// }
151// yarp::os::ResourceFinder rf;
152// if (options.check("verbose"))
153// rf.setVerbose(true);
154// yarp::os::Bottle paths=rf.findPaths((std::string("contexts") + PATH_SEPARATOR +contextName).c_str());
155// std::vector<std::string> fileList;
156// for (int curCont=0; curCont<paths.size(); ++curCont)
157// {
158// std::vector<std::string> newList;
159// fileList.resize(fileList.size()+);
160// }
161// printf("%s\n", paths.get(curCont).asString().c_str());
162// return 0;
163// }
164
165 if(options.check("diff"))
166 {
167 std::string contextName=options.find("diff").asString();
168 if (contextName=="")
169 {
170 printf("No context name provided\n");
171 return 0;
172 }
173#ifndef YARP_NO_DEPRECATED // Since YARP 3.4
174 return diff(contextName, CONTEXTS, options.check("verbose"));
175#else
176 return diff(contextName, CONTEXTS);
177#endif
178 }
179 if(options.check("diff-list"))
180 {
181#ifndef YARP_NO_DEPRECATED // Since YARP 3.4
182 return diffList(CONTEXTS, options.check("verbose"));
183#else
184 return diffList(CONTEXTS);
185#endif
186 }
187 if(options.check("merge"))
188 {
189 Bottle mergeArg=options.findGroup("merge");
190#ifndef YARP_NO_DEPRECATED // Since YARP 3.4
191 return merge(mergeArg, CONTEXTS, options.check("verbose"));
192#else
193 return merge(mergeArg, CONTEXTS);
194#endif
195 }
197 return 1;
198}
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
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 yarp_context_help()
int yarp_context_main(int argc, char *argv[])
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
@ CONTEXTS