Example #1
0
 def welcome(self):
     # 欢迎界面
     height, width = BaseView().linesnum()
     print '\r'
     top_margin = (height - len(welcome)) / 2
     left_margin = (width - len(welcome[-4])) / 2
     print '\n' * top_margin
     for i in welcome:
         print ' ' * left_margin + i
     print '\n' * (height - top_margin - len(welcome))
     # 欢迎界面结束
     time.sleep(time_welcome)
    def run(self, switch_queue):
        #用于控制切换界面
        #self.switch_queue = switch_queue
        #self.quit = False
        #Thread(target=self._controller).start()
        #Thread(target=self._watchdog_queue).start()
        #Thread(target=self._wacthdog_process).start()
        try:
            backdir = raw_input('请输入要保存的路径: ')
        except KeyboardInterrupt:
            print "\t\033[41m 程序终止! \033[m\n"
        if backdir.endswith('/'):
            backdir = backdir[::-1]

	# 进度条
        base = BaseView()
        screen_height, screen_width = base.linesnum()
        content = ['']
        per = 0
	# 进度条线程
        def thread_display():
            while True:
                display_lines = ['\r']
                display_lines.append('正在复制' + '\r')
                display_lines.append('')
                # length = len(content)
                # 显示正在复制的内容
                c = content
                half = screen_height / 2
                if len(c) > half:
                    c = c[-half:]
                for i in c:
                    display_lines.append(i)

                if per == 100:
                    display_lines.append("\t\033[36m 复制完成! \033[m")
                else:
                    display_lines.append('\t\033[36m 完成:' + str(per) + '%\033[m')
                display_lines.append('')
                for i in range(screen_height - len(display_lines) - 3):
                    display_lines.append('')
                pos = screen_width * per / 100 - 1
                if pos < 1:
                    pos = 1
                display_lines.append('=' * pos + '>')
                display_lines.append('\r')
                print '\n'.join(display_lines)
                if per == 100:
                    break
                time.sleep(0.5)

        Thread(target=thread_display).start()
        db = sqlite3.connect('../loginfo.db')
        cur = db.cursor()
        cur.execute('SELECT * FROM log_select')
        all_log = cur.fetchall()
	
	#测试代码
        print '开始'
        total = len(all_log)
        num = 0
        for filelog in all_log:
            print filelog
            copyfile(filelog[0], backdir)
            basename = os.path.basename(filelog[0])
            dirname = os.path.dirname(filelog[0])
            targetname = backdir + dirname + '/' + basename
            content.append('复制' + str(filelog) + '-->' + str(targetname))
            num += 1
            per = num * 100 / total
            time.sleep(0.1)
    def run(self, switch_queue):
        #用于控制切换界面
        #self.switch_queue = switch_queue
        #self.quit = False
        #Thread(target=self._controller).start()
        #Thread(target=self._watchdog_queue).start()
        #Thread(target=self._wacthdog_process).start()
        try:
            backdir = raw_input('请输入要保存的路径: ')
        except KeyboardInterrupt:
            print "\t\033[41m 程序终止! \033[m\n"
        if backdir.endswith('/'):
            backdir = backdir[::-1]

# 进度条
        base = BaseView()
        screen_height, screen_width = base.linesnum()
        content = ['']
        per = 0

        # 进度条线程
        def thread_display():
            while True:
                display_lines = ['\r']
                display_lines.append('正在复制' + '\r')
                display_lines.append('')
                # length = len(content)
                # 显示正在复制的内容
                c = content
                half = screen_height / 2
                if len(c) > half:
                    c = c[-half:]
                for i in c:
                    display_lines.append(i)

                if per == 100:
                    display_lines.append("\t\033[36m 复制完成! \033[m")
                else:
                    display_lines.append('\t\033[36m 完成:' + str(per) +
                                         '%\033[m')
                display_lines.append('')
                for i in range(screen_height - len(display_lines) - 3):
                    display_lines.append('')
                pos = screen_width * per / 100 - 1
                if pos < 1:
                    pos = 1
                display_lines.append('=' * pos + '>')
                display_lines.append('\r')
                print '\n'.join(display_lines)
                if per == 100:
                    break
                time.sleep(0.5)

        Thread(target=thread_display).start()
        db = sqlite3.connect('../loginfo.db')
        cur = db.cursor()
        cur.execute('SELECT * FROM log_select')
        all_log = cur.fetchall()

        #测试代码
        print '开始'
        total = len(all_log)
        num = 0
        for filelog in all_log:
            print filelog
            copyfile(filelog[0], backdir)
            basename = os.path.basename(filelog[0])
            dirname = os.path.dirname(filelog[0])
            targetname = backdir + dirname + '/' + basename
            content.append('复制' + str(filelog) + '-->' + str(targetname))
            num += 1
            per = num * 100 / total
            time.sleep(0.1)
