-
Notifications
You must be signed in to change notification settings - Fork 0
/
venv.hpp
103 lines (94 loc) · 2.88 KB
/
venv.hpp
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//
// venv.hpp
// venv
//
// Created by Daher Alfawares on 11/30/17.
// Copyright © 2017 Daher Alfawares. All rights reserved.
//
#ifndef venv_hpp
#define venv_hpp
#include "x_shell.hpp"
#include "x_table.hpp"
#include "x_uuid.hpp"
#include "venv_item.hpp"
#include "static.hpp"
#include <string>
#include <sstream>
#include <set>
#include <iostream>
namespace v {
struct venv {
std::string name;
std::set<item> items;
std::string id;
venv(){}
venv(std::string name):name(name), id(x::uuid::string()) {}
void add(item i){
if(items.find(i)==items.end()){
items.insert(i);
} else {
std::cerr << external_path(i) << " already exists." << std::endl;
throw -1;
}
}
void remove(item i){
std::string src = this->internal_path(i);
std::string command = x::shell::remove(src).c_str();
::system(command.c_str());
}
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & this->name;
ar & this->id;
ar & this->items;
}
std::string internal_path(const item& item){
return v::root_folder + "/" + this->name + "/" + item.id;
}
std::string external_path(const item& item){
return item.filename;
}
void pull(const item& item){
std::string src = this->internal_path(item);
std::string dst = this->external_path(item);
std::string command = x::shell::copy(src,dst).c_str();
::system(command.c_str());
}
void pull(){
std::cout << "pulling [" << this->name << "]" << std::endl;
for(auto item:this->items){
this->pull(item);
}
}
void push(const item& item){
std::string src = this->external_path(item);
std::string dst = this->internal_path(item);
std::string command = x::shell::copy(src,dst);
::system(command.c_str());
}
void push(){
std::cout << "pushing [" << this->name << "]" << std::endl;
for(auto item:this->items){
push(item);
}
}
void diff(const item& item){
std::string src = this->external_path(item);
std::string dst = this->internal_path(item);
std::string command = x::shell::diff(src,dst);
::system(command.c_str());
}
};
inline
std::ostream& operator << (std::ostream& stream,const venv& venv){
x::table out("files in ["+venv.name+"]");
out("id")("file")++;
for(auto item:venv.items){
out(item.id)(item.filename)++;
}
stream << out;
return stream;
}
}
#endif /* venv_hpp */