Gentoo Logo
Gentoo Spaceship

Installation:
Gentoo Handbook
Installation Docs

Documentation:
Home
Listing
About Gentoo
Philosophy
Social Contract

Resources:
Bug Tracker
Developer List
Discussion Forums
Gentoo BitTorrents
Gentoo Linux Enhancement Proposals
IRC Channels
Mailing Lists
Mirrors
Name and Logo Guidelines
Online Package Database
Security Announcements
Staffing Needs
Supporting Vendors
View our CVS

Graphics:
Logos and themes
Icons
ScreenShots

Miscellaneous Resources:
Gentoo Linux Store
Gentoo-hosted projects
IBM dW/Intel article archive




List Archive: gentoo-soc
Navigation:
Lists: gentoo-soc: < Prev By Thread Next > < Prev By Date Next >
Headers:
To: Gentoo SoC <gentoo-soc@g.o>
From: Sérgio Almeida <mephx.x@...>
Subject: Re: Progress on Universal Select Tool
Date: Wed, 22 Jul 2009 19:41:57 +0100
Hello,

This has been a very productive week regarding uselect.

I'm still not doing any commits as uselect can still break your python
environment while testing and i don't have the time to learn how to
handle branches in git.

Status:

* Fully Converted all action types to new module syntax
* Infinite symlinking dependency fully working
* Runnable Actions now support dynamic usage showing

An example fully commented module follows

### Start of Module

#!/usr/bin/env python
# Copyright 1999-2009 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# python.py mephx.x@... 
# (will explain .py instead of .uselect below)
# still lacking vim/emacs python line

from umodule import * 

