Esempio n. 1
0
    def do_giant(self, cmd):
        p1 = cmd.find("create")
        p2 = cmd.find("upload")
        p3 = cmd.find("download")

        if cmd.find("create") is not -1:
            if cmd.find("--type=root") is not -1:
                ruser_info = {}
                ruser_info["ruser_id"] = get_para("--uid=", cmd)
                ruser_info["ruser_pw"] = get_para("--pw=", cmd)
                auth_api = Auth_api()
                res = auth_api.Create_RUser(ruser_info=ruser_info)
                print(ruser_info)

            elif cmd.find("--type=sub") is not -1:
                ruser_info = {}
                suser_info = {}
                ruser_id = get_para("--uid=", cmd)
                ruser_pw = get_para("--pw=", cmd)
                suser_info["user_id"] = get_para("--suid=", cmd)
                suser_info["display_name"] = get_para("--display_name=", cmd)
                auth_api = Auth_api()
                res = auth_api.Create_SUser(ruser_id=ruser_id, ruser_pw=ruser_pw, suser_info=suser_info)
                print("create subuser sueccess")

            elif cmd.find("--type=bucket") is not -1:
                bucket = get_para("--bucketname=", cmd)
                access_key = get_para("--a_key=", cmd)
                secret_key = get_para("--s_key=", cmd)
                s3 = G_s3.S3(access_key=access_key, secret_key=secret_key)
                res = s3.create_bucket(bucket=bucket)
                print("create bucket success")

        if cmd.find("upload") is not -1:
            bucket = get_para("--bucketname=", cmd)
            access_key = get_para("--a_key=", cmd)
            secret_key = get_para("--s_key=", cmd)
            key = get_para("--key=", cmd)
            local_file_path = get_para("--path=", cmd)
            # print(local_file_path)
            s3 = G_s3.S3(access_key=access_key, secret_key=secret_key)
            res = s3.upload(bucket=bucket, key=key, local_file_path=local_file_path)
            print("upload success")

        if cmd.find("download") is not -1:
            bucket = get_para("--bucketname=", cmd)
            access_key = get_para("--a_key=", cmd)
            secret_key = get_para("--s_key=", cmd)
            key = get_para("--key=", cmd)
            to_local_file_path = get_para("--path=", cmd)
            s3 = G_s3.S3(access_key=access_key, secret_key=secret_key)
            res = s3.download(bucket=bucket, key=key, to_local_file_path=to_local_file_path)
            print("download success")
Esempio n. 2
0
def get_para(key, cmd):
    p = cmd.find(key)
    q = len(key)
    para = cmd[p + q : len(cmd)]
    i = 1
    for s in para:
        if s.isspace() is False:
            i = i + 1
        else:
            break
    para = para[0 : i - 1]
    return para
Esempio n. 3
0
File: jsh.py Progetto: raveneus/jsh
def handle_cmd(cmd, var):
    cmd = sub(cmd, var)
    to_eval = [""]
    evaled = [""]
    for j in range(10):
        to_eval.append("")
        evaled.append("")
    i = 0
    while cmd.find("(") != -1:
        to_eval[i] = cmd[cmd.find("("):cmd.find(")") + 1]
        cmd = cmd.replace(to_eval[i], "/h")
        i += 1
    to_eval = filter(None, to_eval)
    i = 0
    for to in to_eval:
        evaled[i]  = evaluate(to, var)
    cmd = cmd.replace(" ", "\x90")
    i = 0
    while cmd.find("/h") != -1:
        cmd = cmd.replace(cmd[cmd.find("/h"):cmd.find("/h") + 2], evaled[i])
    cmd_list = getTokenList(cmd, "\x90")
    cmd_list = filter(None, cmd_list)
    return cmd_list
Esempio n. 4
0
def command(line,reku=False):
	global stop_command
	args = re.split('\s+',line[1:])
	cmd = find_cmd(args[0])
	if cmd == None:
		print("Unknown command "+args[0])
		return False
	if cmd == 'uart':
		if len(args) == 1:
			b = 9600
		elif args[1] == 'fast':
			b = 460800
		else:
			b = args[1]
		sys.stdout.write(reader_prompt)
		tty_send("uart.setup(0,{0},8,0,1,0)".format(b))
		time.sleep(0.5)
		kill_tty()
		open_tty(b)
	elif cmd == 'help':
		replcmd.do_help('')
	elif cmd == 'paste' or cmd == 'file' or cmd.find('compile') or cmd == 'load':
		if cmd == 'file' or cmd == 'load' or (cmd == 'execute' and len(args) == 2) or (cmd.find('compile') and len(args) == 3):
			if cmd == 'load' or cmd == 'execute':
				if len(args)==1:
					print("bad args, should be ':load src'")
					return False
				args.append(args[1])
			if len(args) != 3:
				print("bad args, should be ':file dst src'")
				return False
			try:
				with open(args[2],"rb") as f:
					buff = f.read()
			except IOError:
				print("file {0} not found".format(args[2]))
				return False
		else:
			try:
				buff = bytes(clipboard.paste())
			except UnicodeEncodeError:
				print("invalid clipboard content")
				return False
		if cmd == 'cross-compile' or cmd == 'execute':
			buff = luac_compile(buff)
			if buff == None:
				return False
		if cmd == 'soft-compile':
			head = ["collectgarbage() function __wrapper__()"]
			head += re.split("[\r\n]+",buff)
			head.append("end")
			head.append(OPEN_SEQ.format(args[1]))
			head.append("file.write(string.dump(__wrapper__)) file.close() __wrapper__=nil collectgarbage()")
		elif cmd == 'execute':
			head = ['collectgarbage() __backup__ = c c = {}']
			head += lualib_b64
			for x in reversed(base64_split(buff)):
				head.append('table.insert(c,{0})'.format(x))
			head.append('__code__=c c=__backup__ __backup__=nil')
			head.append('local r,e=load(function() collectgarbage() tmr.wdclr() return table.remove(__code__,#__code__) end) if r==nil then print(e) else r() end __code__= nil')
		elif len(args) > 1 and cmd != 'load':
			head = ['collectgarbage()']
			head += lualib_b64
			head += lualib_crc
			head.append(OPEN_SEQ.format(args[1]))
			for x in base64_split(buff):
				head.append('file.write({0})'.format(x))
			head.append('file.close() __c32__("{0}",{1}) __c32__=nil __dec__=nil collectgarbage()'.format(args[1],binascii.crc32(buff)))
		else:
			head = re.split("[\r\n]+",buff)
		sys.stdout.write(reader_prompt)
		if not reku:
			stop_command = False
		for x in head:
			if stop_command:
				print("aborted")
				break
			if x[0]==':' and (cmd=='load' or cmd=='paste'):
				command(x,True)
			else:
				tty_send(bytes(x))
				sem.acquire()
		if not reku:
			stop_command = True
Esempio n. 5
0
 def getDirectory(self):
     cmd = self.cmd.strip(',')
     index = cmd.find('/')
     return cmd[index:]
Esempio n. 6
0
 def getDirectory(self):
     cmd = self.cmd.strip(',')
     index = cmd.find('/')
     return cmd[index:]