From d8ec60d6d013fdd7e72861e823a908bc6c9a3704 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Touceda?= Date: Fri, 29 Mar 2013 11:54:36 -0300 Subject: Merge updates directory Also, sets the env for thandy to work properly. --- src/CMakeLists.txt | 1 + src/launcher.py | 7 ++++++- src/main.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) 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 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(full_path.string().c_str())); -- cgit v1.2.3