# HG changeset patch # User Goffi # Date 1592578070 -7200 # Node ID 2e4fcd31f2a92a3f90e2a164efba223d31e031de # Parent cad8f24e23d4ad5fbb082bcf895fb967b73fa0ba pages: use Path in onFileChange + fixed encoding issue diff -r cad8f24e23d4 -r 2e4fcd31f2a9 libervia/server/pages.py --- a/libervia/server/pages.py Fri Jun 19 16:47:50 2020 +0200 +++ b/libervia/server/pages.py Fri Jun 19 16:47:50 2020 +0200 @@ -449,8 +449,8 @@ """ if flags == ['create']: return - path = file_path.path.decode('utf-8') - base_name = os.path.basename(path) + path = Path(file_path.path.decode()) + base_name = path.name if base_name != "page_meta.py": # we only handle libervia pages return @@ -458,13 +458,15 @@ log.debug("{flags} event(s) received for {file_path}".format( flags=", ".join(flags), file_path=file_path)) - dir_path = os.path.dirname(path) - if not dir_path.startswith(str(site_path)): - raise exceptions.InternalError("watched file should start with site path") + dir_path = path.parent + + if dir_path == site_path: + return - path_elts = [p for p in dir_path[len(site_path):].split('/') if p] - if not path_elts: - return + if not site_path in dir_path.parents: + raise exceptions.InternalError("watched file should be in a subdirectory of site path") + + path_elts = list(dir_path.relative_to(site_path).parts) if path_elts[0] == C.PAGES_DIR: # a page has been modified @@ -476,6 +478,7 @@ parent = page = site_root new_page = False for idx, child_name in enumerate(path_elts): + child_name = child_name.encode() try: try: page = page.original.children[child_name] @@ -507,7 +510,7 @@ except Exception as e: log.warning(_("Can't create page: {reason}").format(reason=e)) else: - url_elt = path_elts[-1] + url_elt = path_elts[-1].encode() if not new_page: # the page was already existing, we remove it del parent.children[url_elt]