Пример #1
0
    def on_message(self, message_text):
        message = None
        try:
            message = json.loads(message_text)
        except:
            print 'Invalid message from browser:', message_text
            return
        command = message.get('command')

        if command == 'refresh':
            imgs = base.list_images(path=IMAGE_PATH)
            imgs = [dict(
                path=name.replace('\\', '/'), name=os.path.basename(name)) for name in imgs]
            self.write_message({'type': 'image_list', 'data': list(imgs)})
        elif command == 'stop':
            self._run = False
            self.write_message({'type': 'run', 'notify': '停止中'})
        elif command == 'run':
            if self._run:
                self.write_message({'type': 'run', 'notify': '运行中'})
                return
            self._run = True
            res = yield self.background_task(message.get('code'))
            self.write_message({'type': 'run', 'status': 'ready', 'notify': '运行结束', 'result': res})
        else:
            self.write_message(u"You said: " + message)
Пример #2
0
    def on_message(self, message_text):
        message = None
        try:
            message = json.loads(message_text)
        except:
            print 'Invalid message from browser:', message_text
            return
        command = message.get('command')

        if command == 'refresh':
            imgs = base.list_images(path=IMAGE_PATH)
            imgs = [dict(
                path=name.replace('\\', '/'), name=os.path.basename(name)) for name in imgs]
            self.write_message({'type': 'image_list', 'data': list(imgs)})
        elif command == 'stop':
            self._run = False
            self.write_message({'type': 'run', 'notify': '停止中'})
        elif command == 'run':
            if self._run:
                self.write_message({'type': 'run', 'notify': '运行中'})
                return
            self._run = True
            res = yield self.background_task(message.get('code'))
            self.write_message({'type': 'run', 'status': 'ready', 'notify': '运行结束', 'result': res})
        else:
            self.write_message(u"You said: " + message)
Пример #3
0
 def get(self):
     imgs = base.list_images(path=IMAGE_PATH)
     images = []
     for name in imgs:
         realpath = name.replace('\\', '/') # fix for windows
         name = os.path.basename(name).split('@')[0]
         images.append([name, realpath])
     self.write({
         'images': images, 
         'baseURL': self.request.protocol + '://' + self.request.host+'/static_imgs/'
     })
Пример #4
0
 def get(self):
     imgs = base.list_images(path=IMAGE_PATH)
     images = []
     for name in imgs:
         realpath = name.replace('\\', '/') # fix for windows
         name = os.path.basename(name).split('@')[0]
         images.append([name, realpath])
     self.write({
         'images': images, 
         'baseURL': self.request.protocol + '://' + self.request.host+'/static_imgs/'
     })
Пример #5
0
 def on_message(self, message):
     print(message)
     if message == 'refresh':
         imgs = base.list_images(path=IMAGE_PATH)
         imgs = [dict(
             path=name.replace('\\', '/'), name=os.path.basename(name)) for name in imgs]
         self.write_message({'type': 'image_list', 'data': list(imgs)})
     elif message == 'run':
         res = yield self.background_task(4)
         self.write_message({'type': 'run', 'status': 'ready', 'result': res})
     else:
         self.write_message(u"You said: " + message)
Пример #6
0
    def on_message(self, message_text):
        message = None
        try:
            message = json.loads(message_text)
        except:
            print 'Invalid message from browser:', message_text
            return
        command = message.get('command')

        if command == 'refresh':
            imgs = base.list_images(path=IMAGE_PATH)
            images = []
            screenshots = []
            for name in imgs:
                realpath = name.replace('\\', '/')  # fix for windows
                if realpath.startswith('./'):
                    realpath = realpath[2:]
                directory = os.path.dirname(name)
                name = os.path.basename(name).split('@')[0]
                if realpath.startswith('screenshots/'):
                    screenshots.append({'name': name, 'path': realpath})
                else:
                    images.append({
                        'name':
                        name,
                        'path':
                        realpath,
                        'screen_crop_folder':
                        directory,
                        'hash':
                        '{}'.format(os.path.getmtime(realpath)).replace(
                            '.', '-')
                    })
            self.write_message({
                'type': 'image_list',
                'images': images,
                'screenshots': screenshots,
                'latest': latest_screen
            })
        elif command == 'stop':
            if self._proc:
                self._proc.terminate()
            self.write_message({'type': 'run', 'notify': '停止中'})
            self.write_message({'type': 'stop', 'status': 'stopped'})
        elif command == 'run':
            self.write_message({'type': 'run', 'notify': '开始运行'})
            code = message.get('code')
            yield self.run_python_code(code)
        else:
            self.write_message(u"You said: " + message)
Пример #7
0
    def on_message(self, message_text):
        message = None
        try:
            message = json.loads(message_text)
        except:
            print 'Invalid message from browser:', message_text
            return
        command = message.get('command')

        if command == 'refresh':
            imgs = base.list_images(path=IMAGE_PATH)
            images = []
            screenshots = []
            for name in imgs:
                realpath = name.replace('\\', '/')  # fix for windows
                name = os.path.basename(name).split('@')[0]
                if realpath.startswith('screenshots/'):
                    screenshots.append({'name': name, 'path': realpath})
                else:
                    images.append({'name': name, 'path': realpath})
            self.write_message({
                'type': 'image_list',
                'images': images,
                'screenshots': screenshots,
                'latest': latest_screen
            })
        elif command == 'stop':
            self._run = False
            self.write_message({'type': 'run', 'notify': '停止中'})
        elif command == 'run':
            if self._run:
                self.write_message({'type': 'run', 'notify': '运行中'})
                return
            self._run = True
            res = yield self.background_task(message.get('code'))
            self.write_message({
                'type': 'run',
                'status': 'ready',
                'notify': '运行结束',
                'result': res
            })
        else:
            self.write_message(u"You said: " + message)
Пример #8
0
 def get(self):
     imgs = base.list_images(path=IMAGE_PATH)
     imgs = [(os.path.basename(name), name) for name in imgs]
     self.render('index.html', images=imgs)
Пример #9
0
 def get(self):
     imgs = base.list_images(path=IMAGE_PATH)
     imgs = [(os.path.basename(name), name) for name in imgs]
     self.render('index.html', images=imgs)