public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Sérgio Almeida" <mephx.x@gmail.com>
To: Gentoo SoC <gentoo-soc@lists.gentoo.org>
Cc: Gentoo Dev <gentoo-dev@lists.gentoo.org>
Subject: [gentoo-dev] Re: Progress on Universal Select Tool
Date: Wed, 22 Jul 2009 19:41:57 +0100	[thread overview]
Message-ID: <1248288117.7494.34.camel@thedude> (raw)
In-Reply-To: <1245163715.14589.515.camel@thedude>

[-- Attachment #1: Type: text/plain, Size: 6600 bytes --]

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@gmail.com 
# (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@gmail.com")

# 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@gmail.com 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@gmail.com
mephx @ freenode


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

  parent reply	other threads:[~2009-07-22 18:42 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-16 14:48 [gentoo-dev] Progress on Universal Select Tool Sérgio Almeida
2009-06-17 18:32 ` [gentoo-dev] " Sérgio Almeida
2009-06-29 18:50 ` Sérgio Almeida
2009-06-29 19:02   ` [gentoo-dev] Re: [gentoo-soc] " Sebastian Pipping
2009-06-29 19:42     ` Sérgio Almeida
2009-07-13 15:36 ` [gentoo-dev] " Sérgio Almeida
2009-07-14  9:20   ` Michael Haubenwallner
2009-07-15 15:42     ` Sérgio Almeida
     [not found]     ` <1247582117.3651.3.camel@thedude>
     [not found]       ` <1247584057.14345.29.camel@sapc154.salomon.at>
2009-07-15 15:43         ` Sérgio Almeida
2009-07-16  6:22           ` Michael Haubenwallner
2009-07-22 18:41 ` Sérgio Almeida [this message]
2009-07-23  3:09   ` [gentoo-dev] Re: [gentoo-soc] " Nirbheek Chauhan
2009-07-23  4:43     ` Sérgio Almeida
2009-07-23  5:32       ` Nirbheek Chauhan
2009-07-23 13:35         ` Sérgio Almeida
2009-07-23 15:28           ` Robert Buchholz
2009-07-23 18:33             ` Sérgio Almeida
2009-07-24  8:22               ` Michael Haubenwallner
2009-07-24 15:20                 ` Sérgio Almeida
2009-07-27  8:33                   ` Michael Haubenwallner
2009-07-27 18:35                     ` Sérgio Almeida
     [not found]         ` <6f8b45100907230047k44111c77ha1b68e61b8c88bf2@mail.gmail.com>
2009-07-23 13:40           ` Sérgio Almeida
2009-07-23  6:12     ` [gentoo-dev] " Duncan
2009-08-01 18:46 ` Sérgio Almeida
2009-08-18 15:23 ` Sérgio Almeida

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1248288117.7494.34.camel@thedude \
    --to=mephx.x@gmail.com \
    --cc=gentoo-dev@lists.gentoo.org \
    --cc=gentoo-soc@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox