コード例 #1
0
ファイル: watcher.py プロジェクト: yinheli/PyF5
    def on_any_event(self, event):
        if event.is_directory:
            self.check_folder_change(event.src_path)
            return

        # 暂停文件变更的上报, 以免中途编译占用太长时间,而将事件提前返回
        loop = ioloop.IOLoop.instance()
        if self.changes_timer:
            ioloop.IOLoop.instance().remove_timeout(self.changes_timer)

        now = time.time()
        if event.event_type == EVENT_TYPE_MOVED:
            self.add_pure_change(
                Change(
                    dict(timestamp=now,
                         path=normalize_path(event.src_path),
                         type=EVENT_TYPE_DELETED)))
            self.add_pure_change(
                Change(
                    dict(timestamp=now,
                         path=normalize_path(event.dest_path),
                         type=EVENT_TYPE_CREATED)))
        else:
            self.add_pure_change(
                Change(
                    dict(timestamp=now,
                         path=normalize_path(event.src_path),
                         type=event.event_type)))

        # 延迟0.1秒上报变更,防止有些事件连续发生时错过
        self.changes_timer = loop.add_timeout(
            time.time() + 0.1, self.application.project_file_changed)
コード例 #2
0
ファイル: watcher.py プロジェクト: Megasu/PyF5
    def on_any_event(self, event):
        if event.is_directory:
            self.check_folder_change(event.src_path)
            return

        # 暂停文件变更的上报, 以免中途编译占用太长时间,而将事件提前返回
        loop = ioloop.IOLoop.instance()
        if self.changes_timer:
            ioloop.IOLoop.instance().remove_timeout(self.changes_timer)

        now = time.time()
        if event.event_type == EVENT_TYPE_MOVED:
            self.add_pure_change(Change(dict(
                timestamp=now,
                path=normalize_path(event.src_path),
                type=EVENT_TYPE_DELETED
            )))
            self.add_pure_change(Change(dict(
                timestamp=now,
                path=normalize_path(event.dest_path),
                type=EVENT_TYPE_CREATED
            )))
        else:
            self.add_pure_change(Change(dict(
                timestamp=now,
                path=normalize_path(event.src_path),
                type=event.event_type
            )))

        # 延迟0.1秒上报变更,防止有些事件连续发生时错过
        self.changes_timer = loop.add_timeout(time.time() + 0.1, self.application.project_file_changed)
コード例 #3
0
ファイル: watcher.py プロジェクト: hepochen/PyF5
    def compile_if_necessary(self, change):
        if change.type == EVENT_TYPE_DELETED:
            return

        abs_path = normalize_path(os.path.join(self.path, change.path))
        base_path, ext = os.path.splitext(abs_path)
        ext = ext.lower()

        if ext not in['.less', '.coffee']:
            return

        if not self.application.active_project:
            return

        active_project = self.application.active_project
        begin_time = time.time()
        os.chdir(APP_FOLDER)
        if ext == '.less':
            if active_project.compileLess:
                output_path = base_path + '.css'
                cmd = 'bundled/node.exe bundled/less/bin/lessc %s %s' % (abs_path, output_path)
                os.system(cmd.replace('/', '\\'))
                print 'compile:', change.path, time.time() - begin_time, 'seconds'
            else:
                print 'skip compile', change.path, '(setting is off)'
        elif ext == '.coffee':
            if active_project.compileCoffee:
                output_path = base_path + '.js'
                cmd = 'bundled/node.exe bundled/coffee/bin/coffee --compile %s' % (abs_path, )
                os.system(cmd.replace('/', '\\'))
                print 'compile:', change.path, time.time() - begin_time, 'seconds'
            else:
                print 'skip compile', change.path, '(setting is off)'
