mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Improvements
This commit is contained in:
parent
5b262362af
commit
3f30dee108
1 changed files with 94 additions and 69 deletions
63
yunohost
63
yunohost
|
@ -1,12 +1,45 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
__credits__ = '''Copyright (C) 2012 YunoHost
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, see http://www.gnu.org/licenses
|
||||
'''
|
||||
__author__ = 'Kload'
|
||||
__version__ = '2.0_beta1'
|
||||
|
||||
import sys
|
||||
import argparse
|
||||
sys.path.append('lib') # Local temporary hack
|
||||
|
||||
# Version of YunoHost
|
||||
version = '2.0'
|
||||
|
||||
""" Useful string-to-function definition """
|
||||
def str2fun(astr):
|
||||
module, _, function = astr.rpartition('.')
|
||||
if module:
|
||||
__import__(module)
|
||||
mod = sys.modules[module]
|
||||
else:
|
||||
mod = sys.modules['__main__'] # or whatever's the "default module"
|
||||
|
||||
try:
|
||||
func = getattr(mod, function)
|
||||
except NameError:
|
||||
print 'Error: Function ' + category + '_' + action + '() is not defined'
|
||||
sys.exit(1)
|
||||
return func
|
||||
|
||||
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
CATEGORIES / ACTIONS
|
||||
|
@ -39,6 +72,9 @@ Leads to functions:
|
|||
category6_action6()
|
||||
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
|
||||
def parse_args(parser):
|
||||
|
||||
parser_array = {
|
||||
'user' : {
|
||||
'actions' : {
|
||||
|
@ -64,24 +100,7 @@ parser_array = {
|
|||
}
|
||||
}
|
||||
|
||||
""" Useful string-to-function definition """
|
||||
def str2fun(astr):
|
||||
module, _, function = astr.rpartition('.')
|
||||
if module:
|
||||
__import__(module)
|
||||
mod = sys.modules[module]
|
||||
else:
|
||||
mod = sys.modules['__main__'] # or whatever's the "default module"
|
||||
|
||||
try:
|
||||
func = getattr(mod, function)
|
||||
except NameError:
|
||||
print 'Error: Function ' + category + '_' + action + '() is not defined'
|
||||
sys.exit(1)
|
||||
return func
|
||||
|
||||
""" Intialize parsers """
|
||||
parser = argparse.ArgumentParser()
|
||||
subparsers = parser.add_subparsers()
|
||||
parsers = subparsers_category = subparsers_action = dict()
|
||||
|
||||
|
@ -133,7 +152,13 @@ parsers['user_list'].add_argument(
|
|||
""" Call arguments parsing """
|
||||
args = parser.parse_args()
|
||||
|
||||
return args
|
||||
|
||||
|
||||
|
||||
def main(args):
|
||||
parser = argparse.ArgumentParser()
|
||||
args = parse_args(parser)
|
||||
args.func(vars(args))
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in a new issue