def refresh_resource(self, path): '''Refresh resource corresponding to given path. Static files are updated if necessary, documents are read, parsed and written to the corresponding destination in the deploy directory.''' # has to be done here too to keep track of configuration changes self.init_env() # if a file relative to static source is requested update it and return path_rel = path.lstrip('/') # use only the path component and ignore possible query params issue #3 file_src = urlparse(os.path.join(self.dir_static, path_rel)).path if os.path.isfile(file_src): file_dst = os.path.join(self.dir_dst, path_rel) if self.update_file(file_src, file_dst): logging.info('Copied file %s to %s' % (file_src, file_dst)) return logging.info('src %s not newer than dest %s' % (file_src, file_dst)) return # newly build generated docs and indexes self.exec_bin() self.build_indexes(mode='serve') # try to get doc at path, regenerate it and return doc = None if path in self.docs_parsed: doc = self.docs_parsed[path] else: # if a path like /index.html is requested also try to find / alt_path = os.path.dirname(path) if not alt_path.endswith('/'): alt_path = '%s/' % alt_path if alt_path in self.docs_parsed: doc = self.docs_parsed[alt_path] if doc: docwriter = DocWriter(self.dir_dst, self.template) docwriter.write(doc, self.get_doc_template(doc)) self.write_indexes() logging.info('Refreshed doc at URL: %s' % path) return else: # try to refresh auto-generated index file index_paths = list(self.indexes.keys()) path_normalized = path.strip('/') if path_normalized in index_paths: template = self.config.get_item('templates', 'index', 'content_type', 'template') if template: self.write_index(FileWriter(), path_normalized, template)
def refresh_resource(self, path): '''Refresh resource corresponding to given path. Static files are updated if necessary, documents are read, parsed and written to the corresponding destination in the deploy directory.''' # has to be done here too to keep track of configuration changes self.init_env() # if a file relative to static source is requested update it and return path_rel = path.lstrip('/') # use only the path component and ignore possible query params issue #3 file_src = urlparse(os.path.join(self.dir_static, path_rel)).path if os.path.isfile(file_src): file_dst = os.path.join(self.dir_dst, path_rel) if self.update_file(file_src, file_dst): logging.info('Copied file %s to %s' % (file_src, file_dst)) return logging.info('src %s not newer than dest %s' % (file_src, file_dst)) return # newly build generated docs and indexes self.exec_bin() self.build_indexes(mode='serve') # try to get doc at path, regenerate it and return doc = None if path in self.docs_parsed: doc = self.docs_parsed[path] else: # if a path like /index.html is requested also try to find / alt_path = os.path.dirname(path) if not alt_path.endswith('/'): alt_path = '%s/' % alt_path if alt_path in self.docs_parsed: doc = self.docs_parsed[alt_path] if doc: docwriter = DocWriter(self.dir_dst, self.template) docwriter.write(doc, self.get_doc_template(doc)) self.write_indexes() logging.info('Refreshed doc at URL: %s' % path) return else: # try to refresh auto-generated index file index_paths = list(self.indexes.keys()) path_normalized = path.strip('/') if path_normalized in index_paths: template = self.config.get_item( 'templates', 'index', 'content_type', 'template') if template: self.write_index(FileWriter(), path_normalized, template)
def refresh_resource(self, path): """Refresh resource corresponding to given path. Static files are updated if necessary, documents are read, parsed and written to the corresponding destination in the deploy directory.""" # Keep track of configuration changes. self.init_env() # If a static file is requested update it and return. path_rel = path.lstrip('/') # Use only the URL path and ignore possible query params issue #3. src = unquote(urlparse(os.path.join(self.dir_static, path_rel)).path) if os.path.isfile(src): dst = os.path.join(self.dir_deploy, path_rel) if self.update_file(src, dst): logging.info('Copied file %s to %s', src, dst) return logging.info('%s not newer than %s', src, dst) return # Newly build generated docs and index for HTML page requests. if path.endswith(('/', '.html', '.htm')): self.build_index(mode='serve') # Try to get doc at path, regenerate it and return. doc = None if path in self.docs: doc = self.docs[path] else: # If a path like /index.html is requested also try to find /. alt_path = os.path.dirname(path) if not alt_path.endswith('/'): alt_path = '{}/'.format(alt_path) if alt_path in self.docs: doc = self.docs[alt_path] if doc: docwriter = DocWriter(self.dir_deploy, self.template) docwriter.write(doc, self.get_doc_template(doc)) self.write_index_files() logging.info('Refreshed doc at URL: %s', path) else: # Try to refresh auto-generated index file. path_index = path.strip('/') if path_index in self.index: self.write_index(path_index, self.index[path_index])
def refresh_resource(self, path): """Refresh resource corresponding to given path. Static files are updated if necessary, documents are read, parsed and written to the corresponding destination in the deploy directory.""" # Keep track of configuration changes. self.init_env() # If a static file is requested update it and return. path_rel = path.lstrip('/') # Use only the URL path and ignore possible query params issue #3. src = urlparse(os.path.join(self.dir_static, path_rel)).path if os.path.isfile(src): dst = os.path.join(self.dir_deploy, path_rel) if self.update_file(src, dst): logging.info('Copied file %s to %s', src, dst) return logging.info('%s not newer than %s', src, dst) return # Newly build generated docs and index. self.build_index(mode='serve') # Try to get doc at path, regenerate it and return. doc = None if path in self.docs: doc = self.docs[path] else: # If a path like /index.html is requested also try to find /. alt_path = os.path.dirname(path) if not alt_path.endswith('/'): alt_path = '{}/'.format(alt_path) if alt_path in self.docs: doc = self.docs[alt_path] if doc: docwriter = DocWriter(self.dir_deploy, self.template) docwriter.write(doc, self.get_doc_template(doc)) self.write_index_files() logging.info('Refreshed doc at URL: %s', path) else: # Try to refresh auto-generated index file. path_index = path.strip('/') if path_index in self.index: self.write_index(path_index, self.index[path_index])