Example #1
0
class Generate(Logya):
    """Generate a Web site to deploy from current directory as source."""
    def __init__(self, **kwargs):

        super(self.__class__, self).__init__(**kwargs)
        self.init_env()

        # Init writer before executing scripts, so they can use it.
        self.writer = DocWriter(self.dir_deploy, self.template)

        self.info('Remove existing deploy directory')
        shutil.rmtree(self.dir_deploy, True)

        self.info('Generating site in directory: {}'.format(self.dir_deploy))

        if os.path.exists(self.dir_static):
            self.info('Copy static files')
            shutil.copytree(self.dir_static, self.dir_deploy)

        self.info('Build document index')
        self.build_index()

        self.info('Write documents')
        for doc in list(self.docs.values()):
            self.writer.write(doc, self.get_doc_template(doc))
        self.info('Written {:d} documents to deploy directory'.format(
            len(self.docs)))

        self.info('Write index files')
        self.write_index_files()
        self.info('Written {:d} index files to deploy directory'.format(
            len(self.index)))
Example #2
0
class Generate(Logya):
    """Generate a Web site to deploy from current directory as source."""
    def __init__(self, **kwargs):
        super(Generate, self).__init__(**kwargs)
        self.init_env()
        self.writer = DocWriter(self.dir_deploy, self.template)

        if not kwargs.get('keep'):
            self.info('Remove existing deploy directory')
            shutil.rmtree(self.dir_deploy, True)

        self.info('Generate site in directory: {}'.format(self.dir_deploy))
        if os.path.exists(self.dir_static):
            self.info('Copy static files')
            copytree(self.dir_static, self.dir_deploy)

        self.build()
        self.write()

    def build(self):
        self.info('Build document index')
        self.build_index()

    def write(self):
        self.info('Write documents')
        for doc in self.docs.values():
            self.writer.write(doc, self.get_doc_template(doc))
        self.info('Written {:d} documents to deploy directory'.format(
            len(self.docs)))

        self.info('Write index files')
        self.write_index_files()
        self.info('Written {:d} index files to deploy directory'.format(
            len(self.index)))
Example #3
0
class Generate(Logya):
    '''Generate a Web site to deploy from current directory as source.'''
    def __init__(self, **kwargs):

        super(self.__class__, self).__init__(**kwargs)
        self.init_env()

        # Init writer before executing scripts, so they can use it.
        self.writer = DocWriter(self.dir_dst, self.template)

        self.info('Remove existing deploy directory')
        shutil.rmtree(self.dir_dst, True)

        self.info('Generating site in directory: %s' % self.dir_dst)

        if os.path.exists(self.dir_static):
            self.info('Copy static files')
            shutil.copytree(self.dir_static, self.dir_dst)

        # Execute scripts in before building indexes, so that generated content
        # can be indexed too.
        self.info('Execute scripts in bin dir')
        self.exec_bin()

        self.info('Build document indexes')
        self.build_indexes()

        for doc in list(self.docs_parsed.values()):
            self.writer.write(doc, self.get_doc_template(doc))
        self.info('Written %d documents to deploy directory' %
                  len(self.docs_parsed))

        self.write_indexes()
        self.info('Written %d indexes to deploy directory' % len(self.indexes))
Example #4
0
class Generate(Logya):
    """Generate a Web site to deploy from current directory as source."""
    def __init__(self, **kwargs):

        super(self.__class__, self).__init__(**kwargs)
        self.init_env()

        # init writer before executing scripts, so they can use it
        self.writer = DocWriter(self.dir_dst, self.template)

        self.info("Remove existing deploy directory")
        shutil.rmtree(self.dir_dst, True)

        self.info("Generating site in directory: %s" % self.dir_dst)

        if os.path.exists(self.dir_static):
            self.info("Copy static files")
            shutil.copytree(self.dir_static, self.dir_dst)

        # execute scripts in before building indexes, so that generated content
        # can be indexed too
        self.info("Execute scripts in bin dir")
        self.exec_bin()

        self.info("Build document indexes")
        self.build_indexes()

        self.info("Write documents to deploy directory")
        for doc in list(self.docs_parsed.values()):
            self.writer.write(doc, self.get_doc_template(doc))

        self.info("Write indexes")
        self.write_indexes()
