def cmd_create(self): """ """ if len(self.argv) < 3: value = None else: value = self.argv[2] if value is not None: if value.endswith('.py'): raise CommandError("\nNot include '.py'\n") path_extend = get_config_value('path-extend') if path_extend is None: print "Path extend is not define." print "Use:\n dozo extend path /path/to/extend" return path_to_file = "{0}/commands/{1}.py".format(path_extend,value) if path.isfile(path_to_file): print "\nOption command '{0}' exist.\n".format(value) filename = '%s/commands/%s.py' % ( path_extend, value ) f = open(filename,'w+') f.write(pystache.render(TEMPLATE_OPTION_COMMAND, {'name':value})) f.close()
def cmd_edit(self): """ """ try: extend_command = self.argv[2] except: extend_command = None if extend_command is None: #print "Please use option:" #print " dozo %s" % self.usage return text_editor = get_config_value('text-editor') if text_editor is None: print "\n Text editor is not define.\n" print "Use:\n dozo config add text-editor=vim\n" return path_extend = get_config_value('path-extend') if path_extend is None: print('''\n Path extend is not define.\n Use:\n dozo config path-extend /opt/dozo/dozo_extend''') return filename = '{0}/commands/{1}.py'.format(path_extend, extend_command) if not path.isfile(filename): print('\n{0}: Extend command not exist.\n'.format( extend_command)) return cmd = '{0} {1}'.format(text_editor, filename) r = envoy.run(cmd) if r is not 0: print('\n{0}\n'.format(r.std_err))
def get_extend_commands(test_path_extend=None): """ Returns a list of all the command names that are available. Returns an empty list if no commands are defined. """ if test_path_extend is None: command_dir = '%s/commands' % get_config_value('path-extend') else: command_dir = '%s/commands' % test_path_extend try: return [f[:-3] for f in os.listdir(command_dir) if not f.startswith('_') and f.endswith('.py')] except OSError: return []
def load_extend_commands(name, test_path_extend=None): if test_path_extend is None: path_extend = get_config_value('path-extend') else: path_extend = test_path_extend if path_extend is None: return path_extend path_ext = ('/'.join(path_extend.split('/')[:-1])) path_ext_cmd = path_extend.split('/')[-1:] if path_ext not in sys.path: sys.path.append(path_ext) full_name = '%s.commands.%s' % ('/'.join(path_ext_cmd[-1:]), name) try: __import__(full_name) except Exception, error: print error sys.exit(1)