diff libervia/server/server.py @ 1257:1ec41ac1e7cf

server: seperation between production build dir and dev build dir: LiberviaRootResource instances's `build_path` is the path where generated files are put and served by the HTTP server, while `dev_buid_path` is used for temporary files/libraries needed for the generation/compilation of files.
author Goffi <goffi@goffi.org>
date Sun, 03 May 2020 18:25:11 +0200
parents 08cd652dea14
children 92ff09cdd6dd
line wrap: on
line diff
--- a/libervia/server/server.py	Sun May 03 18:15:22 2020 +0200
+++ b/libervia/server/server.py	Sun May 03 18:25:11 2020 +0200
@@ -192,12 +192,14 @@
         self.pages_redirects = {}
         self.cached_urls = {}
         self.main_menu = None
-        build_path = host.getBuildPath(site_name)
-        build_path.mkdir(parents=True, exist_ok=True)
+        self.build_path = host.getBuildPath(site_name)
+        self.build_path.mkdir(parents=True, exist_ok=True)
+        self.dev_build_path = host.getBuildPath(site_name, dev=True)
+        self.dev_build_path.mkdir(parents=True, exist_ok=True)
         self.putChild(
             C.BUILD_DIR.encode(),
             ProtectedFile(
-                build_path,
+                self.build_path,
                 defaultType="application/octet-stream"),
         )
 
@@ -825,7 +827,7 @@
                 res = existing_vhosts[encoded_site_name]
             else:
                 # for root path we first check if there is a global static dir
-                # if not, we use default template's static dic
+                # if not, we use default template's static dir
                 root_path = os.path.join(site_path, C.TEMPLATE_STATIC_DIR)
                 if not os.path.isdir(root_path):
                     root_path = os.path.join(
@@ -1307,16 +1309,22 @@
         for root in self.roots:
             root.putChild(path, wrapped_res)
 
-    def getBuildPath(self, site_name):
+    def getBuildPath(self, site_name: str, dev: bool=False) -> Path:
         """Generate build path for a given site name
 
-        @param site_name(unicode): name of the site
-        @return (Path): path to the build directory
+        @param site_name: name of the site
+        @param dev: return dev build dir if True, production one otherwise
+            dev build dir is used for installing dependencies needed temporarily (e.g.
+            to compile files), while production build path is the one served by the
+            HTTP server, where final files are downloaded.
+        @return: path to the build directory
         """
+        sub_dir = C.DEV_BUILD_DIR if dev else C.PRODUCTION_BUILD_DIR
         build_path_elts = [
             config.getConfig(self.main_conf, "", "local_dir"),
             C.CACHE_DIR,
             C.LIBERVIA_CACHE,
+            sub_dir,
             regex.pathEscape(site_name or C.SITE_NAME_DEFAULT)]
         build_path = Path("/".join(build_path_elts))
         return build_path.expanduser().resolve()