forked from r4ntix/pythonbrew
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasecommand.py
More file actions
37 lines (30 loc) · 938 Bytes
/
basecommand.py
File metadata and controls
37 lines (30 loc) · 938 Bytes
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
import os
import sys
import re
from optparse import OptionParser
from pythonbrew import commands
command_dict = {}
class Command(object):
name = None
usage = None
summary = ""
def __init__(self):
self.parser = OptionParser(usage=self.usage,
prog='%s %s' % ("pythonbrew", self.name))
command_dict[self.name] = self
def run(self, args):
options, args = self.parser.parse_args(args)
self.run_command(options, args)
def load_command(name):
full_name = 'pythonbrew.commands.%s' % name
if full_name in sys.modules:
return
try:
__import__(full_name)
except ImportError:
pass
def load_all_commands():
for name in command_names():
load_command(name)
def command_names():
return [path[:-3] for path in os.listdir(commands.__path__[0]) if not re.match("(__init__\.py$|.*\.pyc$)", path)]