コード例 #4
0
ファイル: watcher.py プロジェクト: Ju2ender/PyF5
    def compile_if_necessary(self, change):
        if change.type == EVENT_TYPE_DELETED:
            return

        input_path = normalize_path(os.path.join(self.path, change.path))
        base_path, ext = os.path.splitext(input_path)
        ext = ext.lower()
        if ext not in['.less', '.coffee']:
            return

        active_project = self.application.active_project
        if not active_project:
            return

        os.chdir(APP_FOLDER)
        begin_time = time.time()
        if ext == '.less':
            if active_project.compileLess:
                output_path = base_path + '.css'
                run_cmd('%s bundled/less/bin/lessc %s %s' % (NODE_BIN_PATH, input_path, output_path))
                print 'compile:', change.path, time.time() - begin_time, 'seconds'
            else:
                print 'skip compile', change.path, '(OFF by settings)'

        elif ext == '.coffee':
            if active_project.compileCoffee:
                run_cmd('%s bundled/coffee/bin/coffee --compile %s' % (NODE_BIN_PATH, input_path))
                print 'compile:', change.path, time.time() - begin_time, 'seconds'
            else:
                print 'skip compile', change.path, '(OFF by settings)'
コード例 #5
0
ファイル: watcher.py プロジェクト: yinheli/PyF5
    def compile_if_needed(self, change):
        if change.type == EVENT_TYPE_DELETED:
            return

        input_path = normalize_path(change.path)
        base_path, ext = os.path.splitext(input_path)
        ext = ext.lower()
        if ext not in ['.less', '.coffee']:
            return

        project = self.application.find_project(input_path)
        if not project:
            return

        os.chdir(APP_FOLDER)
        begin_time = time.time()
        if ext == '.less':
            if project.compileLess:
                output_path = base_path + '.css'
                run_cmd('%s bundled/less/bin/lessc %s %s' %
                        (NODE_BIN_PATH, input_path, output_path))
                print '.less ->- .css', change.path, time.time(
                ) - begin_time, 'seconds'
            else:
                print '.less -X- .css', change.path, '(OFF by settings)'

        elif ext == '.coffee':
            if project.compileCoffee:
                run_cmd('%s bundled/coffee/bin/coffee --compile %s' %
                        (NODE_BIN_PATH, input_path))
                print '.coffee ->- .js', change.path, time.time(
                ) - begin_time, 'seconds'
            else:
                print '.coffee -X- .js', change.path, '(OFF by settings)'
コード例 #6
0
ファイル: api.py プロジェクト: Megasu/PyF5
    def _get_path_argument(self, argument_name, ensure_exists=False):
        path = self.get_argument(argument_name, '')
        if not path:
            self.respond_error(INVALID_PARAMS, u'缺少%s参数' % argument_name)
            return

        if ensure_exists and not os.path.exists(path):
            self.respond_error(INVALID_PARAMS, u'路径不存在:%s' % path)
            return

        return normalize_path(path)
コード例 #7
0
ファイル: api.py プロジェクト: Megasu/PyF5
    def writeFile(self):
        path = self.get_argument('path', '')
        content = self.get_argument('content', '')
        if not path:
            return self.respond_error(INVALID_PARAMS, u'缺少path参数')
        if not os.path.exists(path):
            return self.respond_error(PATH_NOT_EXISTS, u'路径不存在:' + path)

        path = normalize_path(path)
        open(path, 'w').write(content.encode('utf-8'))
        return self.respond_success()
コード例 #8
0
ファイル: api.py プロジェクト: Megasu/PyF5
    def listDir(self):
        path = self.get_argument('path', '')
        if not path:
            return self.respond_error(INVALID_PARAMS, u'缺少path参数')
        if not os.path.exists(path):
            return self.respond_error(PATH_NOT_EXISTS, u'目录不存在:' + path)
        if not os.path.isdir(path):
            return self.respond_error(PATH_IS_NOT_DIR, u'路径不是目录')
        path = normalize_path(path)

        ret = []
        for name in os.listdir(path):
            abs_path = normalize_path(os.path.join(path, name))
            _, ext = os.path.splitext(name)
            is_dir = os.path.isdir(abs_path)
            ret.append(dict(
                name=name,
                absolutePath=abs_path,
                type='DIR' if is_dir else ext.replace('.', '').lower(),
            ))
        ret.sort(key=lambda item: (item['type'] != 'DIR', name))
        return self.respond_success({'list': ret})
コード例 #9
0
ファイル: static.py プロジェクト: WaveF/PyF5
 def get_content(cls, abspath, start=None, end=None):
     rel_path = normalize_path(abspath.replace('assets://', ''))
     content = VFS.read(rel_path)
     return content