summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/__init__.py0
-rw-r--r--modules/env.uselect325
-rw-r--r--modules/gcc.py18
-rw-r--r--modules/gcc.uselect41
-rw-r--r--modules/kernel.uselect24
-rw-r--r--modules/one.uselect44
-rw-r--r--modules/python.py20
-rw-r--r--modules/python.uselect21
8 files changed, 38 insertions, 455 deletions
diff --git a/modules/__init__.py b/modules/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/modules/__init__.py
diff --git a/modules/env.uselect b/modules/env.uselect
deleted file mode 100644
index effed56..0000000
--- a/modules/env.uselect
+++ /dev/null
@@ -1,325 +0,0 @@
-# Copyright 1999-2009 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-# env.uselect mephx.x@gmail.com
-
-module env {
- description "Manage environment variables set in /etc/env.d/"
- version "0.1"
- author "mephx.x@gmail.com"
-} env
-
-
-user action update
- description "Collect environment variables from all scripts in /etc/env.d/"
- parameters "<makelinks> <noldconfig>"
- options {
- "makelinks : Specify \"makelinks\" to force updating of links"
- "noldconfig : Do not alter the ld.so cache or configuration."
- }
- type runnable
-
- file env-update.bash {
- #!/bin/bash
- # Classes of env-vars
-
- source /usr/share/eselect/libs/tests.bash
- source /usr/share/eselect/libs/core.bash
- source /usr/share/eselect/libs/path-manipulation.bash
-
- source /usr/share/eselect/libs/config.bash
- source /usr/share/eselect/libs/multilib.bash
-
- SPACE_CLASS="CONFIG_PROTECT
- CONFIG_PROTECT_MASK"
- PATH_CLASS="ADA_INCLUDE_PATH
- ADA_OBJECT_PATH
- CLASSPATH
- INFODIR
- INFOPATH
- KDEDIRS
- LDPATH
- MANPATH
- PATH
- PKG_CONFIG_PATH
- PRELINK_PATH
- PRELINK_PATH_MASK
- PYTHONPATH
- ROOTPATH"
-
- # Recognized file formats:
- MIME_WHITELIST="text/plain text/x-makefile"
-
- # Configuration files
- ENVPROFILE="${ROOT}/etc/profile.env"
- LDCONFIG="${ROOT}/etc/ld.so.conf"
- PRELINK="${ROOT}/etc/prelink.conf"
- LDMTIMEDB="${ROOT}/var/lib/eselect/env/ld-mtimedb"
-
- # Keep all stored LDPATHS
- ESELECT_LDPATH=( )
-
- # is_envd_file()
- # Return successfuly when file can be sourced.
- is_envfile() {
- local mime envfile=${1}
-
- # Make sure it is a file and no backup file
- [[ -f ${envfile} ]] || return 1
- [[ -n ${envfile##*~} ]] || return 1
- [[ ${envfile##*.} != bak ]] || return 1
-
- mime=$(POSIXLY_CORRECT=1 file -i ${envfile} \
- | cut -d ' ' -f 2 | sed -e 's/;$//')
- if ! has ${mime} ${MIME_WHITELIST} ; then
- echo "Skipping non-text file ${envfile}."
- return 1
- fi
-
- return 0
- }
-
- # update_envvar_classes()
- # Update the contents of *_CLASS based on env,d files.
- update_envvar_classes() {
- local -a envfiles
- local value
- envfiles=( ${ROOT}/etc/env.d/* )
-
- for envfile in ${envfiles[@]} ; do
- is_envfile ${envfile} || continue
-
- value=$(load_config ${envfile} COLON_SEPARATED)
- for x in ${value} ; do
- has ${x} ${PATH_CLASS} && continue
- PATH_CLASS="${PATH_CLASS} ${x}"
- done
-
- value=$(load_config ${envfile} SPACE_SEPARATED)
- for x in ${value} ; do
- has ${x} ${SPACE_CLASS} && continue
- SPACE_CLASS="${SPACE_CLASS} ${x}"
- done
- done
- }
-
- # create_profile_env()
- # Create profile.env file
- create_profile_env() {
- local -a envfiles
- local vars store items tmpprofile
- envfiles=( ${ROOT}/etc/env.d/* )
-
- # Blank the file first!
- tmpprofile="$(mktemp ${ROOT}/tmp/profile.XXXXXX)"
- [[ $? = 0 ]] || die "Couldn't create temporary file!"
-
- # Gather ye classes while ye may!
- update_envvar_classes
-
- # Parse all files in env.d
- for envfile in ${envfiles[@]} ; do
- is_envfile ${envfile} || continue
-
- # Which vars are to be loaded?
- # TODO: Change to bash magic?
- vars=$(sed \
- -e '/^#/d' -e '/^\s*$/d' -e '/^.*=/s/^\([^=]*\)=.*/\1/' \
- ${envfile})
- [[ -z ${vars} ]] && continue
- for var in ${vars} ; do
- # Colon separated?...
- if has ${var} ${PATH_CLASS} ; then
- store=$(load_config ${tmpprofile} ${var})
- if [[ -z ${store} ]] ; then
- store=$(load_config ${envfile} ${var})
- else
- items="$(load_config ${envfile} ${var})"
- items=( ${items//:/ } )
- for item in ${items[@]} ; do
- has ${item} ${store//:/ } && continue
- store="${store}:${item}"
- done
- fi
- store_config ${tmpprofile} ${var} "${store#:}"
- continue
- fi
- # Space separated!...
- if has ${var} ${SPACE_CLASS} ; then
- store=( $(load_config ${tmpprofile} ${var}) )
- if [[ -z ${store[@]} ]] ; then
- store=( $(load_config ${envfile} ${var}) )
- else
- items=( $(load_config ${envfile} ${var}) )
- for item in ${items[@]} ; do
- has ${item} ${store[@]} && continue
- store=( ${store[@]} ${item} )
- done
- fi
- store_config ${tmpprofile} ${var} "${store[@]}"
- continue
- fi
- # Ok, just a non-cummultative var.
- store_config \
- ${tmpprofile} \
- ${var} \
- "$(load_config ${envfile} ${var})"
- done
-
- has LDPATH ${vars} || continue
- # Store LDPATH for later processing
- items=$(load_config ${envfile} LDPATH)
- items=( ${items//:/ } )
- for item in ${items[@]} ; do
- has ${item} ${LDPATH[@]} && continue
- ESELECT_LDPATH=( ${ESELECT_LDPATH[@]} ${item} )
- done
- done
-
- # Move new file onto old one
- ENVPROFILE=$(canonicalise ${ENVPROFILE})
- chmod a+r ${tmpprofile}
- mv ${tmpprofile} ${ENVPROFILE} \
- || die "Couldn't move ${tmpprofile} to ${ENVPROFILE}!\n
- Original profile.env remains unchanged."
- }
-
- # create_ld_so_conf()
- # Create ld.so.conf file based upon gathered LDPATHs
- create_ld_so_conf() {
- [[ -z ${ESELECT_LDPATH[@]} ]] && die -q 'No LDPATHs found in ${ROOT}/etc/env.d/*'
-
- local str
- str="# ld.so.conf autogenerated by eselect\n"
- str="${str}# Make all changes to /etc/env.d files\n"
- for x in ${ESELECT_LDPATH[@]} ; do
- str="${str}${x}\n"
- done
- echo -e "${str}" > $(canonicalise ${LDCONFIG})
- }
-
- # create_prelink_conf()
- # Create prelink.conf file based upon existing profile.env
- create_prelink_conf() {
- [[ -z ${ESELECT_LDPATH[@]} ]] && die -q 'No LDPATHs found in ${ROOT}/etc/env.d/*'
- local str
- str="# prelink.conf autogenerated by eselect\n"
- str="${str}# Make all changes to /etc/env.d files\n"
- # Add default items
- for x in /bin /sbin /usr/bin /usr/sbin ; do
- str="${str}-l ${x}\n"
- done
- for x in $(list_libdirs) ; do
- [[ -e ${ROOT}/${x} ]] && str="${str}-l /${x}\n"
- [[ -e ${ROOT}/usr/${x} ]] && str="${str}-l /usr/${x}\n"
- done
- prelink_mask=$(load_config ${ENVPROFILE} PRELINK_PATH_MASK)
- prelink_mask=( ${prelink_mask//:/ } )
- prelink="$(load_config ${ENVPROFILE} PATH)"
- prelink="${prelink} $(load_config ${ENVPROFILE} PRELINK_PATH)"
- prelink=( ${prelink//:/ } ${ESELECT_LDPATH[@]} )
- for x in ${prelink[@]} ; do
- has ${x} ${prelink_mask} && continue
- [[ -z ${x##*/} ]] || x="${x}/"
- str="${str}-h ${x}\n"
- done
- for x in ${prelink_mask[@]} ; do
- str="${str}-b ${x}\n"
- done
- echo -e "${str}" > $(canonicalise ${PRELINK})
- }
-
- # need_links()
- # Returns true if any item of ${LDPATH} has been modified.
- need_links() {
- local ret=1
- for x in ${ESELECT_LDPATH[@]} ; do
- y=${x//\//_}
- y=${y//-/_}
- y=${y//./_}
- y=${y//+/_}
- oldmtime=$(load_config ${LDMTIMEDB} "mtime${y}")
- newmtime=$(stat -c %Y ${x} 2> /dev/null)
- if [[ ${oldmtime} != ${newmtime} ]] ; then
- ret=0
- store_config ${LDMTIMEDB} "mtime${y}" ${newmtime}
- fi
- done
- return ${ret}
- }
-
- # update_ldcache()
- # Update ld.so.cache using ldconfig
- update_ldcache() {
- case $(uname -s) in
- FreeBSD | DragonFly)
- echo "Regenerating ${ROOT}/var/run/ld-elf.so.hints..."
- (
- cd /
- ldconfig -elf -i -f "${ROOT:-/}var/run/ld-elf.so.hints" \
- "${ROOT:-/}etc/ld.so.conf"
- )
- ;;
- *)
- echo "Regenerating ${ROOT}/etc/ld.so.cache..."
- (
- cd /
- ldconfig ${1} -r ${ROOT:-/}
- )
- ;;
- esac
- }
-
- ### update action
-
-
-
-
- do_update() {
- local makelinks ldconfig=1
- while [[ ${#@} -gt 0 ]] ; do
- case ${1} in
- makelinks)
- makelinks="-X"
- ;;
- noldconfig)
- ldconfig=0
- ;;
- *)
- die -q "Unknown option '${1}'"
- ;;
- esac
- shift
- done
-
- if [[ -e ${ROOT}/etc/profile.env ]] ; then
- [[ -w ${ROOT}/etc/profile.env ]] \
- || die -q "You need to be root!"
- else
- touch ${ROOT}/etc/profile.env
- fi
-
- # Create configuration files
- create_profile_env
- if [[ ${ldconfig} == 1 ]] ; then
- create_ld_so_conf
- [[ -e ${ROOT}/usr/sbin/prelink ]] && create_prelink_conf
- need_links && makelinks="-X"
- update_ldcache ${makelinks}
- fi
-
- # fix up ${ENVPROFILE}
- cp ${ENVPROFILE} ${ENVPROFILE/.env/.csh}
- sed -i \
- -e "s/^\(.*\)=\"\(.*\)\"/export \1='\2'/" \
- $(canonicalise ${ENVPROFILE})
- sed -i \
- -e "s/^\(.*\)=\"\(.*\)\"/setenv \1 '\2'/" \
- $(canonicalise ${ENVPROFILE/.env/.csh})
- }
-
- do_update $@
-
- } env-update.bash
-} update
-
-# vim: ft=eselect
diff --git a/modules/gcc.py b/modules/gcc.py
new file mode 100644
index 0000000..ece02f4
--- /dev/null
+++ b/modules/gcc.py
@@ -0,0 +1,18 @@
+#!/usr/bin/env python
+# Copyright 1999-2009 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# python.uselect mephx.x@gmail.com
+
+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_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
+bin.add_link(gcc) # Adding The Link to the action
+module.add_action(bin) #Adding the action to the module
+
+
diff --git a/modules/gcc.uselect b/modules/gcc.uselect
deleted file mode 100644
index 10a1fad..0000000
--- a/modules/gcc.uselect
+++ /dev/null
@@ -1,41 +0,0 @@
-module gcc{
- description "GCC Version Switcher"
- version "0.1"
- author "mephx.x@gmail.com"
-} gcc
-
-system action profile {
- description "Change GCC's /usr/bin/gcc Version"
- type runnable
- parameters "<target>"
- usage "<target> Target GCC profile."
- file moo.bash {
- #!/bin/bash
- do_moo() {
- if [ -z $1 ]
- then
- gcc-config -l
- else
- gcc-config $@
- fi
- }
- do_moo $@
- } moo.bash
-} profile
-
-system action bin {
- description "Print path where binaries of the given/current profile are located."
- type runnable
- file moo.bash {
- #!/bin/bash
- do_moo() {
- if [ -z $1 ]
- then
- gcc-config -B
- else
- gcc-config -B
- fi
- }
- do_moo $@
- } moo.bash
-} bin
diff --git a/modules/kernel.uselect b/modules/kernel.uselect
deleted file mode 100644
index 646730a..0000000
--- a/modules/kernel.uselect
+++ /dev/null
@@ -1,24 +0,0 @@
-# Copyright 1999-2009 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-# kernel.uselect mephx.x@gmail.com
-
-module kernel {
- description "Kernel Switcher"
- version "0.1"
- author "mephx.x@gmail.com"
-} kernel
-
-system action src {
- description "Change current kernel source target"
- type sym
- sym linux /usr/src/linux /usr/src/ (.*)-(.*$) *
-} src
-
-system action boot {
- description "Change current kernel boot target"
- type sym
- sym vmlinuz /boot/vmlinuz /boot/ vmlinuz-(.*$) *
-} boot
-
-
-
diff --git a/modules/one.uselect b/modules/one.uselect
deleted file mode 100644
index 91e3709..0000000
--- a/modules/one.uselect
+++ /dev/null
@@ -1,44 +0,0 @@
-# Copyright 1999-2009 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-# one.uselect mephx.x@gmail.com
-
-module one {
- description "Example Module description"
- version "0.2"
- author "mephx.x@gmail.com"
-} one
-
-user action moo {
- description "Example Module will moo for any user"
- parameters "<integer>"
- usage "<integer> - number of moos"
- type runnable
- file moo.bash {
- #!/bin/bash
- do_moo() {
- if [ -z $1 ]
- then
- # print options
- echo "1 - moo one time"
- echo "2 - moo two times"
- echo "3 - moo three times"
- echo "x - moo x times"
- else
- for((i=0;$i<$1;i=$(($i+1))));do
- echo moo
- done
- fi
- }
- do_moo $@
- } moo.bash
-} moo
-
-system action foo {
- description "Example Simple symlinking Action"
- usage "moo <option>"
- type sym
- sym /usr/moo /usr/share/ moo-(\w+) /bin/moo
-} foo
-
-
-
diff --git a/modules/python.py b/modules/python.py
new file mode 100644
index 0000000..e6115fc
--- /dev/null
+++ b/modules/python.py
@@ -0,0 +1,20 @@
+#!/usr/bin/env python
+# Copyright 1999-2009 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# python.uselect mephx.x@gmail.com
+
+from umodule import *
+
+module = Module(name = "python", description = "Python Version Switcher", version = "0.1", author ="mephx.x@gmail.com") # We define the module
+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_config2 = Link(alias = "python-config", target = "/usr/bin/python-config", prefix = "/usr/bin/", regexp = "python([0-9]+\.[0-9]+)-config$")
+
+python.add_link(python_config) # For inheritance
+#python_config.add_link(python_config2) # For further inheritance test
+bin.add_link(python) # Adding The Link to the action
+module.add_action(bin) #Adding the action to the module
+
+
diff --git a/modules/python.uselect b/modules/python.uselect
deleted file mode 100644
index 79df588..0000000
--- a/modules/python.uselect
+++ /dev/null
@@ -1,21 +0,0 @@
-# Copyright 1999-2009 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-# python.uselect mephx.x@gmail.com
-
-module python {
- description "Python Version Switcher"
- version "0.1"
- author "mephx.x@gmail.com"
-} python
-
-user action bin {
- description "Change Python's Version"
- type sym
- sym python /usr/bin/python /usr/bin/ python([0-9]+\.[0-9]+$) *
-} bin
-
-system action config {
- description "Change Python's /usr/bin/python-config Version"
- type sym
- sym python /usr/bin/python-config /usr/bin/ python([0-9]+\.[0-9]+)-config($) *
-} config