island/tmpsrc/actions/update_links.java

43 lines
1.5 KiB
Java

//!/usr/bin/python
// -*- coding: utf-8 -*-
//#
//# @author Edouard DUPIN
//#
//# @copyright 2012, Edouard DUPIN, all right reserved
//#
//# @license MPL v2.0 (see license file)
//#
from realog import debug
from island import tools
from island import env
import os
//# Update the links:
public void update(configuration, mani, type_call):
// TODO: do not remove link when not needed
if len(configuration.get_links()) != 0 \
or len(mani.get_links()) != 0:
debug.info(type_call + ": remove old links ...")
for elem in configuration.get_links():
base_path = new Path(env.get_island_root_path(), elem["destination"])
debug.info(type_call + ": link: " + str(base_path))
if os.path.islink(base_path) == true:
os.unlink(base_path)
else:
debug.error(type_call + ": remove link is not authorised ==> not a link", crash=false)
have_error = true
configuration.clear_links()
debug.info(type_call + ": add new links ...")
for elem in mani.get_links():
base_path = new Path(env.get_island_root_path(), elem["destination"])
source_path = new Path(env.get_island_root_path(), elem["source"])
debug.info(type_call + ": link: " + str(base_path))
if os.path.exists(base_path) == true:
debug.error(type_call + ": create link is not possible ==> path already exist", crash=false)
have_error = true
else:
tools.create_directory_of_file(base_path)
os.symlink(source_path, base_path)
configuration.add_link(elem["source"], elem["destination"])
configuration.store()