Example #1
0
def main():
    cli_context = CliContext()

    historyPath = os.path.expanduser("~/.uahistory")

    def save_history(historyPath=historyPath):
        import readline
        readline.write_history_file(historyPath)

    if os.path.exists(historyPath):
        readline.read_history_file(historyPath)

    atexit.register(save_history)

    config = Configuration(file_path='/etc/userapp/config.json')
    config.load()

    service_locator = ServiceLocator.get_instance()
    service_locator.register('config', config)
    service_locator.register('cli_context', cli_context)

    command_factory = CliCommandFactory()

    if len(sys.argv) == 1:
        ConsoleHelper.clear_console()

        cli_context.set_interactive(True)

        parser = CliCommandParser()

        while True:
            try:
                cli_scopes = cli_context.get_scopes()

                line = raw_input("userapp" + (
                    ' ' +
                    (':'.join(cli_scopes)) if len(cli_scopes) > 0 else '') +
                                 "> ")

                arguments = parser.parse(line)

                command = command_factory.create(cli_scopes + arguments)
                command.execute()
            except KeyboardInterrupt:
                print(" ")
                if cli_context.exit() is None:
                    break
    else:
        try:
            arguments = sys.argv
            arguments.pop(0)

            command = command_factory.create(arguments)
            command.execute()
        except KeyboardInterrupt:
            print(" ")

    return 0
Example #2
0
def main():
	cli_context=CliContext()

	historyPath = os.path.expanduser("~/.uahistory")

	def save_history(historyPath=historyPath):
	    import readline
	    readline.write_history_file(historyPath)

	if os.path.exists(historyPath):
	    readline.read_history_file(historyPath)

	atexit.register(save_history)

	config=Configuration(file_path='/etc/userapp/config.json')
	config.load()

	service_locator=ServiceLocator.get_instance()
	service_locator.register('config', config)
	service_locator.register('cli_context', cli_context)

	command_factory=CliCommandFactory()

	if len(sys.argv) == 1:
		ConsoleHelper.clear_console()

		cli_context.set_interactive(True)

		parser=CliCommandParser()

		while True:
			try:
				cli_scopes=cli_context.get_scopes()

				line=raw_input("userapp" + (' ' + (':'.join(cli_scopes)) if len(cli_scopes) > 0 else '') + "> ")

				arguments=parser.parse(line)

				command=command_factory.create(cli_scopes + arguments)
				command.execute()
			except KeyboardInterrupt:
				print(" ")
				if cli_context.exit() is None:
					break
	else:
		try:
			arguments=sys.argv
			arguments.pop(0)

			command=command_factory.create(arguments)
			command.execute()
		except KeyboardInterrupt:
			print(" ")

	return 0
Example #3
0
	def __init__(self, arguments=None):
		self.config=ServiceLocator.get_instance().resolve('config')

		self.email=None
		self.password=None

		if arguments is None:
			arguments=[]

		if len(arguments) > 0:
			self.email=arguments[0]

		if len(arguments) > 1:
			self.password=arguments[1]
Example #4
0
	def __init__(self, arguments):
		self.config=ServiceLocator.get_instance().resolve('config')

		self.service=None
		self.method=None
		self.parameters=None

		if len(arguments) > 0:
			call=arguments.pop(0)

			call_segments=call.split('.')
			self.method=call_segments.pop()
			self.service='.'.join(call_segments)

			if len(arguments) > 0:
				parameters={}

				for argument in arguments:
					param_segments=argument.split('=', 1)
					if len(param_segments) == 2:
						parameters[param_segments[0]]=param_segments[1]

				self.parameters=parameters
Example #5
0
	def __init__(self):
		self.config=ServiceLocator.get_instance().resolve('config')
Example #6
0
	def __init__(self, arguments):
		self.arguments=arguments
		self.cli_context=ServiceLocator.get_instance().resolve('cli_context')
Example #7
0
	def __init__(self, arguments):
		service_locator=ServiceLocator.get_instance()
		self.config=service_locator.resolve('config')
		self.cli_context=service_locator.resolve('cli_context')
		self.arguments=arguments
Example #8
0
	def __init__(self):
		self.cli_context=ServiceLocator.get_instance().resolve('cli_context')