File: command.pyx

package info (click to toggle)
obitools 3.0.1~b26%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 26,788 kB
  • sloc: ansic: 24,299; python: 657; sh: 27; makefile: 20
file content (44 lines) | stat: -rwxr-xr-x 1,015 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#cython: language_level=3

'''
Created on 27 mars 2016

@author: coissac
'''

import pkgutil

from obitools3 import commands

cdef object loadCommand(str name,loader):
    '''
    Load a command module from its name and an ImpLoader
    
    This function is for internal use
    
    @param name:   name of the module
    @type name: str 
    @param loader: the module loader
    @type loader: ImpLoader
    
    @return the loaded module
    @rtype: module 
    '''
    
    module = loader.find_spec(name).loader.load_module(name)
    return module

def getCommandsList():
    '''
    Returns the list of sub-commands available to the main `obi` command
    
    @return: a dict instance with key corresponding to each command and
             value corresponding to the module
             
    @rtype: dict
    '''
    
    cdef dict cmds = dict((x[1],loadCommand(x[1],x[0])) 
                           for x in pkgutil.iter_modules(commands.__path__) 
                           if not x[2])
    return cmds