Example #1
0
    def on_any_event(self, event):
        if event.is_directory:
            return
        now = time.time()
        rel_src_path = get_rel_path(event.src_path, self.path)

        if event.event_type == EVENT_TYPE_MOVED:
            self.add_pure_change(Change(now, rel_src_path, EVENT_TYPE_DELETED))
            rel_dest_path = get_rel_path(event.dest_path, self.path)
            self.add_pure_change(Change(now, rel_dest_path, EVENT_TYPE_CREATED))
        else:
            self.add_pure_change(Change(time.time(), rel_src_path, event.event_type))
        try:
            ioloop.IOLoop.instance().add_callback(self.refresh_change_timer)
        except RuntimeError:
            print 'ioloop.add_callback failed'
Example #2
0
File: zfs.py Project: no2key/PyF5
    def make_zip_file_with_folder(cls, folder_path, zip_file_path):
        zip_file = ZipFile(zip_file_path, "w", ZIP_DEFLATED)

        for root, dirs, files in os.walk(folder_path):
            for file_name in files:
                abs_path = os.path.join(root, file_name)
                rel_path = unicode(get_rel_path(abs_path, folder_path), sys.getfilesystemencoding())
                zip_file.write(abs_path, rel_path)
                print "add...", rel_path
        zip_file.close()
        print "done!"
Example #3
0
    def on_any_event(self, event):
        if event.is_directory:
            self.if_folder_changed(event.src_path)
            return

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

        now = time.time()
        src_relative_path = get_rel_path(event.src_path, self.path)

        if event.event_type == EVENT_TYPE_MOVED:
            self.add_pure_change(Change(dict(timestamp=now, path=src_relative_path, type=EVENT_TYPE_DELETED)))
            dest_relative_path = get_rel_path(event.dest_path, self.path)
            self.add_pure_change(Change(dict(timestamp=now, path=dest_relative_path, type=EVENT_TYPE_CREATED)))
        else:
            self.add_pure_change(Change(dict(timestamp=now, path=src_relative_path, type=event.event_type)))

        # 延迟0.1秒上报变更,防止有些事件连续发生时错过
        self.changes_timer = loop.add_timeout(time.time() + 0.1, self.application.project_file_changed)
Example #4
0
    def toggleBlockPath(self):
        project_path = self.get_path_argument('projectPath')
        if not project_path:
            return self.respond_error(INVALID_PARAMS, u'缺少projectPath参数')
        if not os.path.exists(project_path):
            return self.respond_error(PATH_NOT_EXISTS, u'项目目录不存在:' + project_path)

        block_path = self.get_path_argument('blockPath')
        if not block_path:
            return self.respond_error(INVALID_PARAMS, u'缺少blockPath参数')
        if not os.path.exists(block_path):
            return self.respond_error(PATH_NOT_EXISTS, u'屏蔽的目录不存在:' + block_path)

        action = self.get_argument('action', '')
        if not action or action not in ['on', 'off']:
            return self.respond_error(INVALID_PARAMS, u'缺少action参数或参数值不正确')

        project = self.find(project_path)
        if not project:
            return self.respond_error(PROJECT_NOT_EXISTS, u'找不到项目')

        rel_path = get_rel_path(block_path, project_path)
        if '..' in rel_path:
            return self.respond_error(INVALID_PARAMS, u'blockPath不属于ProjectPath')

        project_path = self.get_path_argument('projectPath')
        block_path = self.get_path_argument('blockPath')
        project = self.find(project_path)
        rel_path = get_rel_path(block_path, project_path)

        project.setdefault('blockPaths', [])
        if action == 'on' and not rel_path in project['blockPaths']:
            project['blockPaths'].append(rel_path)
        if action == 'off' and rel_path in project['blockPaths']:
            project['blockPaths'].remove(rel_path)
        self.save_config()
        return self.respond_success({})
Example #5
0
 def get_content(cls, abspath, start=None, end=None):
     rel_path = get_rel_path(abspath, 'assets://')
     content = VFS.read(rel_path)
     return content