comparison 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
comparison
equal deleted inserted replaced
1256:08cd652dea14 1257:1ec41ac1e7cf
190 self.dyn_data_common = {"scripts": []} 190 self.dyn_data_common = {"scripts": []}
191 self.uri_callbacks = {} 191 self.uri_callbacks = {}
192 self.pages_redirects = {} 192 self.pages_redirects = {}
193 self.cached_urls = {} 193 self.cached_urls = {}
194 self.main_menu = None 194 self.main_menu = None
195 build_path = host.getBuildPath(site_name) 195 self.build_path = host.getBuildPath(site_name)
196 build_path.mkdir(parents=True, exist_ok=True) 196 self.build_path.mkdir(parents=True, exist_ok=True)
197 self.dev_build_path = host.getBuildPath(site_name, dev=True)
198 self.dev_build_path.mkdir(parents=True, exist_ok=True)
197 self.putChild( 199 self.putChild(
198 C.BUILD_DIR.encode(), 200 C.BUILD_DIR.encode(),
199 ProtectedFile( 201 ProtectedFile(
200 build_path, 202 self.build_path,
201 defaultType="application/octet-stream"), 203 defaultType="application/octet-stream"),
202 ) 204 )
203 205
204 def __str__(self): 206 def __str__(self):
205 return ("Root resource for {host_name} using {site_name} at {site_path} and " 207 return ("Root resource for {host_name} using {site_name} at {site_path} and "
823 if encoded_site_name in existing_vhosts: 825 if encoded_site_name in existing_vhosts:
824 # we have an alias host, we re-use existing resource 826 # we have an alias host, we re-use existing resource
825 res = existing_vhosts[encoded_site_name] 827 res = existing_vhosts[encoded_site_name]
826 else: 828 else:
827 # for root path we first check if there is a global static dir 829 # for root path we first check if there is a global static dir
828 # if not, we use default template's static dic 830 # if not, we use default template's static dir
829 root_path = os.path.join(site_path, C.TEMPLATE_STATIC_DIR) 831 root_path = os.path.join(site_path, C.TEMPLATE_STATIC_DIR)
830 if not os.path.isdir(root_path): 832 if not os.path.isdir(root_path):
831 root_path = os.path.join( 833 root_path = os.path.join(
832 site_path, C.TEMPLATE_TPL_DIR, C.TEMPLATE_THEME_DEFAULT, 834 site_path, C.TEMPLATE_TPL_DIR, C.TEMPLATE_THEME_DEFAULT,
833 C.TEMPLATE_STATIC_DIR) 835 C.TEMPLATE_STATIC_DIR)
1305 wrapped_res = web_resource.EncodingResourceWrapper( 1307 wrapped_res = web_resource.EncodingResourceWrapper(
1306 resource, [server.GzipEncoderFactory()]) 1308 resource, [server.GzipEncoderFactory()])
1307 for root in self.roots: 1309 for root in self.roots:
1308 root.putChild(path, wrapped_res) 1310 root.putChild(path, wrapped_res)
1309 1311
1310 def getBuildPath(self, site_name): 1312 def getBuildPath(self, site_name: str, dev: bool=False) -> Path:
1311 """Generate build path for a given site name 1313 """Generate build path for a given site name
1312 1314
1313 @param site_name(unicode): name of the site 1315 @param site_name: name of the site
1314 @return (Path): path to the build directory 1316 @param dev: return dev build dir if True, production one otherwise
1315 """ 1317 dev build dir is used for installing dependencies needed temporarily (e.g.
1318 to compile files), while production build path is the one served by the
1319 HTTP server, where final files are downloaded.
1320 @return: path to the build directory
1321 """
1322 sub_dir = C.DEV_BUILD_DIR if dev else C.PRODUCTION_BUILD_DIR
1316 build_path_elts = [ 1323 build_path_elts = [
1317 config.getConfig(self.main_conf, "", "local_dir"), 1324 config.getConfig(self.main_conf, "", "local_dir"),
1318 C.CACHE_DIR, 1325 C.CACHE_DIR,
1319 C.LIBERVIA_CACHE, 1326 C.LIBERVIA_CACHE,
1327 sub_dir,
1320 regex.pathEscape(site_name or C.SITE_NAME_DEFAULT)] 1328 regex.pathEscape(site_name or C.SITE_NAME_DEFAULT)]
1321 build_path = Path("/".join(build_path_elts)) 1329 build_path = Path("/".join(build_path_elts))
1322 return build_path.expanduser().resolve() 1330 return build_path.expanduser().resolve()
1323 1331
1324 def getExtBaseURLData(self, request): 1332 def getExtBaseURLData(self, request):