summaryrefslogtreecommitdiff
blob: c51be9a7679244093d27c7177091e6f4b4d823f6 (plain)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env python
# Copyright 1999-2009 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# Universal Select Tool
# Base Module
# umodule.py mephx.x@gmail.com

import os
import re
import sys
import stat
import string
import traceback

from umodule import *
from uio import *
	
verbose = False

version = '0.2'
modules_dir = '/usr/share/uselect/modules/'


class UniversalSelectTool:
	
	def __init__(self):

		return

	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)		
		
				
	def get_module(self, name):
		import modules
		modname = name
		modpath = 'modules.'+ modname
		__import__(modpath)
		module = eval(modpath + '.module')
		return module

	def parse_argv(self, argv):
		global profile, verbose, version
		module = None
		modules = None
		action = None
		args = None	
		printsystem.use_colors(True)
		for arg in argv:
			if arg == '-v':
				verbose = True
				printsystem.verbose()
				argv = argv[1:]
			elif arg == '-nc':
				printsystem.use_colors(False)
				argv = argv[1:]
			elif arg == '-version':
				printsystem.print_version(version)
				argv = argv[1:]			
		if len(argv) < 1:
			self.get_modules()
			modules = self.modules
		elif len(argv) == 1:
			module = self.get_module(argv[0])
		elif len(argv) >= 2:
			module = self.get_module(argv[0])
			action = module.get_action(argv[1])
			action.build()
			action.do_action(argv[2:])
		if len(argv) == 2:
			argv = None
		else:
			argv = argv[2:]
		
		return [module, modules, argv, action]


def main():
	uselect = UniversalSelectTool()
	try:
		list = uselect.parse_argv(sys.argv[1:])
		printsystem.print_ui(module = list[0], \
			modules = list[1], args = list[2], action = list[3])
	except UserWarning, warning:
		printsystem.print_exception(warning, True)
	except Exception, exception:
		printsystem.print_exception(exception)
		if verbose:
			traceback.print_exc()
			printsystem.print_line('')
		exit(1)
	exit(0)

if __name__ == '__main__': main()