forked from mheily/rooms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
repoParser.cc.UNUSED
66 lines (56 loc) · 1.66 KB
/
repoParser.cc.UNUSED
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "repoParser.hpp"
#include <iostream>
#include <fstream>
#include <string.h>
using json = nlohmann::json;
RepoParser::RepoParser() {
}
void RepoParser::parse(const std::string& path)
{
repoJsonPath = path;
json top;
parseJSON(top);
if (top["api_version"].get<unsigned int>() != 0) {
throw std::runtime_error("unsupported API version");
}
baseUri = top["base_uri"];
json rooms_json = top["rooms"];
for (json::iterator it = rooms_json.begin(); it != rooms_json.end(); ++it) {
RepoRoom* rr = new RepoRoom(it.key(), it.value());
rooms[it.key()] = rr;
}
}
void RepoParser::parseJSON(json& result)
{
try {
std::ifstream ifs(repoJsonPath, std::ifstream::in);
ifs >> result;
} catch (std::exception& e) {
//log_error("error parsing %s: %s", path.c_str(), e.what());
throw;
} catch (...) {
throw;
}
}
void RepoParser::installRoom(const std::string& name)
{
std::string uri = baseUri + "/" + name + "/full.txz";
std::cout << "downloading: " << uri << "\n";
string tarball = "/tmp/test-" + name + ".txz"; //XXX-FIXME insecure
Shell::execute("/usr/bin/fetch", { "-q", "-o", path, uri });
}
void RepoParser::printSearchResult(const std::string& pattern)
{
for (auto& it : rooms) {
auto rr = it.second;
if (pattern != "") {
auto name = rr->getName();
auto summary = rr->getSummary();
if (strcasestr(name.c_str(), pattern.c_str()) == NULL &&
strcasestr(summary.c_str(), pattern.c_str()) == NULL) {
continue;
}
}
printf("%-20s %s\n", rr->getName().c_str(), rr->getSummary().c_str());
}
}