# We Create The Module
module = Module(name = "python", description = "Python Version
Switcher", version = "0.1", author ="mephx.x@...")

# We Create a Linking Action
action_bin = Action (name = 'bin', description = "Change Python's
Version", type = "sym")

# We Create a Link
link_python = Link(alias = "python", target = "/usr/bin/python", prefix
= "/usr/bin/", regexp = "python([0-9]+\.[0-9]+$)")

# We Create Another Link
link_python_config = Link(alias = "python-config", target =
"/usr/bin/python-config", prefix = "/usr/bin/", regexp =
"python([0-9]+\.[0-9]+)-config$")

# Make the link "python_config" depend of "link_python"
link_python.add_link(link_python_config)

# Add the link to the action
action_bin.add_link(python)

# Add the action to the module
module.add_action(action_bin)


# We create a simple runnable action that "tests" python environment
test = Action (name = 'test', description = 'Test Python Environment',
type = 'runnable')

# We add the parameters/arguments

test.add_parameter('<times>')
test.add_parameter('[<what>]')

# We add the usage code

test.add_usage("""#!/usr/bin/python
print "Python Test will echo <times> * <what>"
print "Usage can be multi-line Yay!"
print ""
for i in range(5):
	print "Usage can have dynamic options! " + str(i)
""")

# We add the action code
test.add_code("""#!/usr/bin/python
import sys

def is_number(s):
    try:
        int(s)
        return True
    except ValueError:
        return False
		
argv = sys.argv[1:]
times = sys.argv[1:][0]
if is_number(times):
	times = int(times)	
	if len(argv) >= 2:
		what = sys.argv[1:][1]
	else: 
		what = 'Hello World...'
	print str(what) * times
else:
	print 'Invalid Option(s)'
	exit(1)
exit(0)
""")

# We add the action to the module
module.add_action(test)

### End of Module


So... what's the output of this?

### Start Examples

* uselect 

Usage: uselect <options> <module> <action> 

 Options:
    -v  		(*) Verbose Mode
    -nc 		(*) No Colors
    -version    	(*) Version Information

Modules:
    python      	(*) Python Version Switcher
    gcc 		(*) Python GCC Version Switcher

* uselect python

Usage: uselect <options> python <action> 

Module python:
Author: mephx.x@... Version: 0.1

Actions:
    bin 		Change Python's Version
    test		Test Python Environment


* uselect python bin

Usage: uselect <options> python bin <target> ... <target> 

    Change Python's Version

      0 - /usr/bin/python2.6 - (>)
          1 - /usr/bin/python2.6-config - (>)
          2 - /usr/bin/python2.5-config - (!)
      3 - /usr/bin/python2.5 - (!)
          4 - /usr/bin/python2.6-config - (>)
          5 - /usr/bin/python2.5-config - (!)

* uselect python bin 2

Setting /usr/bin/python2.5-config success!
Setting /usr/bin/python2.6 success

* uselect python bin (again)

Usage: uselect <options> python bin <target> ... <target> 

    Change Python's Version

      0 - /usr/bin/python2.6 - (>)
          1 - /usr/bin/python2.6-config - (!)
          2 - /usr/bin/python2.5-config - (>)
      3 - /usr/bin/python2.5 - (!)
          4 - /usr/bin/python2.6-config - (>)
          5 - /usr/bin/python2.5-config - (!)

* uselect python test

Usage: uselect <options> python test <times> [<what>] 

    Test Python Environment

    Python Test will echo <times> * <what>
    Usage can be multi-line Yay!
        		
    Usage can have dynamic options! 0
    Usage can have dynamic options! 1
    Usage can have dynamic options! 2
    Usage can have dynamic options! 3
    Usage can have dynamic options! 4

* uselect python test 10 "yeah! "

yeahyeahyeahyeahyeahyeahyeahyeahyeahyeah

I guess this is all for the past week. Symlinking dependency really
cranked my brain and almost got me stuck.

Next steps:

* add the --system option for system-wide changes
* Implement env actions
* Structure folders ".uselect/" (probabily will have a bin folder and a
env.d folder)
* Start structuring uprofile application and api
* Profiles will be xml/json (and will use this part of code to uselect
too)


* Call for ideas

        * Python gurus: Atm i'm retrieving the module from .uselect
        files this way:
        
        def get_modules(self):
        	self.modules = []
        	for module in filesystem.list_dir(modules_dir):
        		if re.match('__init__.py$', module):
        			continue
        		match = re.match('(.*).py$', module)
        		if match:
        			import modules
        			modname = match.group(1)
        			modpath = 'modules.'+ modname
        			__import__(modpath)
        			module = eval(modpath + '.module')
        			self.modules.append(module)		
        
        This is a bit ugly. Should there be a better way? I can't seem
        to achieve one. This is the reason why new modules are still
        called module.py and not module.uselect as should be.
        

        * If you are a developer of any eselect modules or
        something-config please reply with suggestions. All ideas are
        welcome.

    * Everyone else: 
        User profiles will stand in ~/.uselect
        Folder Profiles will stand in $FOLDER/.uselect
        What about group profiles?
        
        Modules like bash-completion work in a "env.d" style. Should an
        action type be created for actions like these (I believe they
        are very common).
        
        Well, all ideas are welcome again.

P.S: I have successfully passed the first midterm evaluation. Thanks to
everyone that has contributed to this new project, especially my mentor
Sébastien Fabbro (bicatali).

Cheers,
Sérgio
        
-- 
Sérgio Almeida - mephx.x@...
mephx @ freenode

Attachment:
signature.asc (This is a digitally signed message part)
Replies:
Re: Re: Progress on Universal Select Tool
-- Donnie Berkholz
Re: Re: Progress on Universal Select Tool
-- Nirbheek Chauhan
References:
Progress on Universal Select Tool
-- Sérgio Almeida
Navigation:
Lists: gentoo-soc: < Prev By Thread Next > < Prev By Date Next >
Previous by thread:
Re: Progress on Universal Select Tool
Next by thread:
Re: Re: Progress on Universal Select Tool
Previous by date:
Re: Re: [GSoC-status] Collagen - database schema and further changes
Next by date:
Re: Re: Progress on Universal Select Tool


Updated Sep 12, 2009

Donate to support our development efforts.

Gentoo Centric Hosting: vr.org

VR Hosted

Tek Alchemy

Tek Alchemy

SevenL.net

SevenL.net

php|architect

php|architect

Copyright 2001-2007 Gentoo Foundation, Inc. Questions, Comments? Email www@gentoo.org.