From 3dd1822e27f5da4d24457b4f2652fa0ae3c120aa Mon Sep 17 00:00:00 2001 From: Sérgio Almeida Date: Mon, 17 Aug 2009 16:29:32 +0100 Subject: Added support for targetless links aka *.d/ alike links --- modules/gcc.py | 2 +- modules/python.py | 4 ++-- uio.py | 4 ++++ umodule.py | 44 ++++++++++++++++++++++++++++++++++++-------- 4 files changed, 43 insertions(+), 11 deletions(-) diff --git a/modules/gcc.py b/modules/gcc.py index fc18cb8..0249104 100644 --- a/modules/gcc.py +++ b/modules/gcc.py @@ -8,7 +8,7 @@ from umodule import * module = Module(name = "gcc", description = "Python GCC Version Switcher", version = "0.1", author ="mephx.x@gmail.com") # We define the module bin = Action (name = 'bin', description = "Change GCC's Version", type = "sym") # Define a Symlinking Action -gcc = Link(alias = "gcc", target = "/usr/bin/gcc", prefix = "/usr/bin/", regexp = "gcc-([0-9]+\.[0-9]+$)") +gcc = Link(alias = "gcc", target_dir = "usr/bin/", target = "gcc", prefix = "/usr/bin/", regexp = "gcc-([0-9]+\.[0-9]+$)") #gcc_config = Link(alias = "gcc-config", target = "/usr/bin/gcc-config", prefix = "/usr/bin/", regexp = "gcc-config([0-9]+\.[0-9]+$)") #gcc.add_link(gcc_config) # For inheritance testing diff --git a/modules/python.py b/modules/python.py index c850505..f16311e 100644 --- a/modules/python.py +++ b/modules/python.py @@ -9,8 +9,8 @@ module = Module(name = "python", description = "Python Version Switcher", versio bin = Action (name = 'bin', description = "Change Python's Version", type = "sym") # Define a Symlinking Action -python = Link(alias = "python", target = "/usr/bin/python", prefix = "/usr/bin/", regexp = "python([0-9]+\.[0-9]+$)") -python_config = Link(alias = "python-config", target = "/usr/bin/python-config", prefix = "/usr/bin/", regexp = "python([0-9]+\.[0-9]+)-config$") +python = Link(alias = "python", target_dir = "usr/bin/", target = "python", prefix = "/usr/bin/", regexp = "python([0-9]+\.[0-9]+$)") +python_config = Link(alias = "python-config", target_dir = "usr/bin/", target = "python-config", prefix = "/usr/bin/", regexp = "python([0-9]+\.[0-9]+)-config$") python.add_link(python_config) # For inheritance bin.add_link(python) # Adding The Link to the action diff --git a/uio.py b/uio.py index 30e05cd..f0d9423 100644 --- a/uio.py +++ b/uio.py @@ -37,6 +37,10 @@ class FileSystem: def set_type(self, type): if type == 'profile': self.environment = './.uprofile/' + def create_dir(self, target): + """Recursively creates directories""" + if not os.path.exists(target): + os.makedirs(target) def prepare_environment(self): if not os.path.exists(self.environment): diff --git a/umodule.py b/umodule.py index 74c84f9..26ab137 100644 --- a/umodule.py +++ b/umodule.py @@ -101,18 +101,22 @@ class Link: self.links.append(link) link.parent = self - def __init__(self, lines = None, alias = None, target = None, prefix = None, regexp = None, sufix = ''): + def __init__(self, lines = None, alias = None, target = None, \ + target_dir = None, prefix = None, regexp = None, sufix = ''): self.alias = alias - self.target = prefix + alias + self.target_dir = target_dir + self.target = target self.prefix = prefix self.sufix = sufix self.regexp = regexp self.targets = [] self.status = [] self.links = [] - self.destination = self.prefix + self.alias - + if target == None: + self.destination = target_dir + else: + self.destination = target_dir + target def get_links(self, counter = None): """ @@ -143,13 +147,18 @@ class Link: if match: source = self.prefix + match.group(0) + self.sufix self.targets.append(source) - if filesystem.path_exists(self.destination): - if filesystem.real_path(self.destination) == source: + if self.target == None: + target = match.group(0) + else: + target = self.target + + if filesystem.path_exists('/' + self.target_dir + target): + if filesystem.real_path('/' + self.target_dir + target) == source: self.status.append('ok') else: self.status.append('warning') if filesystem.real_path( \ - filesystem.environment + 'bin/' + self.alias) == \ + filesystem.environment + self.target_dir + target) == \ source: status = self.status.pop() status += ' + space + notice' @@ -264,6 +273,7 @@ class Sym(Action): self.output.append('Unsetting ' + link.destination\ + ' success!') else: + filesystem.create_symlink(link.targets[i], \ link.destination) self.output.append('Setting ' + link.targets[i]\ @@ -344,6 +354,16 @@ class ProfileAction(Action): def setup(self): return +class EnvSym(Action): + def do_action(self, args): + print "nothing to do" + + def setup(self): + print "setting up" + + def build(self): + print "building" + class Env(Action): def do_action(self, args): @@ -395,8 +415,16 @@ class Path(Action, Sym): i = target[2] link = target[1] + + filesystem.create_dir(filesystem.environment + link.target_dir) + + if link.target == None: + target = link.targets[i].split('/').pop() + else: + target = link.target + filesystem.create_symlink(link.targets[i], \ - filesystem.environment + 'bin/' + link.alias) + filesystem.environment + link.target_dir + target) self.output.append('Setting ' + link.targets[i] \ + ' success!') -- cgit v1.2.3-65-gdbad