summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomás Touceda <chiiph@leap.se>2013-03-29 11:54:36 -0300
committerTomás Touceda <chiiph@leap.se>2013-03-29 11:54:36 -0300
commitd8ec60d6d013fdd7e72861e823a908bc6c9a3704 (patch)
tree73e5690546f95ae342759c6deea195545aba7cfc
parent1a39a8fa75494a05606312342d1cfa8d94035efa (diff)
Merge updates directory
Also, sets the env for thandy to work properly.
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/launcher.py7
-rw-r--r--src/main.cpp59
3 files changed, 66 insertions, 1 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b783d6c..13eec53 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -4,6 +4,7 @@ SET(CMAKE_INSTALL_RPATH "lib")
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
SET(launcher_SOURCES main.cpp)
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
IF(WIN32)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mwindows")
diff --git a/src/launcher.py b/src/launcher.py
index 61e2a7f..328c965 100644
--- a/src/launcher.py
+++ b/src/launcher.py
@@ -1,3 +1,4 @@
+import os
import time
import threading
@@ -9,8 +10,12 @@ class Thandy(threading.Thread):
def run(self):
while True:
try:
+ os.environ["THP_DB_ROOT"] = os.path.join(os.getcwd(),
+ "packages")
+ os.environ["THP_INSTALL_ROOT"] = os.path.join(os.getcwd(),
+ "updates")
args = [
- "--repo=/home/chiiph/Code/leap/repo/",
+ "--repo=/home/chiiph/Code/leap/repo/", # TODO:set as a URL
"--debug",
"--install",
"/bundleinfo/LEAPClient/"
diff --git a/src/main.cpp b/src/main.cpp
index d59a886..7b99470 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -10,12 +10,71 @@
namespace py = boost::python;
namespace fs = boost::filesystem;
+static const std::string UPDATES_DIR = "updates";
+
+/**
+ Given two directories, it merges them by copying new files and
+ directories, and replacing existing files with the ones at the
+ destination
+ */
+void
+mergeDirectories(const fs::path &source,
+ const fs::path &dest)
+{
+ fs::path sourceDir(source);
+ fs::directory_iterator end_iter;
+
+ std::vector<fs::path> files;
+
+ if (fs::exists(sourceDir) && fs::is_directory(sourceDir))
+ {
+ for(fs::directory_iterator dir_iter(sourceDir); dir_iter != end_iter; ++dir_iter)
+ {
+ if (fs::is_regular_file(dir_iter->status()))
+ {
+ auto destFilePath = dest / dir_iter->path().filename();
+ copy_file(dir_iter->path(), destFilePath, fs::copy_option::overwrite_if_exists);
+ }
+ else if (fs::is_directory(dir_iter->status()))
+ {
+ auto currentPath = dir_iter->path();
+ auto pathAtDest = dest / currentPath.filename();
+ if (!fs::exists(pathAtDest))
+ {
+ // This just creates the directory
+ copy_directory(currentPath, pathAtDest);
+ }
+ mergeDirectories(currentPath, pathAtDest);
+ } // Ignore other kind of files for now
+ }
+ }
+}
+
+void
+updateIfNeeded()
+{
+ fs::path updatePath(fs::current_path() / fs::path(UPDATES_DIR));
+ if (fs::exists(updatePath))
+ {
+ std::cout << "Found updates, merging directories before doing anything..."
+ << std::endl;
+ mergeDirectories(updatePath, fs::current_path());
+ fs::remove_all(updatePath);
+ }
+ else
+ {
+ std::cout << "No updates found" << std::endl;
+ }
+}
+
int
main(int argc, char** argv)
{
try {
fs::path full_path(fs::current_path());
+ updateIfNeeded();
+
Py_Initialize();
Py_SetPythonHome(const_cast<char*>(full_path.string().c_str()));