Example #5
0
class Generate(Logya):
    """Generate a Web site to deploy from current directory as source."""

    def __init__(self, **kwargs):

        super(self.__class__, self).__init__(**kwargs)
        self.init_env()

        # Init writer before executing scripts, so they can use it.
        self.writer = DocWriter(self.dir_deploy, self.template)

        self.info('Remove existing deploy directory')
        shutil.rmtree(self.dir_deploy, True)

        self.info('Generating site in directory: {}'.format(self.dir_deploy))

        if os.path.exists(self.dir_static):
            self.info('Copy static files')
            shutil.copytree(self.dir_static, self.dir_deploy)

        self.info('Build document index')
        self.build_index()

        self.info('Write documents')
        for doc in list(self.docs.values()):
            self.writer.write(doc, self.get_doc_template(doc))
        self.info(
            'Written {:d} documents to deploy directory'
            .format(len(self.docs)))

        self.info('Write index files')
        self.write_index_files()
        self.info(
            'Written {:d} index files to deploy directory'
            .format(len(self.index)))
Example #6
0
    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)
Example #7
0
    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)
Example #8
0
    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])
Example #9
0
    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])
Example #10
0
    def __init__(self, **kwargs):

        super(self.__class__, self).__init__(**kwargs)
        self.init_env()

        # Init writer before executing scripts, so they can use it.
        self.writer = DocWriter(self.dir_dst, self.template)

        self.info('Remove existing deploy directory')
        shutil.rmtree(self.dir_dst, True)

        self.info('Generating site in directory: %s' % self.dir_dst)

        if os.path.exists(self.dir_static):
            self.info('Copy static files')
            shutil.copytree(self.dir_static, self.dir_dst)

        # Execute scripts in before building indexes, so that generated content
        # can be indexed too.
        self.info('Execute scripts in bin dir')
        self.exec_bin()

        self.info('Build document indexes')
        self.build_indexes()

        for doc in list(self.docs_parsed.values()):
            self.writer.write(doc, self.get_doc_template(doc))
        self.info(
            'Written %d documents to deploy directory' % len(self.docs_parsed))

        self.write_indexes()
        self.info(
            'Written %d indexes to deploy directory' % len(self.indexes))
Example #11
0
    def __init__(self, **kwargs):
        super(Generate, self).__init__(**kwargs)
        self.init_env()
        self.writer = DocWriter(self.dir_deploy, self.template)

        if not kwargs.get('keep'):
            self.info('Remove existing deploy directory')
            shutil.rmtree(self.dir_deploy, True)

        self.info('Generate site in directory: {}'.format(self.dir_deploy))
        if os.path.exists(self.dir_static):
            self.info('Copy static files')
            copytree(self.dir_static, self.dir_deploy)

        self.build()
        self.write()
Example #12
0
class Generate(Logya):
    """Generate a Web site to deploy from current directory as source."""

    def __init__(self, **kwargs):
        super(Generate, self).__init__(**kwargs)
        self.init_env()
        self.writer = DocWriter(self.dir_deploy, self.template)

        if not kwargs.get('keep'):
            self.info('Remove existing deploy directory')
            shutil.rmtree(self.dir_deploy, True)

        self.info('Generate site in directory: {}'.format(self.dir_deploy))
        if os.path.exists(self.dir_static):
            self.info('Copy static files')
            copytree(self.dir_static, self.dir_deploy)

        self.build()
        self.write()

    def build(self):
        self.info('Build document index')
        self.build_index()

    def write(self):
        self.info('Write documents')
        for doc in self.docs.values():
            self.writer.write(doc, self.get_doc_template(doc))
        self.info(
            'Written {:d} documents to deploy directory'
            .format(len(self.docs)))

        self.info('Write index files')
        self.write_index_files()
        self.info(
            'Written {:d} index files to deploy directory'
            .format(len(self.index)))
Example #13
0
    def __init__(self, **kwargs):
        super(Generate, self).__init__(**kwargs)
        self.init_env()
        self.writer = DocWriter(self.dir_deploy, self.template)

        if not kwargs.get('keep'):
            self.info('Remove existing deploy directory')
            shutil.rmtree(self.dir_deploy, True)

        self.info('Generate site in directory: {}'.format(self.dir_deploy))
        if os.path.exists(self.dir_static):
            self.info('Copy static files')
            copytree(self.dir_static, self.dir_deploy)

        self.build()
        self.write()