コード例 #1
0
ファイル: ftp_client.py プロジェクト: alys114/Python_FTP
	def authorization(self):
		'''
		权限验证
		:return:True --> Pass
		'''
		user_name = input('username:'******'password:'******'password:'******'user1'
		# password = '******'
		# md5加密
		password = common.md5Encode(password)
		data = {
			'user_name':user_name,
			'password':password,
			'action':'auth'
				}
		auth_info = json.dumps(data)
		self.client.send(auth_info.encode(CODING))
		server_reply = self.client.recv(BUFSIZ)
		auth_result = json.loads(server_reply.decode(CODING))
		# print(auth_result)
		if auth_result['result']:
			self.user_name = user_name
			self.user_def_dir = auth_result['user_home']
			self.user_cur_dir = auth_result['user_home']
			self.user_old_dir = auth_result['user_home']
			self.limit_size = auth_result['limit_size']
			self.used_size = auth_result['used_size']
			return True

		else:
			common.errorPrompt(auth_result['msg'])
			return False
コード例 #2
0
def classesManage(role):
    '''创建班级'''
    while True:
        for c in role.tec.school.courses:
            print(c)
            for cls in c.classes_list:
                print('|--', cls)
        choice = input('请选择课程编号:([q]退出)')
        if choice == 'q':
            break
        else:
            for c in role.tec.school.courses:
                if c.id == int(choice):
                    cur_course = c
            if cur_course:
                input_name = input('班级名称:')
                input_period = input('学习周期:')
                input_openDate = input('开班日期(%Y-%m-%d):')
                new_classes = Classes(name=input_name,
                                      openDate=input_openDate,
                                      period=input_period)
                new_classes.course = cur_course
                new_classes.teachers = [role.tec]
                role.db.db_session.add(new_classes)
                role.db.db_session.commit()

            else:
                common.errorPrompt('..录入错误..')
コード例 #3
0
ファイル: ftp_client.py プロジェクト: alys114/Python_FTP
	def cmd_put(self,*args):
		'''
		上传文件
		:return:
		'''
		cmd_split = args[0].split()
		if len(cmd_split)>1:
			file_name = cmd_split[1]
			if os.path.isfile(file_name):
				# 组织头文件,发送给客户端确认
				file_size = os.stat(file_name).st_size
				if self.user_cur_dir[-1] ==os.sep:
					client_path = self.user_cur_dir + file_name
				else:
					client_path = self.user_cur_dir + os.sep + file_name

				# 额度校验
				if self.limit_size < self.used_size + file_size:
					common.errorPrompt('已超过上传的额度[%s]k,当前已用[%s]k,当前文件[%s]k'
									   %(self.limit_size,self.used_size,file_size))
					return
				header={
					'file_name':client_path,
					'file_size':file_size,
					'overridden':True,
					'action':'put'
				}
				header_json = json.dumps(header)
				self.client.send(header_json.encode(CODING))
				client_reply = self.client.recv(BUFSIZ).decode()
				# 回复码验证
				if client_reply.__contains__('200'):
					m = hashlib.md5()
					f = open(file_name,'rb')
					send_size = 0
					for line in f:
						self.client.send(line)
						m.update(line)
						send_size += len(line)
						percent = send_size / file_size  # 接收的比例
						common.progress(percent, width=80)  # 进度条的宽度80
					f.close()
					local_md5 = m.hexdigest()
					self.client.send(local_md5.encode(CODING))
					print('send done')



			else:
				print(file_name,' is not exit')
コード例 #4
0
ファイル: ftp_client.py プロジェクト: alys114/Python_FTP
	def cmd_cd(self,*args):
		'''
		切换路径
		:param args:
		:return:
		'''
		cmd =args[0]
		input_path = cmd.split()[1].strip()
		dir_list = self.user_cur_dir.split(os.sep)
		if dir_list[-1]=='':
			del dir_list[-1]
		print(dir_list)
		new_path = ''
		if input_path == '..':
			# 返回上一级菜单
			del dir_list[-1]
			if len(dir_list)>0:
				new_path = os.sep.join(dir_list)+os.sep
		elif input_path == '-':
			# 返回上一轮菜单
			new_path = self.user_old_dir
		else:
			if input_path.startswith(self.user_def_dir):
				new_path = input_path
			else:
				new_path = self.user_def_dir + input_path

		if not new_path.startswith(self.user_def_dir):
			common.errorPrompt('输入的路径有误..')
		# print(new_path)
		else:
			header = {
				'user_name': self.user_name,
				'user_new_dir': new_path,
				'action': 'cd'
			}
			header_json = json.dumps(header)
			# print(header_json)
			self.client.send(header_json.encode(CODING))
			# 服务返回
			server_reply = self.client.recv(BUFSIZ)
			auth_result = json.loads(server_reply.decode(CODING))
			if auth_result['result']:
				self.user_old_dir = self.user_cur_dir
				self.user_cur_dir = new_path
				return True

			else:
				common.errorPrompt(auth_result['msg'])
				return False
コード例 #5
0
ファイル: ftp_client.py プロジェクト: alys114/Python_FTP
	def cmd_get(self,*args):
		'''
		下载文件
		:return:
		'''
		cmd_split = args[0].split()
		if len(cmd_split) > 1:
			file_name = cmd_split[1]
			if self.user_cur_dir[-1] == os.sep:
				client_path = self.user_cur_dir + file_name
			else:
				client_path = self.user_cur_dir + os.sep + file_name
			header = {
				'file_name': client_path,
				'action': 'get'
			}
			header_json = json.dumps(header)
			self.client.send(header_json.encode(CODING))
			# 获取文件信息
			server_reply = self.client.recv(BUFSIZ).decode(CODING)
			print(server_reply)
			# 客户端确认
			self.client.send('ok'.encode(CODING))
			file_size = int(server_reply)
			receive_size = 0
			file_name = cmd_split[1]
			m = hashlib.md5()
			# 写本地文件
			with open(file_name + '.new', 'wb') as f:
				while receive_size < file_size:
					# 解决粘包问题:获取文件大小的数据,作为边界
					cur_buf_size = file_size - receive_size
					if cur_buf_size > BUFSIZ:
						cur_buf_size = BUFSIZ

					data = self.client.recv(cur_buf_size)
					f.write(data)
					receive_size += len(data)  # 注意:一定不能+cur_buf_size,要以实际收到的数据为准
					m.update(data)
					percent = receive_size / file_size  # 接收的比例
					common.progress(percent, width=80)  # 进度条的宽度80
				else:
					local_md5 = m.hexdigest()
					server_md5 = self.client.recv(BUFSIZ)
					server_md5 = server_md5.decode()
					if local_md5 == server_md5:
						print('file rec done.')
					else:
						common.errorPrompt('data is missing or changed..')
コード例 #6
0
def classes_action(role, action):
    '''上课签到/上传作业'''
    print('上课的时间表'.center(center_width, '-'))
    for cls in role.stu.classes_list:
        print(cls)
        for cr in cls.classesRecords:
            print('|--', cr)
    choice = input('请选择签到的课时编号:([q]退出)')
    if choice == 'q':
        return
    else:
        cur_classRecord = None
        for cls in role.stu.classes_list:
            for cr in cls.classesRecords:
                if cr.id == int(choice):
                    cur_classRecord = cr
                    break

        if cur_classRecord:
            input_checkDate = datetime.datetime.now()
            exist_record = None
            for sr in role.stu.studentRecords:
                if sr.classes_record_id == cur_classRecord.id:
                    exist_record = sr
                    break
            if exist_record:
                if action == 'C':
                    exist_record.checkDate = input_checkDate
                else:
                    exist_record.status = 1
            else:
                if action == 'C':
                    new_record = StudentRecord(checkDate=input_checkDate,
                                               status=0)
                else:
                    new_record = StudentRecord(status=1)
                new_record.student = role.stu
                new_record.classesRecord = cur_classRecord
                role.db.db_session.add(new_record)
            role.db.db_session.commit()
            if action == 'C':
                print('签到成功...')
            else:
                print('上传作业成功...')
        else:
            common.errorPrompt('录入错误...')
コード例 #7
0
def register(user):
    print('register...')
    input_login_user = input('login_user > ')
    result = user.Register_Check_LoginUser(input_login_user)
    if result[0]:
        input_qq = input('qq >')
        result = user.Register_Check_qq(input_qq)
        if result[0]:
            input_name = input('alias name > ')
            input_password = input('password > ')
            new_stu = Student(name=input_name,
                              login_user=input_login_user,
                              qq=input_qq,
                              password=input_password)
            user.Register(new_stu)
        else:
            common.errorPrompt(result[1])
            return
    else:
        common.errorPrompt(result[1])
        return
コード例 #8
0
def login(user, db):
    login_user = input('login_user > ').strip()
    password = input('password > ').strip()
    role = input('role[1-stu;2-Teacher] >')
    # login_user = '******'
    # password = '******'
    # role = '1'
    # login_user = '******'
    # password = '******'
    # role = '2'
    member = [int(role), login_user, password]
    result = user.Login(member)
    if result[0]:
        print(result[1])
        member = result[2]
        if role == '1':
            student_main.displayMenu(member, db)
        else:
            teacher_main.displayMenu(member, db)
    else:
        common.errorPrompt(result[1])
コード例 #9
0
def addStu(role):
    while True:
        for cls in role.tec.classes_list:
            print(cls)
        choice = input('请选择班级编号:([q]退出)')
        if choice == 'q':
            break
        else:
            cur_cls = None
            for cls in role.tec.classes_list:
                if cls.id == int(choice):
                    cur_cls = cls
            if cur_cls:
                input_qq = input('加入班级的学生QQ号:')
                stu = role.db.db_session.query(Student).filter(
                    Student.qq == input_qq).first()
                if stu:
                    try:
                        if cur_cls.students.index(stu) > -1:
                            common.errorPrompt('..该学生已在读..')
                    except Exception as e:
                        cur_cls.students.append(stu)
                        role.db.db_session.commit()
                else:
                    common.errorPrompt('没有该QQ号的学生信息..')
            else:
                common.errorPrompt('..录入错误..')
コード例 #10
0
def ChangeScore(role):
    '''修改成绩'''
    while True:
        # 显示已开课的情况
        if len(role.tec.classesRecords) < 1:
            print('暂时没有上课记录....')
            break
        for cr in role.tec.classesRecords:
            print(cr)
        choice = input('请选择你要修改成绩的课时:([q]退出)')
        if choice == 'q':
            break
        else:
            cur_classes = None
            for cr in role.tec.classesRecords:
                if cr.id == int(choice):
                    cur_classes = cr
                    break
            if cur_classes:
                if len(cur_classes.studentRecords) < 1:
                    common.errorPrompt('没有学生上传作业...')
                    break
                for st in cur_classes.studentRecords:
                    print(st)
                choice = input('请录入要修改成绩的记录编号:([q]退出)')
                if choice == 'q':
                    break
                else:
                    for st in cur_classes.studentRecords:
                        if st.id == int(choice):
                            cur_st = st
                            input_score = input('成绩为:')
                            cur_st.score = input_score
                            role.db.db_session.commit()
            else:
                common.errorPrompt('录入错误...')
                break
コード例 #11
0
ファイル: RPC_Client_1.py プロジェクト: alys114/RPC_Cmd

if __name__ == '__main__':
	while True:
		# input_cmd = 'run "ifconfig eth0" --hosts 10.0.0.90    10.0.0.88'
		input_cmd = input('>>:([q:退出]) ')
		remote_hosts = None
		cmd = None
		if input_cmd == 'q':
			break
		elif input_cmd.startswith('run'):
			input_cmd = input_cmd.strip().replace("'", '"')
			cmd = re.search('"(.*)"', input_cmd).group(1)
			data = input_cmd.split(" --hosts ")
			if len(data) > 1:
				remote_hosts = data[1].split()
				# print(remote_hosts)
				cmd_rpc = RemoteCmd_RpcClient()
				for h in remote_hosts:
					print(" [x] Requesting (%s) running: %s " % (h, cmd))
					cmd_rpc.call(h, cmd)
					response = cmd_rpc.get_result()
					common.menuDisplay(("[ Response from %r ]" % h).center(50, '#'))
					print(response)
		else:
			common.errorPrompt('run "ifconfig eth0" --hosts 10.0.0.90    10.0.0.88')