Changeset View
Changeset View
Standalone View
Standalone View
pykolab/cli/commands.py
Show All 10 Lines | |||||
# This program is distributed in the hope that it will be useful, | # This program is distributed in the hope that it will be useful, | ||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
# GNU General Public License for more details. | # GNU General Public License for more details. | ||||
# You should have received a copy of the GNU General Public License | # You should have received a copy of the GNU General Public License | ||||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
# | # | ||||
from six import string_types | |||||
import os | import os | ||||
import sys | import sys | ||||
import pykolab | import pykolab | ||||
from pykolab.translate import _ | from pykolab.translate import _ | ||||
▲ Show 20 Lines • Show All 128 Lines • ▼ Show 20 Lines | for commands_path, dirnames, filenames in os.walk(commands_base_path): | ||||
exec("%s_%s_register()" % (module,cmd_name)) | exec("%s_%s_register()" % (module,cmd_name)) | ||||
def register(cmd_name, func, group=None, description=None, aliases=[]): | def register(cmd_name, func, group=None, description=None, aliases=[]): | ||||
if not group == None: | if not group == None: | ||||
command = "%s_%s" % (group,cmd_name) | command = "%s_%s" % (group,cmd_name) | ||||
else: | else: | ||||
command = cmd_name | command = cmd_name | ||||
if isinstance(aliases, basestring): | if isinstance(aliases, string_types): | ||||
aliases = [aliases] | aliases = [aliases] | ||||
if command in commands: | if command in commands: | ||||
log.fatal(_("Command '%s' already registered") % (command)) | log.fatal(_("Command '%s' already registered") % (command)) | ||||
sys.exit(1) | sys.exit(1) | ||||
if callable(func): | if callable(func): | ||||
if group == None: | if group == None: | ||||
Show All 30 Lines |