Example #4
0
	print('# {0:<30} #'.format(''))
	print('# {0:<30} #'.format('Choose an option:'))
	print('# {0:<30} #'.format('1 - Login'))
	print('# {0:<30} #'.format('0 - Close'))
	print('# {0:<30} #'.format(''))
	print(34 * '#')
	print()
	print('Type your option:')

if __name__ == '__main__':
	
	controller = MainController()
	
	close_app = False
	while not close_app:
		BaseView.clear_screen()
		print_menu()
		choice = input()
		if choice == '0':
			close_app = True
		elif choice == '1':
			controller.start_session()
		else:
			BaseView.clear_screen()
			print('\nInvalid option.\n')
			print('Press ENTER to try again...')
			input()
			
	
	BaseView.clear_screen()
Example #5
0
    def _watchdog_switch(self):
        '''
        切换页面线程
        '''
        self.view_control_map['main'].run(self.switch_queue)

        while not self.quit_quit:
            try:
                key = self.switch_queue.get()
                if key == 'quit_quit':
                    self.quit_quit = True
                elif key == 'rawinput':# 输出所有文件
                    logging.info('输出所有文件 开始')
                    try:
                        # backdir = raw_input('请输入要保存的路径: ')
                        backdir = raw_input('\033[41m请输入要保存的目录名称:\033[m    ')

                    except KeyboardInterrupt:
                        print "\t\033[41m 程序终止! \033[m\n"

                    try: 

                        if backdir == '':
                            backdir = '../__save'
                        if backdir.endswith('/'):
                            backdir = backdir[::-1]
                        now = time.strftime('%Y_%m_%d_%H_%M_%S', time.localtime())
                        backdir = '../' + backdir + '/' + now
                        # 进度条
                        base = BaseView()
                        screen_height, screen_width = base.linesnum()
                        content = ['']
                        per = 0
                        # 进度条线程
                        def thread_display():
                            while True:
                                try:
                                    display_lines = ['\r']
                                    display_lines.append('正在复制' + '\r')
                                    display_lines.append('')
                                    # length = len(content)
                                    # 显示正在复制的内容
                                    c = content
                                    half = screen_height / 2
                                    if len(c) > half:
                                        c = c[-half:]
                                    for i in c:
                                        display_lines.append(i)

                                    if per == 100:
                                        pass
                                    else:
                                        display_lines.append('\t\033[36m 完成:' + str(per) + '%\033[m')
                                    display_lines.append('')
                                    for i in range(screen_height - len(display_lines) - 10):
                                        display_lines.append('')
                                    pos = screen_width * per / 100 - 1
                                    if pos < 1:
                                        pos = 1
                                    display_lines.append('=' * pos + '>')
                                    display_lines.append('')
                                    display_lines.append('')
                                    if per == 100:
                                        display_lines.append('')
                                        display_lines.append(' ' * (screen_width / 2 - len(done_msg) / 3) + done_msg)
                                    else:
                                        display_lines.append('')
                                        display_lines.append('')
                                    display_lines.append('')
                                    display_lines.append('')
                                    display_lines.append('')
                                    display_lines.append('\r')
                                    print '\n'.join(display_lines)
                                    if per == 100:
                                        break
                                    time.sleep(0.5)
                                except Exception,e:
                                    print e
                                    logging.debug(e)
                                    break

                        Thread(target=thread_display).start()
                        
                        logging.info('读取选择的文件')
                        db = sqlite3.connect('db/loginfo.db')
                        cur = db.cursor()
                        cur.execute('SELECT * FROM log_select')
                        all_log = cur.fetchall()
                        # 
                        total = len(all_log)
                        logging.info('选择的文件共:%s' % total)
                        num = 0
                        for filelog in all_log:
                            # copyfile(filelog[0], backdir)
                            copyfileByCommd(filelog[0], backdir)
                            basename = os.path.basename(filelog[0])
                            dirname = os.path.dirname(filelog[0])
                            targetname = backdir + dirname + '/' + basename
                            content.append('复制 ' + str(filelog[0]) + ' --> ' + str(targetname))
                            logging.info('复制 ' + str(filelog[0]) + ' --> ' + str(targetname))
                            num += 1
                            per = num * 100 / total
                            # TODO delete
                            time.sleep(0.1)
                        per = 100
                        logging.info('输出所有文件 结束')
                        self.initsysteminfo(backdir)
                        time.sleep(1)
                    except Exception,e:
                        print e
                        logging.debug(e)
                    break